github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_incoming_phone_numbers_local.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Api 8 * This is the public Twilio REST API. 9 * 10 * NOTE: This class is auto generated by OpenAPI Generator. 11 * https://openapi-generator.tech 12 * Do not edit the class manually. 13 */ 14 15 package openapi 16 17 import ( 18 "encoding/json" 19 "fmt" 20 "net/url" 21 "strings" 22 23 "github.com/twilio/twilio-go/client" 24 ) 25 26 // Optional parameters for the method 'CreateIncomingPhoneNumberLocal' 27 type CreateIncomingPhoneNumberLocalParams struct { 28 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that will create the resource. 29 PathAccountSid *string `json:"PathAccountSid,omitempty"` 30 // 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. 31 PhoneNumber *string `json:"PhoneNumber,omitempty"` 32 // The API version to use for incoming calls made to the new phone number. The default is `2010-04-01`. 33 ApiVersion *string `json:"ApiVersion,omitempty"` 34 // A descriptive string that you created to describe the new phone number. It can be up to 64 characters long. By default, this is a formatted version of the phone number. 35 FriendlyName *string `json:"FriendlyName,omitempty"` 36 // 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 set on the application. 37 SmsApplicationSid *string `json:"SmsApplicationSid,omitempty"` 38 // The HTTP method that we should use to call `sms_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`. 39 SmsFallbackMethod *string `json:"SmsFallbackMethod,omitempty"` 40 // The URL that we should call when an error occurs while requesting or executing the TwiML defined by `sms_url`. 41 SmsFallbackUrl *string `json:"SmsFallbackUrl,omitempty"` 42 // The HTTP method that we should use to call `sms_url`. Can be: `GET` or `POST` and defaults to `POST`. 43 SmsMethod *string `json:"SmsMethod,omitempty"` 44 // The URL we should call when the new phone number receives an incoming SMS message. 45 SmsUrl *string `json:"SmsUrl,omitempty"` 46 // The URL we should call using the `status_callback_method` to send status information to your application. 47 StatusCallback *string `json:"StatusCallback,omitempty"` 48 // The HTTP method we should use to call `status_callback`. Can be: `GET` or `POST` and defaults to `POST`. 49 StatusCallbackMethod *string `json:"StatusCallbackMethod,omitempty"` 50 // 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. 51 VoiceApplicationSid *string `json:"VoiceApplicationSid,omitempty"` 52 // 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`. 53 VoiceCallerIdLookup *bool `json:"VoiceCallerIdLookup,omitempty"` 54 // The HTTP method that we should use to call `voice_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`. 55 VoiceFallbackMethod *string `json:"VoiceFallbackMethod,omitempty"` 56 // The URL that we should call when an error occurs retrieving or executing the TwiML requested by `url`. 57 VoiceFallbackUrl *string `json:"VoiceFallbackUrl,omitempty"` 58 // The HTTP method that we should use to call `voice_url`. Can be: `GET` or `POST` and defaults to `POST`. 59 VoiceMethod *string `json:"VoiceMethod,omitempty"` 60 // 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. 61 VoiceUrl *string `json:"VoiceUrl,omitempty"` 62 // The SID of the Identity resource that we should associate with the new phone number. Some regions require an identity to meet local regulations. 63 IdentitySid *string `json:"IdentitySid,omitempty"` 64 // The SID of the Address resource we should associate with the new phone number. Some regions require addresses to meet local regulations. 65 AddressSid *string `json:"AddressSid,omitempty"` 66 // 67 EmergencyStatus *string `json:"EmergencyStatus,omitempty"` 68 // The SID of the emergency address configuration to use for emergency calling from the new phone number. 69 EmergencyAddressSid *string `json:"EmergencyAddressSid,omitempty"` 70 // 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. 71 TrunkSid *string `json:"TrunkSid,omitempty"` 72 // 73 VoiceReceiveMode *string `json:"VoiceReceiveMode,omitempty"` 74 // The SID of the Bundle resource that you associate with the phone number. Some regions require a Bundle to meet local Regulations. 75 BundleSid *string `json:"BundleSid,omitempty"` 76 } 77 78 func (params *CreateIncomingPhoneNumberLocalParams) SetPathAccountSid(PathAccountSid string) *CreateIncomingPhoneNumberLocalParams { 79 params.PathAccountSid = &PathAccountSid 80 return params 81 } 82 func (params *CreateIncomingPhoneNumberLocalParams) SetPhoneNumber(PhoneNumber string) *CreateIncomingPhoneNumberLocalParams { 83 params.PhoneNumber = &PhoneNumber 84 return params 85 } 86 func (params *CreateIncomingPhoneNumberLocalParams) SetApiVersion(ApiVersion string) *CreateIncomingPhoneNumberLocalParams { 87 params.ApiVersion = &ApiVersion 88 return params 89 } 90 func (params *CreateIncomingPhoneNumberLocalParams) SetFriendlyName(FriendlyName string) *CreateIncomingPhoneNumberLocalParams { 91 params.FriendlyName = &FriendlyName 92 return params 93 } 94 func (params *CreateIncomingPhoneNumberLocalParams) SetSmsApplicationSid(SmsApplicationSid string) *CreateIncomingPhoneNumberLocalParams { 95 params.SmsApplicationSid = &SmsApplicationSid 96 return params 97 } 98 func (params *CreateIncomingPhoneNumberLocalParams) SetSmsFallbackMethod(SmsFallbackMethod string) *CreateIncomingPhoneNumberLocalParams { 99 params.SmsFallbackMethod = &SmsFallbackMethod 100 return params 101 } 102 func (params *CreateIncomingPhoneNumberLocalParams) SetSmsFallbackUrl(SmsFallbackUrl string) *CreateIncomingPhoneNumberLocalParams { 103 params.SmsFallbackUrl = &SmsFallbackUrl 104 return params 105 } 106 func (params *CreateIncomingPhoneNumberLocalParams) SetSmsMethod(SmsMethod string) *CreateIncomingPhoneNumberLocalParams { 107 params.SmsMethod = &SmsMethod 108 return params 109 } 110 func (params *CreateIncomingPhoneNumberLocalParams) SetSmsUrl(SmsUrl string) *CreateIncomingPhoneNumberLocalParams { 111 params.SmsUrl = &SmsUrl 112 return params 113 } 114 func (params *CreateIncomingPhoneNumberLocalParams) SetStatusCallback(StatusCallback string) *CreateIncomingPhoneNumberLocalParams { 115 params.StatusCallback = &StatusCallback 116 return params 117 } 118 func (params *CreateIncomingPhoneNumberLocalParams) SetStatusCallbackMethod(StatusCallbackMethod string) *CreateIncomingPhoneNumberLocalParams { 119 params.StatusCallbackMethod = &StatusCallbackMethod 120 return params 121 } 122 func (params *CreateIncomingPhoneNumberLocalParams) SetVoiceApplicationSid(VoiceApplicationSid string) *CreateIncomingPhoneNumberLocalParams { 123 params.VoiceApplicationSid = &VoiceApplicationSid 124 return params 125 } 126 func (params *CreateIncomingPhoneNumberLocalParams) SetVoiceCallerIdLookup(VoiceCallerIdLookup bool) *CreateIncomingPhoneNumberLocalParams { 127 params.VoiceCallerIdLookup = &VoiceCallerIdLookup 128 return params 129 } 130 func (params *CreateIncomingPhoneNumberLocalParams) SetVoiceFallbackMethod(VoiceFallbackMethod string) *CreateIncomingPhoneNumberLocalParams { 131 params.VoiceFallbackMethod = &VoiceFallbackMethod 132 return params 133 } 134 func (params *CreateIncomingPhoneNumberLocalParams) SetVoiceFallbackUrl(VoiceFallbackUrl string) *CreateIncomingPhoneNumberLocalParams { 135 params.VoiceFallbackUrl = &VoiceFallbackUrl 136 return params 137 } 138 func (params *CreateIncomingPhoneNumberLocalParams) SetVoiceMethod(VoiceMethod string) *CreateIncomingPhoneNumberLocalParams { 139 params.VoiceMethod = &VoiceMethod 140 return params 141 } 142 func (params *CreateIncomingPhoneNumberLocalParams) SetVoiceUrl(VoiceUrl string) *CreateIncomingPhoneNumberLocalParams { 143 params.VoiceUrl = &VoiceUrl 144 return params 145 } 146 func (params *CreateIncomingPhoneNumberLocalParams) SetIdentitySid(IdentitySid string) *CreateIncomingPhoneNumberLocalParams { 147 params.IdentitySid = &IdentitySid 148 return params 149 } 150 func (params *CreateIncomingPhoneNumberLocalParams) SetAddressSid(AddressSid string) *CreateIncomingPhoneNumberLocalParams { 151 params.AddressSid = &AddressSid 152 return params 153 } 154 func (params *CreateIncomingPhoneNumberLocalParams) SetEmergencyStatus(EmergencyStatus string) *CreateIncomingPhoneNumberLocalParams { 155 params.EmergencyStatus = &EmergencyStatus 156 return params 157 } 158 func (params *CreateIncomingPhoneNumberLocalParams) SetEmergencyAddressSid(EmergencyAddressSid string) *CreateIncomingPhoneNumberLocalParams { 159 params.EmergencyAddressSid = &EmergencyAddressSid 160 return params 161 } 162 func (params *CreateIncomingPhoneNumberLocalParams) SetTrunkSid(TrunkSid string) *CreateIncomingPhoneNumberLocalParams { 163 params.TrunkSid = &TrunkSid 164 return params 165 } 166 func (params *CreateIncomingPhoneNumberLocalParams) SetVoiceReceiveMode(VoiceReceiveMode string) *CreateIncomingPhoneNumberLocalParams { 167 params.VoiceReceiveMode = &VoiceReceiveMode 168 return params 169 } 170 func (params *CreateIncomingPhoneNumberLocalParams) SetBundleSid(BundleSid string) *CreateIncomingPhoneNumberLocalParams { 171 params.BundleSid = &BundleSid 172 return params 173 } 174 175 // 176 func (c *ApiService) CreateIncomingPhoneNumberLocal(params *CreateIncomingPhoneNumberLocalParams) (*ApiV2010IncomingPhoneNumberLocal, error) { 177 path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json" 178 if params != nil && params.PathAccountSid != nil { 179 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 180 } else { 181 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 182 } 183 184 data := url.Values{} 185 headers := make(map[string]interface{}) 186 187 if params != nil && params.PhoneNumber != nil { 188 data.Set("PhoneNumber", *params.PhoneNumber) 189 } 190 if params != nil && params.ApiVersion != nil { 191 data.Set("ApiVersion", *params.ApiVersion) 192 } 193 if params != nil && params.FriendlyName != nil { 194 data.Set("FriendlyName", *params.FriendlyName) 195 } 196 if params != nil && params.SmsApplicationSid != nil { 197 data.Set("SmsApplicationSid", *params.SmsApplicationSid) 198 } 199 if params != nil && params.SmsFallbackMethod != nil { 200 data.Set("SmsFallbackMethod", *params.SmsFallbackMethod) 201 } 202 if params != nil && params.SmsFallbackUrl != nil { 203 data.Set("SmsFallbackUrl", *params.SmsFallbackUrl) 204 } 205 if params != nil && params.SmsMethod != nil { 206 data.Set("SmsMethod", *params.SmsMethod) 207 } 208 if params != nil && params.SmsUrl != nil { 209 data.Set("SmsUrl", *params.SmsUrl) 210 } 211 if params != nil && params.StatusCallback != nil { 212 data.Set("StatusCallback", *params.StatusCallback) 213 } 214 if params != nil && params.StatusCallbackMethod != nil { 215 data.Set("StatusCallbackMethod", *params.StatusCallbackMethod) 216 } 217 if params != nil && params.VoiceApplicationSid != nil { 218 data.Set("VoiceApplicationSid", *params.VoiceApplicationSid) 219 } 220 if params != nil && params.VoiceCallerIdLookup != nil { 221 data.Set("VoiceCallerIdLookup", fmt.Sprint(*params.VoiceCallerIdLookup)) 222 } 223 if params != nil && params.VoiceFallbackMethod != nil { 224 data.Set("VoiceFallbackMethod", *params.VoiceFallbackMethod) 225 } 226 if params != nil && params.VoiceFallbackUrl != nil { 227 data.Set("VoiceFallbackUrl", *params.VoiceFallbackUrl) 228 } 229 if params != nil && params.VoiceMethod != nil { 230 data.Set("VoiceMethod", *params.VoiceMethod) 231 } 232 if params != nil && params.VoiceUrl != nil { 233 data.Set("VoiceUrl", *params.VoiceUrl) 234 } 235 if params != nil && params.IdentitySid != nil { 236 data.Set("IdentitySid", *params.IdentitySid) 237 } 238 if params != nil && params.AddressSid != nil { 239 data.Set("AddressSid", *params.AddressSid) 240 } 241 if params != nil && params.EmergencyStatus != nil { 242 data.Set("EmergencyStatus", *params.EmergencyStatus) 243 } 244 if params != nil && params.EmergencyAddressSid != nil { 245 data.Set("EmergencyAddressSid", *params.EmergencyAddressSid) 246 } 247 if params != nil && params.TrunkSid != nil { 248 data.Set("TrunkSid", *params.TrunkSid) 249 } 250 if params != nil && params.VoiceReceiveMode != nil { 251 data.Set("VoiceReceiveMode", *params.VoiceReceiveMode) 252 } 253 if params != nil && params.BundleSid != nil { 254 data.Set("BundleSid", *params.BundleSid) 255 } 256 257 resp, err := c.requestHandler.Post(c.baseURL+path, data, headers) 258 if err != nil { 259 return nil, err 260 } 261 262 defer resp.Body.Close() 263 264 ps := &ApiV2010IncomingPhoneNumberLocal{} 265 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 266 return nil, err 267 } 268 269 return ps, err 270 } 271 272 // Optional parameters for the method 'ListIncomingPhoneNumberLocal' 273 type ListIncomingPhoneNumberLocalParams struct { 274 // The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the resources to read. 275 PathAccountSid *string `json:"PathAccountSid,omitempty"` 276 // Whether to include phone numbers new to the Twilio platform. Can be: `true` or `false` and the default is `true`. 277 Beta *bool `json:"Beta,omitempty"` 278 // A string that identifies the resources to read. 279 FriendlyName *string `json:"FriendlyName,omitempty"` 280 // The phone numbers of the IncomingPhoneNumber resources to read. You can specify partial numbers and use '*' as a wildcard for any digit. 281 PhoneNumber *string `json:"PhoneNumber,omitempty"` 282 // Whether to include phone numbers based on their origin. Can be: `twilio` or `hosted`. By default, phone numbers of all origin are included. 283 Origin *string `json:"Origin,omitempty"` 284 // How many resources to return in each list page. The default is 50, and the maximum is 1000. 285 PageSize *int `json:"PageSize,omitempty"` 286 // Max number of records to return. 287 Limit *int `json:"limit,omitempty"` 288 } 289 290 func (params *ListIncomingPhoneNumberLocalParams) SetPathAccountSid(PathAccountSid string) *ListIncomingPhoneNumberLocalParams { 291 params.PathAccountSid = &PathAccountSid 292 return params 293 } 294 func (params *ListIncomingPhoneNumberLocalParams) SetBeta(Beta bool) *ListIncomingPhoneNumberLocalParams { 295 params.Beta = &Beta 296 return params 297 } 298 func (params *ListIncomingPhoneNumberLocalParams) SetFriendlyName(FriendlyName string) *ListIncomingPhoneNumberLocalParams { 299 params.FriendlyName = &FriendlyName 300 return params 301 } 302 func (params *ListIncomingPhoneNumberLocalParams) SetPhoneNumber(PhoneNumber string) *ListIncomingPhoneNumberLocalParams { 303 params.PhoneNumber = &PhoneNumber 304 return params 305 } 306 func (params *ListIncomingPhoneNumberLocalParams) SetOrigin(Origin string) *ListIncomingPhoneNumberLocalParams { 307 params.Origin = &Origin 308 return params 309 } 310 func (params *ListIncomingPhoneNumberLocalParams) SetPageSize(PageSize int) *ListIncomingPhoneNumberLocalParams { 311 params.PageSize = &PageSize 312 return params 313 } 314 func (params *ListIncomingPhoneNumberLocalParams) SetLimit(Limit int) *ListIncomingPhoneNumberLocalParams { 315 params.Limit = &Limit 316 return params 317 } 318 319 // Retrieve a single page of IncomingPhoneNumberLocal records from the API. Request is executed immediately. 320 func (c *ApiService) PageIncomingPhoneNumberLocal(params *ListIncomingPhoneNumberLocalParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberLocalResponse, error) { 321 path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/Local.json" 322 323 if params != nil && params.PathAccountSid != nil { 324 path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1) 325 } else { 326 path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1) 327 } 328 329 data := url.Values{} 330 headers := make(map[string]interface{}) 331 332 if params != nil && params.Beta != nil { 333 data.Set("Beta", fmt.Sprint(*params.Beta)) 334 } 335 if params != nil && params.FriendlyName != nil { 336 data.Set("FriendlyName", *params.FriendlyName) 337 } 338 if params != nil && params.PhoneNumber != nil { 339 data.Set("PhoneNumber", *params.PhoneNumber) 340 } 341 if params != nil && params.Origin != nil { 342 data.Set("Origin", *params.Origin) 343 } 344 if params != nil && params.PageSize != nil { 345 data.Set("PageSize", fmt.Sprint(*params.PageSize)) 346 } 347 348 if pageToken != "" { 349 data.Set("PageToken", pageToken) 350 } 351 if pageNumber != "" { 352 data.Set("Page", pageNumber) 353 } 354 355 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 356 if err != nil { 357 return nil, err 358 } 359 360 defer resp.Body.Close() 361 362 ps := &ListIncomingPhoneNumberLocalResponse{} 363 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 364 return nil, err 365 } 366 367 return ps, err 368 } 369 370 // Lists IncomingPhoneNumberLocal records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning. 371 func (c *ApiService) ListIncomingPhoneNumberLocal(params *ListIncomingPhoneNumberLocalParams) ([]ApiV2010IncomingPhoneNumberLocal, error) { 372 response, errors := c.StreamIncomingPhoneNumberLocal(params) 373 374 records := make([]ApiV2010IncomingPhoneNumberLocal, 0) 375 for record := range response { 376 records = append(records, record) 377 } 378 379 if err := <-errors; err != nil { 380 return nil, err 381 } 382 383 return records, nil 384 } 385 386 // Streams IncomingPhoneNumberLocal records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached. 387 func (c *ApiService) StreamIncomingPhoneNumberLocal(params *ListIncomingPhoneNumberLocalParams) (chan ApiV2010IncomingPhoneNumberLocal, chan error) { 388 if params == nil { 389 params = &ListIncomingPhoneNumberLocalParams{} 390 } 391 params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit)) 392 393 recordChannel := make(chan ApiV2010IncomingPhoneNumberLocal, 1) 394 errorChannel := make(chan error, 1) 395 396 response, err := c.PageIncomingPhoneNumberLocal(params, "", "") 397 if err != nil { 398 errorChannel <- err 399 close(recordChannel) 400 close(errorChannel) 401 } else { 402 go c.streamIncomingPhoneNumberLocal(response, params, recordChannel, errorChannel) 403 } 404 405 return recordChannel, errorChannel 406 } 407 408 func (c *ApiService) streamIncomingPhoneNumberLocal(response *ListIncomingPhoneNumberLocalResponse, params *ListIncomingPhoneNumberLocalParams, recordChannel chan ApiV2010IncomingPhoneNumberLocal, errorChannel chan error) { 409 curRecord := 1 410 411 for response != nil { 412 responseRecords := response.IncomingPhoneNumbers 413 for item := range responseRecords { 414 recordChannel <- responseRecords[item] 415 curRecord += 1 416 if params.Limit != nil && *params.Limit < curRecord { 417 close(recordChannel) 418 close(errorChannel) 419 return 420 } 421 } 422 423 record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberLocalResponse) 424 if err != nil { 425 errorChannel <- err 426 break 427 } else if record == nil { 428 break 429 } 430 431 response = record.(*ListIncomingPhoneNumberLocalResponse) 432 } 433 434 close(recordChannel) 435 close(errorChannel) 436 } 437 438 func (c *ApiService) getNextListIncomingPhoneNumberLocalResponse(nextPageUrl string) (interface{}, error) { 439 if nextPageUrl == "" { 440 return nil, nil 441 } 442 resp, err := c.requestHandler.Get(nextPageUrl, nil, nil) 443 if err != nil { 444 return nil, err 445 } 446 447 defer resp.Body.Close() 448 449 ps := &ListIncomingPhoneNumberLocalResponse{} 450 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 451 return nil, err 452 } 453 return ps, nil 454 }