/
accounts_incoming_phone_numbers_mobile.go
454 lines (415 loc) · 19.3 KB
/
accounts_incoming_phone_numbers_mobile.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/*
* This code was generated by
* ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __
* | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/
* | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \
*
* Twilio - Api
* This is the public Twilio REST API.
*
* NOTE: This class is auto generated by OpenAPI Generator.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package openapi
import (
"encoding/json"
"fmt"
"net/url"
"strings"
"github.com/twilio/twilio-go/client"
)
// Optional parameters for the method 'CreateIncomingPhoneNumberMobile'
type CreateIncomingPhoneNumberMobileParams struct {
// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will create the resource.
PathAccountSid *string `json:"PathAccountSid,omitempty"`
// The phone number to purchase specified in [E.164](https://www.twilio.com/docs/glossary/what-e164) format. E.164 phone numbers consist of a + followed by the country code and subscriber number without punctuation characters. For example, +14155551234.
PhoneNumber *string `json:"PhoneNumber,omitempty"`
// The API version to use for incoming calls made to the new phone number. The default is `2010-04-01`.
ApiVersion *string `json:"ApiVersion,omitempty"`
// A descriptive string that you created to describe the new phone number. It can be up to 64 characters long. By default, the is a formatted version of the phone number.
FriendlyName *string `json:"FriendlyName,omitempty"`
// The SID of the application that should handle SMS messages sent to the new phone number. If an `sms_application_sid` is present, we ignore all of the `sms_*_url` urls and use those of the application.
SmsApplicationSid *string `json:"SmsApplicationSid,omitempty"`
// The HTTP method that we should use to call `sms_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`.
SmsFallbackMethod *string `json:"SmsFallbackMethod,omitempty"`
// The URL that we should call when an error occurs while requesting or executing the TwiML defined by `sms_url`.
SmsFallbackUrl *string `json:"SmsFallbackUrl,omitempty"`
// The HTTP method that we should use to call `sms_url`. Can be: `GET` or `POST` and defaults to `POST`.
SmsMethod *string `json:"SmsMethod,omitempty"`
// The URL we should call when the new phone number receives an incoming SMS message.
SmsUrl *string `json:"SmsUrl,omitempty"`
// The URL we should call using the `status_callback_method` to send status information to your application.
StatusCallback *string `json:"StatusCallback,omitempty"`
// The HTTP method we should use to call `status_callback`. Can be: `GET` or `POST` and defaults to `POST`.
StatusCallbackMethod *string `json:"StatusCallbackMethod,omitempty"`
// The SID of the application we should use to handle calls to the new phone number. If a `voice_application_sid` is present, we ignore all of the voice urls and use only those set on the application. Setting a `voice_application_sid` will automatically delete your `trunk_sid` and vice versa.
VoiceApplicationSid *string `json:"VoiceApplicationSid,omitempty"`
// Whether to lookup the caller's name from the CNAM database and post it to your app. Can be: `true` or `false` and defaults to `false`.
VoiceCallerIdLookup *bool `json:"VoiceCallerIdLookup,omitempty"`
// The HTTP method that we should use to call `voice_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`.
VoiceFallbackMethod *string `json:"VoiceFallbackMethod,omitempty"`
// The URL that we should call when an error occurs retrieving or executing the TwiML requested by `url`.
VoiceFallbackUrl *string `json:"VoiceFallbackUrl,omitempty"`
// The HTTP method that we should use to call `voice_url`. Can be: `GET` or `POST` and defaults to `POST`.
VoiceMethod *string `json:"VoiceMethod,omitempty"`
// The URL that we should call to answer a call to the new phone number. The `voice_url` will not be called if a `voice_application_sid` or a `trunk_sid` is set.
VoiceUrl *string `json:"VoiceUrl,omitempty"`
// The SID of the Identity resource that we should associate with the new phone number. Some regions require an identity to meet local regulations.
IdentitySid *string `json:"IdentitySid,omitempty"`
// The SID of the Address resource we should associate with the new phone number. Some regions require addresses to meet local regulations.
AddressSid *string `json:"AddressSid,omitempty"`
//
EmergencyStatus *string `json:"EmergencyStatus,omitempty"`
// The SID of the emergency address configuration to use for emergency calling from the new phone number.
EmergencyAddressSid *string `json:"EmergencyAddressSid,omitempty"`
// The SID of the Trunk we should use to handle calls to the new phone number. If a `trunk_sid` is present, we ignore all of the voice urls and voice applications and use only those set on the Trunk. Setting a `trunk_sid` will automatically delete your `voice_application_sid` and vice versa.
TrunkSid *string `json:"TrunkSid,omitempty"`
//
VoiceReceiveMode *string `json:"VoiceReceiveMode,omitempty"`
// The SID of the Bundle resource that you associate with the phone number. Some regions require a Bundle to meet local Regulations.
BundleSid *string `json:"BundleSid,omitempty"`
}
func (params *CreateIncomingPhoneNumberMobileParams) SetPathAccountSid(PathAccountSid string) *CreateIncomingPhoneNumberMobileParams {
params.PathAccountSid = &PathAccountSid
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetPhoneNumber(PhoneNumber string) *CreateIncomingPhoneNumberMobileParams {
params.PhoneNumber = &PhoneNumber
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetApiVersion(ApiVersion string) *CreateIncomingPhoneNumberMobileParams {
params.ApiVersion = &ApiVersion
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetFriendlyName(FriendlyName string) *CreateIncomingPhoneNumberMobileParams {
params.FriendlyName = &FriendlyName
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetSmsApplicationSid(SmsApplicationSid string) *CreateIncomingPhoneNumberMobileParams {
params.SmsApplicationSid = &SmsApplicationSid
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetSmsFallbackMethod(SmsFallbackMethod string) *CreateIncomingPhoneNumberMobileParams {
params.SmsFallbackMethod = &SmsFallbackMethod
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetSmsFallbackUrl(SmsFallbackUrl string) *CreateIncomingPhoneNumberMobileParams {
params.SmsFallbackUrl = &SmsFallbackUrl
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetSmsMethod(SmsMethod string) *CreateIncomingPhoneNumberMobileParams {
params.SmsMethod = &SmsMethod
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetSmsUrl(SmsUrl string) *CreateIncomingPhoneNumberMobileParams {
params.SmsUrl = &SmsUrl
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetStatusCallback(StatusCallback string) *CreateIncomingPhoneNumberMobileParams {
params.StatusCallback = &StatusCallback
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetStatusCallbackMethod(StatusCallbackMethod string) *CreateIncomingPhoneNumberMobileParams {
params.StatusCallbackMethod = &StatusCallbackMethod
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetVoiceApplicationSid(VoiceApplicationSid string) *CreateIncomingPhoneNumberMobileParams {
params.VoiceApplicationSid = &VoiceApplicationSid
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetVoiceCallerIdLookup(VoiceCallerIdLookup bool) *CreateIncomingPhoneNumberMobileParams {
params.VoiceCallerIdLookup = &VoiceCallerIdLookup
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetVoiceFallbackMethod(VoiceFallbackMethod string) *CreateIncomingPhoneNumberMobileParams {
params.VoiceFallbackMethod = &VoiceFallbackMethod
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetVoiceFallbackUrl(VoiceFallbackUrl string) *CreateIncomingPhoneNumberMobileParams {
params.VoiceFallbackUrl = &VoiceFallbackUrl
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetVoiceMethod(VoiceMethod string) *CreateIncomingPhoneNumberMobileParams {
params.VoiceMethod = &VoiceMethod
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetVoiceUrl(VoiceUrl string) *CreateIncomingPhoneNumberMobileParams {
params.VoiceUrl = &VoiceUrl
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetIdentitySid(IdentitySid string) *CreateIncomingPhoneNumberMobileParams {
params.IdentitySid = &IdentitySid
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetAddressSid(AddressSid string) *CreateIncomingPhoneNumberMobileParams {
params.AddressSid = &AddressSid
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetEmergencyStatus(EmergencyStatus string) *CreateIncomingPhoneNumberMobileParams {
params.EmergencyStatus = &EmergencyStatus
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetEmergencyAddressSid(EmergencyAddressSid string) *CreateIncomingPhoneNumberMobileParams {
params.EmergencyAddressSid = &EmergencyAddressSid
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetTrunkSid(TrunkSid string) *CreateIncomingPhoneNumberMobileParams {
params.TrunkSid = &TrunkSid
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetVoiceReceiveMode(VoiceReceiveMode string) *CreateIncomingPhoneNumberMobileParams {
params.VoiceReceiveMode = &VoiceReceiveMode
return params
}
func (params *CreateIncomingPhoneNumberMobileParams) SetBundleSid(BundleSid string) *CreateIncomingPhoneNumberMobileParams {
params.BundleSid = &BundleSid
return params
}
//
func (c *ApiService) CreateIncomingPhoneNumberMobile(params *CreateIncomingPhoneNumberMobileParams) (*ApiV2010IncomingPhoneNumberMobile, error) {
path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json"
if params != nil && params.PathAccountSid != nil {
path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
} else {
path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
}
data := url.Values{}
headers := make(map[string]interface{})
if params != nil && params.PhoneNumber != nil {
data.Set("PhoneNumber", *params.PhoneNumber)
}
if params != nil && params.ApiVersion != nil {
data.Set("ApiVersion", *params.ApiVersion)
}
if params != nil && params.FriendlyName != nil {
data.Set("FriendlyName", *params.FriendlyName)
}
if params != nil && params.SmsApplicationSid != nil {
data.Set("SmsApplicationSid", *params.SmsApplicationSid)
}
if params != nil && params.SmsFallbackMethod != nil {
data.Set("SmsFallbackMethod", *params.SmsFallbackMethod)
}
if params != nil && params.SmsFallbackUrl != nil {
data.Set("SmsFallbackUrl", *params.SmsFallbackUrl)
}
if params != nil && params.SmsMethod != nil {
data.Set("SmsMethod", *params.SmsMethod)
}
if params != nil && params.SmsUrl != nil {
data.Set("SmsUrl", *params.SmsUrl)
}
if params != nil && params.StatusCallback != nil {
data.Set("StatusCallback", *params.StatusCallback)
}
if params != nil && params.StatusCallbackMethod != nil {
data.Set("StatusCallbackMethod", *params.StatusCallbackMethod)
}
if params != nil && params.VoiceApplicationSid != nil {
data.Set("VoiceApplicationSid", *params.VoiceApplicationSid)
}
if params != nil && params.VoiceCallerIdLookup != nil {
data.Set("VoiceCallerIdLookup", fmt.Sprint(*params.VoiceCallerIdLookup))
}
if params != nil && params.VoiceFallbackMethod != nil {
data.Set("VoiceFallbackMethod", *params.VoiceFallbackMethod)
}
if params != nil && params.VoiceFallbackUrl != nil {
data.Set("VoiceFallbackUrl", *params.VoiceFallbackUrl)
}
if params != nil && params.VoiceMethod != nil {
data.Set("VoiceMethod", *params.VoiceMethod)
}
if params != nil && params.VoiceUrl != nil {
data.Set("VoiceUrl", *params.VoiceUrl)
}
if params != nil && params.IdentitySid != nil {
data.Set("IdentitySid", *params.IdentitySid)
}
if params != nil && params.AddressSid != nil {
data.Set("AddressSid", *params.AddressSid)
}
if params != nil && params.EmergencyStatus != nil {
data.Set("EmergencyStatus", *params.EmergencyStatus)
}
if params != nil && params.EmergencyAddressSid != nil {
data.Set("EmergencyAddressSid", *params.EmergencyAddressSid)
}
if params != nil && params.TrunkSid != nil {
data.Set("TrunkSid", *params.TrunkSid)
}
if params != nil && params.VoiceReceiveMode != nil {
data.Set("VoiceReceiveMode", *params.VoiceReceiveMode)
}
if params != nil && params.BundleSid != nil {
data.Set("BundleSid", *params.BundleSid)
}
resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
if err != nil {
return nil, err
}
defer resp.Body.Close()
ps := &ApiV2010IncomingPhoneNumberMobile{}
if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
return nil, err
}
return ps, err
}
// Optional parameters for the method 'ListIncomingPhoneNumberMobile'
type ListIncomingPhoneNumberMobileParams struct {
// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the resources to read.
PathAccountSid *string `json:"PathAccountSid,omitempty"`
// Whether to include phone numbers new to the Twilio platform. Can be: `true` or `false` and the default is `true`.
Beta *bool `json:"Beta,omitempty"`
// A string that identifies the resources to read.
FriendlyName *string `json:"FriendlyName,omitempty"`
// The phone numbers of the IncomingPhoneNumber resources to read. You can specify partial numbers and use '*' as a wildcard for any digit.
PhoneNumber *string `json:"PhoneNumber,omitempty"`
// Whether to include phone numbers based on their origin. Can be: `twilio` or `hosted`. By default, phone numbers of all origin are included.
Origin *string `json:"Origin,omitempty"`
// How many resources to return in each list page. The default is 50, and the maximum is 1000.
PageSize *int `json:"PageSize,omitempty"`
// Max number of records to return.
Limit *int `json:"limit,omitempty"`
}
func (params *ListIncomingPhoneNumberMobileParams) SetPathAccountSid(PathAccountSid string) *ListIncomingPhoneNumberMobileParams {
params.PathAccountSid = &PathAccountSid
return params
}
func (params *ListIncomingPhoneNumberMobileParams) SetBeta(Beta bool) *ListIncomingPhoneNumberMobileParams {
params.Beta = &Beta
return params
}
func (params *ListIncomingPhoneNumberMobileParams) SetFriendlyName(FriendlyName string) *ListIncomingPhoneNumberMobileParams {
params.FriendlyName = &FriendlyName
return params
}
func (params *ListIncomingPhoneNumberMobileParams) SetPhoneNumber(PhoneNumber string) *ListIncomingPhoneNumberMobileParams {
params.PhoneNumber = &PhoneNumber
return params
}
func (params *ListIncomingPhoneNumberMobileParams) SetOrigin(Origin string) *ListIncomingPhoneNumberMobileParams {
params.Origin = &Origin
return params
}
func (params *ListIncomingPhoneNumberMobileParams) SetPageSize(PageSize int) *ListIncomingPhoneNumberMobileParams {
params.PageSize = &PageSize
return params
}
func (params *ListIncomingPhoneNumberMobileParams) SetLimit(Limit int) *ListIncomingPhoneNumberMobileParams {
params.Limit = &Limit
return params
}
// Retrieve a single page of IncomingPhoneNumberMobile records from the API. Request is executed immediately.
func (c *ApiService) PageIncomingPhoneNumberMobile(params *ListIncomingPhoneNumberMobileParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberMobileResponse, error) {
path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Mobile.json"
if params != nil && params.PathAccountSid != nil {
path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
} else {
path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
}
data := url.Values{}
headers := make(map[string]interface{})
if params != nil && params.Beta != nil {
data.Set("Beta", fmt.Sprint(*params.Beta))
}
if params != nil && params.FriendlyName != nil {
data.Set("FriendlyName", *params.FriendlyName)
}
if params != nil && params.PhoneNumber != nil {
data.Set("PhoneNumber", *params.PhoneNumber)
}
if params != nil && params.Origin != nil {
data.Set("Origin", *params.Origin)
}
if params != nil && params.PageSize != nil {
data.Set("PageSize", fmt.Sprint(*params.PageSize))
}
if pageToken != "" {
data.Set("PageToken", pageToken)
}
if pageNumber != "" {
data.Set("Page", pageNumber)
}
resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
if err != nil {
return nil, err
}
defer resp.Body.Close()
ps := &ListIncomingPhoneNumberMobileResponse{}
if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
return nil, err
}
return ps, err
}
// Lists IncomingPhoneNumberMobile records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning.
func (c *ApiService) ListIncomingPhoneNumberMobile(params *ListIncomingPhoneNumberMobileParams) ([]ApiV2010IncomingPhoneNumberMobile, error) {
response, errors := c.StreamIncomingPhoneNumberMobile(params)
records := make([]ApiV2010IncomingPhoneNumberMobile, 0)
for record := range response {
records = append(records, record)
}
if err := <-errors; err != nil {
return nil, err
}
return records, nil
}
// Streams IncomingPhoneNumberMobile records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached.
func (c *ApiService) StreamIncomingPhoneNumberMobile(params *ListIncomingPhoneNumberMobileParams) (chan ApiV2010IncomingPhoneNumberMobile, chan error) {
if params == nil {
params = &ListIncomingPhoneNumberMobileParams{}
}
params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit))
recordChannel := make(chan ApiV2010IncomingPhoneNumberMobile, 1)
errorChannel := make(chan error, 1)
response, err := c.PageIncomingPhoneNumberMobile(params, "", "")
if err != nil {
errorChannel <- err
close(recordChannel)
close(errorChannel)
} else {
go c.streamIncomingPhoneNumberMobile(response, params, recordChannel, errorChannel)
}
return recordChannel, errorChannel
}
func (c *ApiService) streamIncomingPhoneNumberMobile(response *ListIncomingPhoneNumberMobileResponse, params *ListIncomingPhoneNumberMobileParams, recordChannel chan ApiV2010IncomingPhoneNumberMobile, errorChannel chan error) {
curRecord := 1
for response != nil {
responseRecords := response.IncomingPhoneNumbers
for item := range responseRecords {
recordChannel <- responseRecords[item]
curRecord += 1
if params.Limit != nil && *params.Limit < curRecord {
close(recordChannel)
close(errorChannel)
return
}
}
record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberMobileResponse)
if err != nil {
errorChannel <- err
break
} else if record == nil {
break
}
response = record.(*ListIncomingPhoneNumberMobileResponse)
}
close(recordChannel)
close(errorChannel)
}
func (c *ApiService) getNextListIncomingPhoneNumberMobileResponse(nextPageUrl string) (interface{}, error) {
if nextPageUrl == "" {
return nil, nil
}
resp, err := c.requestHandler.Get(nextPageUrl, nil, nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()
ps := &ListIncomingPhoneNumberMobileResponse{}
if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
return nil, err
}
return ps, nil
}