-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook.go
154 lines (117 loc) · 4.73 KB
/
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package aircall
import (
"fmt"
)
// Webhook service
type WebhookService service
type WebhooksResponse struct {
Meta *GenericResponseMeta `json:"meta,omitempty"`
Webhooks *[]Webhook `json:"webhooks,omitempty"`
}
type WebhookResponse struct {
Webhook *Webhook `json:"webhook,omitempty"`
}
type CreateUpdateWebhook struct {
CustomName string `json:"custom_name,omitempty"`
URL string `json:"url,omitempty"`
Events []string `json:"events,omitempty"`
}
type Webhook struct {
WebhookID string `json:"webhook_id,omitempty"`
DirectLink string `json:"direct_link,omitempty"`
CreatedAt interface{} `json:"created_at,omitempty"`
URL string `json:"url,omitempty"`
Active bool `json:"active,omitempty"`
Token string `json:"token,omitempty"`
Events *[]string `json:"events,omitempty"`
}
type WebhookQueries struct{}
// Query parameters for 'ListWebhooks' method.
type ListWebhooksQueryParams struct {
QueryValues
}
// Create Query parameters for accounts routes.
func (service *WebhookService) Query() *WebhookQueries {
return &WebhookQueries{}
}
// ***********************************************************************************
// LIST ALL WEBHOOKS
// https://developer.aircall.io/api-references/#list-all-webhooks
// ***********************************************************************************
// Creates Query parameters for 'ListContacts'
func (pq WebhookQueries) NewListWebhooks() *ListWebhooksQueryParams {
return &ListWebhooksQueryParams{
QueryValues: QueryValues{},
}
}
func (p ListWebhooksQueryParams) Order(value string) {
p.order(value)
}
func (p ListWebhooksQueryParams) Paginate(page int, perPage int) {
p.page(page, perPage)
}
// List webhooks. Reference: https://developer.aircall.io/api-references/#list-all-webhooks
func (service *WebhookService) List(opts *ListWebhooksQueryParams) (*WebhooksResponse, *Response, error) {
_url := "webhooks"
responseBody := new(WebhooksResponse)
response, err := service.client.Get(_url, opts, responseBody)
if err != nil {
return nil, response, err
}
return responseBody, response, nil
}
// ***********************************************************************************
// GET WEBHOOK
// https://developer.aircall.io/api-references/#retrieve-a-webhook
// ***********************************************************************************
// Get a webhook. Reference: https://developer.aircall.io/api-references/#retrieve-a-webhook
func (service *WebhookService) Get(webhookID string) (*WebhookResponse, *Response, error) {
_url := fmt.Sprintf("webhooks/%s", webhookID)
responseBody := new(WebhookResponse)
response, err := service.client.Get(_url, nil, responseBody)
if err != nil {
return nil, response, err
}
return responseBody, response, nil
}
// ***********************************************************************************
// CREATE WEBHOOK
// https://developer.aircall.io/api-references/#create-a-webhook
// ***********************************************************************************
// Create a webhook. Reference: https://developer.aircall.io/api-references/#create-a-webhook
func (service *WebhookService) Create(webhook *CreateUpdateWebhook) (*WebhookResponse, *Response, error) {
_url := "webhooks"
responseBody := new(WebhookResponse)
response, err := service.client.Post(_url, webhook, responseBody)
if err != nil {
return nil, response, err
}
return responseBody, response, nil
}
// ***********************************************************************************
// UPDATE WEBHOOK
// https://developer.aircall.io/api-references/#update-a-webhook
// ***********************************************************************************
// Update a webhook. Reference: https://developer.aircall.io/api-references/#update-a-webhook
func (service *WebhookService) Update(webhookID string, webhook *CreateUpdateWebhook) (*WebhookResponse, *Response, error) {
_url := fmt.Sprintf("webhooks/%s", webhookID)
responseBody := new(WebhookResponse)
response, err := service.client.Put(_url, webhook, responseBody)
if err != nil {
return nil, response, err
}
return responseBody, response, nil
}
// ***********************************************************************************
// DELETE WEBHOOK
// https://developer.aircall.io/api-references/#delete-a-webhook
// ***********************************************************************************
// Delete a webhook. Reference: https://developer.aircall.io/api-references/#delete-a-webhook
func (service *WebhookService) Delete(webhookID string) (*Response, error) {
_url := fmt.Sprintf("webhooks/%s", webhookID)
response, err := service.client.Delete(_url)
if err != nil {
return nil, err
}
return response, nil
}