-
Notifications
You must be signed in to change notification settings - Fork 18
/
calendar.go
77 lines (60 loc) · 1.78 KB
/
calendar.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package proton
import (
"context"
"github.com/go-resty/resty/v2"
)
func (c *Client) GetCalendars(ctx context.Context) ([]Calendar, error) {
var res struct {
Calendars []Calendar
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/calendar/v1")
}); err != nil {
return nil, err
}
return res.Calendars, nil
}
func (c *Client) GetCalendar(ctx context.Context, calendarID string) (Calendar, error) {
var res struct {
Calendar Calendar
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/calendar/v1/" + calendarID)
}); err != nil {
return Calendar{}, err
}
return res.Calendar, nil
}
func (c *Client) GetCalendarKeys(ctx context.Context, calendarID string) (CalendarKeys, error) {
var res struct {
Keys CalendarKeys
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/calendar/v1/" + calendarID + "/keys")
}); err != nil {
return nil, err
}
return res.Keys, nil
}
func (c *Client) GetCalendarMembers(ctx context.Context, calendarID string) ([]CalendarMember, error) {
var res struct {
Members []CalendarMember
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/calendar/v1/" + calendarID + "/members")
}); err != nil {
return nil, err
}
return res.Members, nil
}
func (c *Client) GetCalendarPassphrase(ctx context.Context, calendarID string) (CalendarPassphrase, error) {
var res struct {
Passphrase CalendarPassphrase
}
if err := c.do(ctx, func(r *resty.Request) (*resty.Response, error) {
return r.SetResult(&res).Get("/calendar/v1/" + calendarID + "/passphrase")
}); err != nil {
return CalendarPassphrase{}, err
}
return res.Passphrase, nil
}