-
Notifications
You must be signed in to change notification settings - Fork 23
/
campaign.go
276 lines (251 loc) · 11.5 KB
/
campaign.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package plivo
type CampaignService struct {
client *Client
}
type ImportCampaignParams struct {
CampaignID string `json:"campaign_id,omitempty" url:"campaign_id,omitempty"`
CampaignAlias string `json:"campaign_alias,omitempty" url:"campaign_alias,omitempty"`
URL string `json:"url,omitempty" url:"url,omitempty"`
Method string `json:"method,omitempty" url:"method,omitempty"`
}
type CampaignCreationParams struct {
BrandID string `json:"brand_id" url:"brand_id" validate:"required"`
CampaignAlias *string `json:"campaign_alias,omitempty" url:"campaign_alias,omitempty"`
Vertical string `json:"vertical" url:"vertical"`
Usecase string `json:"usecase" url:"usecase"`
ResellerID string `json:" reseller_id,omitempty" url:" reseller_id,omitempty"`
SubUsecases *[]string `json:"sub_usecases" url:"sub_usecases"`
Description string `json:"description,omitempty" url:"description,omitempty"`
EmbeddedLink *bool `json:"embedded_link,omitempty" url:"embedded_link,omitempty"`
EmbeddedPhone *bool `json:"embedded_phone,omitempty" url:"embedded_phone,omitempty"`
AgeGated *bool `json:"age_gated,omitempty" url:"age_gated,omitempty"`
DirectLending *bool `json:"direct_lending,omitempty" url:"direct_lending,omitempty"`
SubscriberOptin bool `json:"subscriber_optin" url:"subscriber_optin"`
SubscriberOptout bool `json:"subscriber_optout" url:"subscriber_optout"`
SubscriberHelp bool `json:"subscriber_help" url:"subscriber_help"`
AffiliateMarketing bool `json:"affiliate_marketing" url:"subscriber_help"`
Sample1 *string `json:"sample1" url:"sample1"`
Sample2 *string `json:"sample2,omitempty" url:"sample2,omitempty"`
URL string `json:"url,omitempty" url:"url,omitempty"`
Method string `json:"method,omitempty" url:"method,omitempty"`
MessageFlow string `json:"message_flow,omitempty" url:"message_flow"`
HelpMessage string `json:"help_message,omitempty" url:"help_message"`
OptinKeywords string `json:"optin_keywords,omitempty" url:"optin_keywords"`
OptinMessage string `json:"optin_message,omitempty" url:"optin_message"`
OptoutKeywords string `json:"optout_keywords,omitempty" url:"optout_keywords"`
OptoutMessage string `json:"optout_message,omitempty" url:"optout_message"`
HelpKeywords string `json:"help_keywords,omitempty" url:"help_keywords"`
}
type CampaignUpdateParams struct {
ResellerID string `json:" reseller_id,omitempty" url:" reseller_id,omitempty"`
Description string `json:"description,omitempty" url:"description,omitempty"`
Sample1 string `json:"sample1" url:"sample1"`
Sample2 string `json:"sample2,omitempty" url:"sample2,omitempty"`
MessageFlow string `json:"message_flow,omitempty" url:"message_flow"`
HelpMessage string `json:"help_message,omitempty" url:"help_message"`
OptinKeywords string `json:"optin_keywords,omitempty" url:"optin_keywords"`
OptinMessage string `json:"optin_message,omitempty" url:"optin_message"`
OptoutKeywords string `json:"optout_keywords,omitempty" url:"optout_keywords"`
OptoutMessage string `json:"optout_message,omitempty" url:"optout_message"`
HelpKeywords string `json:"help_keywords,omitempty" url:"help_keywords"`
}
type CampaignListResponse struct {
ApiID string `json:"api_id,omitempty"`
Meta struct {
Previous *string
Next *string
Offset int64
Limit int64
TotalCount int64 `json:"total_count"`
} `json:"meta"`
CampaignResponse []Campaign `json:"campaigns,omitempty"`
}
type CampaignGetResponse struct {
ApiID string `json:"api_id"`
Campaign Campaign `json:"campaign"`
}
type CampaignCreateResponse struct {
ApiID string `json:"api_id,omitempty"`
CampaignID string `json:"campaign_id"`
Message string `json:"message,omitempty"`
}
type CampaignDeleteResponse struct {
ApiID string `json:"api_id"`
CampaignID string `json:"campaign_id,omitempty"`
Message string `json:"message,omitempty"`
}
type Campaign struct {
BrandID string `json:"brand_id,omitempty"`
CampaignID string `json:"campaign_id,omitempty"`
MnoMetadata MnoMetadata `json:"mno_metadata,omitempty"`
ResellerID string `json:"reseller_id,omitempty"`
Usecase string `json:"usecase,omitempty"`
SubUsecase string `json:"sub_usecase,omitempty"`
RegistrationStatus string `json:"registration_status,omitempty"`
MessageFlow string `json:"message_flow,omitempty"`
HelpMessage string `json:"help_message,omitempty"`
OptinKeywords string `json:"optin_keywords,omitempty"`
OptinMessage string `json:"optin_message,omitempty"`
OptoutKeywords string `json:"optout_keywords,omitempty"`
OptoutMessage string `json:"optout_message,omitempty"`
HelpKeywords string `json:"help_keywords,omitempty"`
SampleMessage1 string `json:"sample1,omitempty"`
SampleMessage2 string `json:"sample2,omitempty"`
CampaignDescription string `json:"description,omitempty"`
CampaignAttributes CampaignAttributes `json:"campaign_attributes,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
CampaignSource string `json:"campaign_source,omitempty"`
ErrorCode string `json:"error_code,omitempty"`
ErrorReason string `json:"error_reason,omitempty"`
Vertical string `json:"vertical,omitempty"`
CampaignAlias string `json:"campaign_alias,omitempty"`
}
type CampaignAttributes struct {
EmbeddedLink bool `json:"embedded_link"`
EmbeddedPhone bool `json:"embedded_phone"`
AgeGated bool `json:"age_gated"`
DirectLending bool `json:"direct_lending"`
SubscriberOptin bool `json:"subscriber_optin"`
SubscriberOptout bool `json:"subscriber_optout"`
SubscriberHelp bool `json:"subscriber_help"`
AffiliateMarketing bool `json:"affiliate_marketing"`
}
type MnoMetadata struct {
ATandT OperatorDetail `json:"AT&T,omitempty"`
TMobile OperatorDetail `json:"T-Mobile,omitempty"`
VerizonWireless OperatorDetail `json:"Verizon Wireless,omitempty"`
USCellular OperatorDetail `json:"US Cellular,omitempty"`
}
type OperatorDetail struct {
BrandTier string `json:"brand_tier,omitempty"`
TPM int `json:"tpm,omitempty"`
}
type CampaignListParams struct {
BrandID *string `url:"brand_id,omitempty"`
Usecase *string `url:"usecase,omitempty"`
RegistrationStatus *string `url:"registration_status,omitempty"`
CampaignSource *string `url:"campaign_source,omitempty"`
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
}
type CampaignNumberLinkParams struct {
Numbers []string `json:"numbers,omitempty"`
URL string `json:"url,omitempty"`
Method string `json:"method,omitempty"`
}
type CampaignNumberUnlinkParams struct {
URL string `json:"url,omitempty"`
Method string `json:"method,omitempty"`
}
type CampaignNumbersGetParams struct {
Limit int `url:"limit,omitempty"`
Offset int `url:"offset,omitempty"`
}
type CampaignNumberLinkUnlinkResponse struct {
ApiID string `json:"api_id"`
Message string `json:"message,omitempty"`
}
type CampaignNumberGetResponse struct {
ApiID string `json:"api_id"`
CampaignID string `json:"campaign_id"`
CampaignAlias string `json:"campaign_alias"`
CampaignUseCase string `json:"usecase"`
CampaignNumbers []CampaignNumber `json:"phone_numbers"`
CampaignNumberSummary map[string]int `json:"phone_numbers_summary,omitempty"`
NumberPoolLimit int `json:"number_pool_limit,omitempty"`
}
type CampaignNumber struct {
Number string `json:"number"`
Status string `json:"status"`
}
func (service *CampaignService) List(params CampaignListParams) (response *CampaignListResponse, err error) {
req, err := service.client.NewRequest("GET", params, "10dlc/Campaign")
if err != nil {
return
}
response = &CampaignListResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *CampaignService) Get(campaignID string) (response *CampaignGetResponse, err error) {
req, err := service.client.NewRequest("GET", nil, "10dlc/Campaign/%s", campaignID)
if err != nil {
return
}
response = &CampaignGetResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *CampaignService) Create(params CampaignCreationParams) (response *CampaignCreateResponse, err error) {
req, err := service.client.NewRequest("POST", params, "10dlc/Campaign")
if err != nil {
return
}
response = &CampaignCreateResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *CampaignService) Import(params ImportCampaignParams) (response *CampaignCreateResponse, err error) {
req, err := service.client.NewRequest("POST", params, "10dlc/Campaign/Import")
if err != nil {
return
}
response = &CampaignCreateResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *CampaignService) Update(campaignID string, params CampaignUpdateParams) (response *CampaignGetResponse, err error) {
// response needs to be same as CampaignGetResponse
req, err := service.client.NewRequest("POST", params, "10dlc/Campaign/%s", campaignID)
if err != nil {
return
}
response = &CampaignGetResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *CampaignService) Delete(campaignID string) (response *CampaignDeleteResponse, err error) {
req, err := service.client.NewRequest("DELETE", nil, "10dlc/Campaign/%s", campaignID)
if err != nil {
return
}
response = &CampaignDeleteResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *CampaignService) NumberLink(campaignID string, params CampaignNumberLinkParams) (response *CampaignNumberLinkUnlinkResponse, err error) {
req, err := service.client.NewRequest("POST", params, "10dlc/Campaign/%s/Number", campaignID)
if err != nil {
return
}
response = &CampaignNumberLinkUnlinkResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *CampaignService) NumberGet(campaignID, number string) (response *CampaignNumberGetResponse, err error) {
req, err := service.client.NewRequest("GET", nil, "10dlc/Campaign/%s/Number/%s", campaignID, number)
if err != nil {
return
}
response = &CampaignNumberGetResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *CampaignService) NumbersGet(campaignID string, params CampaignNumbersGetParams) (response *CampaignNumberGetResponse, err error) {
req, err := service.client.NewRequest("GET", params, "10dlc/Campaign/%s/Number", campaignID)
if err != nil {
return
}
response = &CampaignNumberGetResponse{}
err = service.client.ExecuteRequest(req, response)
return
}
func (service *CampaignService) NumberUnlink(campaignID, number string, params CampaignNumberUnlinkParams) (response *CampaignNumberLinkUnlinkResponse, err error) {
req, err := service.client.NewRequest("DELETE", params, "10dlc/Campaign/%s/Number/%s", campaignID, number)
if err != nil {
return
}
response = &CampaignNumberLinkUnlinkResponse{}
err = service.client.ExecuteRequest(req, response)
return
}