-
Notifications
You must be signed in to change notification settings - Fork 4
/
sms_recipients.go
114 lines (92 loc) · 2.92 KB
/
sms_recipients.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
package mailersend
import (
"context"
"fmt"
"net/http"
"time"
)
const smsRecipientPath = "/sms-recipients"
type SmsRecipientService service
// smsRecipientRoot - format of activity response
type smsRecipientRoot struct {
Data []SmsRecipient `json:"data"`
Links Links `json:"links"`
Meta Meta `json:"meta"`
}
// singleSmsNumberRoot - format of activity response
type singleSmsRecipientRoot struct {
Data SmsRecipientData `json:"data"`
}
// singleSmsRecipientUpdateRoot - format of activity response
type singleSmsRecipientUpdateRoot struct {
Data SmsRecipientDataUpdate `json:"data"`
}
type SmsRecipient struct {
Id string `json:"id"`
Number string `json:"number"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
}
type SmsRecipientData struct {
Id string `json:"id"`
Number string `json:"number"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
Sms []SmsMessage
}
type SmsRecipientDataUpdate struct {
Id string `json:"id"`
Number string `json:"number"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
}
// SmsRecipientSettingOptions - modifies the behavior of SmsNumbersService.Update method
type SmsRecipientSettingOptions struct {
Id string `json:"-"`
Status string `json:"status,omitempty"`
}
// SmsRecipientOptions - modifies the behavior of SmsNumbersService.List method
type SmsRecipientOptions struct {
Status bool `url:"status,omitempty"`
SmsNumberId string `url:"sms_number_id,omitempty"`
Page int `url:"page,omitempty"`
Limit int `url:"limit,omitempty"`
}
func (s *SmsRecipientService) List(ctx context.Context, options *SmsRecipientOptions) (*smsRecipientRoot, *Response, error) {
req, err := s.client.newRequest(http.MethodGet, smsRecipientPath, options)
if err != nil {
return nil, nil, err
}
root := new(smsRecipientRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *SmsRecipientService) Get(ctx context.Context, smsRecipientId string) (*singleSmsRecipientRoot, *Response, error) {
path := fmt.Sprintf("%s/%s", smsRecipientPath, smsRecipientId)
req, err := s.client.newRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(singleSmsRecipientRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}
func (s *SmsRecipientService) Update(ctx context.Context, options *SmsRecipientSettingOptions) (*singleSmsRecipientUpdateRoot, *Response, error) {
path := fmt.Sprintf("%s/%s", smsRecipientPath, options.Id)
req, err := s.client.newRequest(http.MethodPut, path, options)
if err != nil {
return nil, nil, err
}
root := new(singleSmsRecipientUpdateRoot)
res, err := s.client.do(ctx, req, root)
if err != nil {
return nil, res, err
}
return root, res, nil
}