-
Notifications
You must be signed in to change notification settings - Fork 2
/
calendars.go
54 lines (45 loc) · 1.54 KB
/
calendars.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
package client
import (
"fmt"
"net/http"
)
// Calendar describes a calendar schema object
//
// Data is the base64 encoded ical
type Calendar struct {
ID int `json:"id"`
Name string `json:"name"`
Data string `json:"data"`
Attributes Attributes `json:"attributes"`
}
// ListCalendars fetches a list of Calendars
// Without params, it returns a list of Calendars the user has access to
//
// Params:
// WithAll - Can only be used by admins or managers to fetch all entities
// WithUserID - Standard users can use this only with their own userId
func (c *Client) ListCalendars(params ...QueryParameter) (calendars []Calendar, err error) {
err = c.doRequest(http.MethodGet, "calendars"+query(params), nil, &calendars)
return
}
// CreateCalendar creates a Calendar
func (c *Client) CreateCalendar(calendar Calendar) (Calendar, error) {
return c.doCalendar(http.MethodPost, "calendars", calendar)
}
// DeleteCalendar deletes a Calendar
func (c *Client) DeleteCalendar(id int) error {
return c.doRequest(http.MethodDelete, fmt.Sprintf("calendars/%d", id), nil, nil)
}
// UpdateCalendar updates a Calendar
func (c *Client) UpdateCalendar(id int, calendar Calendar) (Calendar, error) {
calendar.ID = id
return c.doCalendar(http.MethodPut, fmt.Sprintf("calendars/%d", id), calendar)
}
func (c *Client) doCalendar(method, path string, calendar Calendar) (Calendar, error) {
body, err := jsonBody(calendar)
if err != nil {
return calendar, err
}
err = c.doRequest(method, path, body, &calendar)
return calendar, err
}