-
Notifications
You must be signed in to change notification settings - Fork 18
/
svc_webhook.go
102 lines (82 loc) · 2.58 KB
/
svc_webhook.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
97
98
99
100
101
102
package lokalise
import (
"fmt"
)
const (
pathWebhooks = "webhooks"
)
type WebhookService struct {
BaseService
}
type Webhook struct {
WebhookID string `json:"webhook_id"`
URL string `json:"url"`
Secret string `json:"secret"`
Events []string `json:"events"`
EventLangMap []EventLang `json:"event_lang_map,omitempty"`
}
type CreateWebhook struct {
URL string `json:"url"`
Events []string `json:"events"`
EventLangMap []EventLang `json:"event_lang_map,omitempty"`
Branch string `json:"branch,omitempty"`
}
type UpdateWebhook struct { // all optional
URL string `json:"url,omitempty"`
Events []string `json:"events,omitempty"`
EventLangMap []EventLang `json:"event_lang_map,omitempty"`
Branch string `json:"branch,omitempty"`
}
type EventLang struct {
Event string `json:"event"`
LangISOCodes []string `json:"lang_iso_codes"`
}
type WebhooksResponse struct {
Paged
WithProjectID
Webhooks []Webhook `json:"webhooks"`
}
type WebhookResponse struct {
WithProjectID
Webhook Webhook `json:"webhook"`
}
type DeleteWebhookResponse struct {
WithProjectID
Deleted bool `json:"webhook_deleted"`
}
func (c *WebhookService) List(projectID string) (r WebhooksResponse, err error) {
resp, err := c.getWithOptions(c.Ctx(), fmt.Sprintf("%s/%s/%s", pathProjects, projectID, pathWebhooks), &r, c.PageOpts())
if err != nil {
return
}
applyPaged(resp, &r.Paged)
return r, apiError(resp)
}
func (c *WebhookService) Create(projectID string, wh CreateWebhook) (r WebhookResponse, err error) {
resp, err := c.post(c.Ctx(), fmt.Sprintf("%s/%s/%s", pathProjects, projectID, pathWebhooks), &r, wh)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *WebhookService) Update(projectID string, webhookID string, opts UpdateWebhook) (r WebhookResponse, err error) {
resp, err := c.put(c.Ctx(), fmt.Sprintf("%s/%s/%s/%s", pathProjects, projectID, pathWebhooks, webhookID), &r, opts)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *WebhookService) Retrieve(projectID string, webhookID string) (r WebhookResponse, err error) {
resp, err := c.get(c.Ctx(), fmt.Sprintf("%s/%s/%s/%s", pathProjects, projectID, pathWebhooks, webhookID), &r)
if err != nil {
return
}
return r, apiError(resp)
}
func (c *WebhookService) Delete(projectID string, webhookID string) (r DeleteWebhookResponse, err error) {
resp, err := c.delete(c.Ctx(), fmt.Sprintf("%s/%s/%s/%s", pathProjects, projectID, pathWebhooks, webhookID), &r)
if err != nil {
return
}
return r, apiError(resp)
}