-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsms_webhooks.go
136 lines (110 loc) · 3.6 KB
/
sms_webhooks.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
package mailersend
import (
"context"
"fmt"
"net/http"
"time"
)
const smsWebhookPath = "/sms-webhooks"
type SmsWebhookService service
// smsWebhookRoot - format of activity response
type smsWebhookRoot struct {
Data []smsWebhook `json:"data"`
Links Links `json:"links"`
Meta Meta `json:"meta"`
}
// singleSmsNumberRoot - format of activity response
type singleSmsWebhookRoot struct {
Data smsWebhook `json:"data"`
}
type smsWebhook struct {
Id string `json:"id"`
Url string `json:"url"`
Events []string `json:"events"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
SmsNumber Number `json:"sms_number"`
}
// CreateSmsWebhookOptions - modifies the behavior of *WebhookService.Create Method
type CreateSmsWebhookOptions struct {
SmsNumberId string `json:"sms_number_id"`
Name string `json:"name"`
URL string `json:"url"`
Enabled *bool `json:"enabled,omitempty"`
Events []string `json:"events"`
}
// UpdateSmsWebhookOptions - modifies the behavior of SmsNumbersService.Update method
type UpdateSmsWebhookOptions struct {
Id string `json:"-"`
URL string `json:"url,omitempty"`
Name string `json:"name,omitempty"`
Events []string `json:"events,omitempty"`
Status string `json:"status,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}
// ListSmsWebhookOptions - modifies the behavior of SmsNumbersService.List method
type ListSmsWebhookOptions struct {
SmsNumberId string `url:"sms_number_id,omitempty"`
Page int `url:"page,omitempty"`
Limit int `url:"limit,omitempty"`
}
func (s *SmsWebhookService) List(ctx context.Context, options *ListSmsWebhookOptions) (*smsWebhookRoot, *Response, error) {
req, err := s.client.newRequest(http.MethodGet, smsWebhookPath, options)
if err != nil {
return nil, nil, err
}
root := new(smsWebhookRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *SmsWebhookService) Get(ctx context.Context, smsWebhookId string) (*singleSmsWebhookRoot, *Response, error) {
path := fmt.Sprintf("%s/%s", smsWebhookPath, smsWebhookId)
req, err := s.client.newRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(singleSmsWebhookRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *SmsWebhookService) Create(ctx context.Context, options *CreateSmsWebhookOptions) (*singleSmsWebhookRoot, *Response, error) {
req, err := s.client.newRequest(http.MethodPost, smsWebhookPath, options)
if err != nil {
return nil, nil, err
}
root := new(singleSmsWebhookRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *SmsWebhookService) Update(ctx context.Context, options *UpdateSmsWebhookOptions) (*singleSmsWebhookRoot, *Response, error) {
path := fmt.Sprintf("%s/%s", smsWebhookPath, options.Id)
req, err := s.client.newRequest(http.MethodPut, path, options)
if err != nil {
return nil, nil, err
}
root := new(singleSmsWebhookRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *SmsWebhookService) Delete(ctx context.Context, smsWebhookId string) (*Response, error) {
path := fmt.Sprintf("%s/%s", smsWebhookPath, smsWebhookId)
req, err := s.client.newRequest(http.MethodDelete, path, nil)
if err != nil {
return nil, err
}
return s.client.do(ctx, req, nil)
}