forked from heimweh/go-pagerduty
/
addon.go
96 lines (79 loc) · 2.64 KB
/
addon.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package pagerduty
import "fmt"
// AddonService handles the communication with add-on related methods
// of the PagerDuty API.
type AddonService service
// Addon represents a PagerDuty add-on.
type Addon struct {
Addon *Addon `json:"addon,omitempty"`
HTMLURL string `json:"html_url,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Self string `json:"self,omitempty"`
Src string `json:"src,omitempty"`
Summary string `json:"summary,omitempty"`
Type string `json:"type,omitempty"`
}
// ListAddonsOptions represents options when listing add-ons.
type ListAddonsOptions struct {
Limit int `url:"limit,omitempty"`
More bool `url:"more,omitempty"`
Offset int `url:"offset,omitempty"`
Total int `url:"total,omitempty"`
Filter string `url:"filter,omitempty"`
Include []string `url:"include,omitempty,brackets"`
ServiceIDs []string `url:"service_ids,omitempty,brackets"`
}
// ListAddonsResponse represents a list response of add-ons.
type ListAddonsResponse struct {
Limit int `json:"limit,omitempty"`
More bool `json:"more,omitempty"`
Offset int `json:"offset,omitempty"`
Total int `json:"total,omitempty"`
Addons []*Addon `json:"addons,omitempty"`
}
// List lists installed add-ons.
func (s *AddonService) List(o *ListAddonsOptions) (*ListAddonsResponse, *Response, error) {
u := "/addons"
v := new(ListAddonsResponse)
resp, err := s.client.newRequestDo("GET", u, o, nil, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
// Install installs an add-on.
func (s *AddonService) Install(addon *Addon) (*Addon, *Response, error) {
u := "/addons"
v := new(Addon)
resp, err := s.client.newRequestDo("POST", u, nil, &Addon{Addon: addon}, v)
if err != nil {
return nil, nil, err
}
return v.Addon, resp, nil
}
// Delete removes an existing add-on.
func (s *AddonService) Delete(id string) (*Response, error) {
u := fmt.Sprintf("/addons/%s", id)
return s.client.newRequestDo("DELETE", u, nil, nil, nil)
}
// Get retrieves information about an add-on.
func (s *AddonService) Get(id string) (*Addon, *Response, error) {
u := fmt.Sprintf("/addons/%s", id)
v := new(Addon)
resp, err := s.client.newRequestDo("GET", u, nil, nil, &v)
if err != nil {
return nil, nil, err
}
return v.Addon, resp, nil
}
// Update updates an existing add-on.
func (s *AddonService) Update(id string, addon *Addon) (*Addon, *Response, error) {
u := fmt.Sprintf("/addons/%s", id)
v := new(Addon)
resp, err := s.client.newRequestDo("PUT", u, nil, &Addon{Addon: addon}, &v)
if err != nil {
return nil, nil, err
}
return v.Addon, resp, nil
}