github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_incoming_phone_numbers.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 'CreateIncomingPhoneNumber'
    27  type CreateIncomingPhoneNumberParams 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 API version to use for incoming calls made to the new phone number. The default is `2010-04-01`.
    31  	ApiVersion *string `json:"ApiVersion,omitempty"`
    32  	// 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 new phone number.
    33  	FriendlyName *string `json:"FriendlyName,omitempty"`
    34  	// 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.
    35  	SmsApplicationSid *string `json:"SmsApplicationSid,omitempty"`
    36  	// The HTTP method that we should use to call `sms_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`.
    37  	SmsFallbackMethod *string `json:"SmsFallbackMethod,omitempty"`
    38  	// The URL that we should call when an error occurs while requesting or executing the TwiML defined by `sms_url`.
    39  	SmsFallbackUrl *string `json:"SmsFallbackUrl,omitempty"`
    40  	// The HTTP method that we should use to call `sms_url`. Can be: `GET` or `POST` and defaults to `POST`.
    41  	SmsMethod *string `json:"SmsMethod,omitempty"`
    42  	// The URL we should call when the new phone number receives an incoming SMS message.
    43  	SmsUrl *string `json:"SmsUrl,omitempty"`
    44  	// The URL we should call using the `status_callback_method` to send status information to your application.
    45  	StatusCallback *string `json:"StatusCallback,omitempty"`
    46  	// The HTTP method we should use to call `status_callback`. Can be: `GET` or `POST` and defaults to `POST`.
    47  	StatusCallbackMethod *string `json:"StatusCallbackMethod,omitempty"`
    48  	// 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.
    49  	VoiceApplicationSid *string `json:"VoiceApplicationSid,omitempty"`
    50  	// 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`.
    51  	VoiceCallerIdLookup *bool `json:"VoiceCallerIdLookup,omitempty"`
    52  	// The HTTP method that we should use to call `voice_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`.
    53  	VoiceFallbackMethod *string `json:"VoiceFallbackMethod,omitempty"`
    54  	// The URL that we should call when an error occurs retrieving or executing the TwiML requested by `url`.
    55  	VoiceFallbackUrl *string `json:"VoiceFallbackUrl,omitempty"`
    56  	// The HTTP method that we should use to call `voice_url`. Can be: `GET` or `POST` and defaults to `POST`.
    57  	VoiceMethod *string `json:"VoiceMethod,omitempty"`
    58  	// 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.
    59  	VoiceUrl *string `json:"VoiceUrl,omitempty"`
    60  	//
    61  	EmergencyStatus *string `json:"EmergencyStatus,omitempty"`
    62  	// The SID of the emergency address configuration to use for emergency calling from the new phone number.
    63  	EmergencyAddressSid *string `json:"EmergencyAddressSid,omitempty"`
    64  	// 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.
    65  	TrunkSid *string `json:"TrunkSid,omitempty"`
    66  	// The SID of the Identity resource that we should associate with the new phone number. Some regions require an identity to meet local regulations.
    67  	IdentitySid *string `json:"IdentitySid,omitempty"`
    68  	// The SID of the Address resource we should associate with the new phone number. Some regions require addresses to meet local regulations.
    69  	AddressSid *string `json:"AddressSid,omitempty"`
    70  	//
    71  	VoiceReceiveMode *string `json:"VoiceReceiveMode,omitempty"`
    72  	// The SID of the Bundle resource that you associate with the phone number. Some regions require a Bundle to meet local Regulations.
    73  	BundleSid *string `json:"BundleSid,omitempty"`
    74  	// 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.
    75  	PhoneNumber *string `json:"PhoneNumber,omitempty"`
    76  	// The desired area code for your new incoming phone number. Can be any three-digit, US or Canada area code. We will provision an available phone number within this area code for you. **You must provide an `area_code` or a `phone_number`.** (US and Canada only).
    77  	AreaCode *string `json:"AreaCode,omitempty"`
    78  }
    79  
    80  func (params *CreateIncomingPhoneNumberParams) SetPathAccountSid(PathAccountSid string) *CreateIncomingPhoneNumberParams {
    81  	params.PathAccountSid = &PathAccountSid
    82  	return params
    83  }
    84  func (params *CreateIncomingPhoneNumberParams) SetApiVersion(ApiVersion string) *CreateIncomingPhoneNumberParams {
    85  	params.ApiVersion = &ApiVersion
    86  	return params
    87  }
    88  func (params *CreateIncomingPhoneNumberParams) SetFriendlyName(FriendlyName string) *CreateIncomingPhoneNumberParams {
    89  	params.FriendlyName = &FriendlyName
    90  	return params
    91  }
    92  func (params *CreateIncomingPhoneNumberParams) SetSmsApplicationSid(SmsApplicationSid string) *CreateIncomingPhoneNumberParams {
    93  	params.SmsApplicationSid = &SmsApplicationSid
    94  	return params
    95  }
    96  func (params *CreateIncomingPhoneNumberParams) SetSmsFallbackMethod(SmsFallbackMethod string) *CreateIncomingPhoneNumberParams {
    97  	params.SmsFallbackMethod = &SmsFallbackMethod
    98  	return params
    99  }
   100  func (params *CreateIncomingPhoneNumberParams) SetSmsFallbackUrl(SmsFallbackUrl string) *CreateIncomingPhoneNumberParams {
   101  	params.SmsFallbackUrl = &SmsFallbackUrl
   102  	return params
   103  }
   104  func (params *CreateIncomingPhoneNumberParams) SetSmsMethod(SmsMethod string) *CreateIncomingPhoneNumberParams {
   105  	params.SmsMethod = &SmsMethod
   106  	return params
   107  }
   108  func (params *CreateIncomingPhoneNumberParams) SetSmsUrl(SmsUrl string) *CreateIncomingPhoneNumberParams {
   109  	params.SmsUrl = &SmsUrl
   110  	return params
   111  }
   112  func (params *CreateIncomingPhoneNumberParams) SetStatusCallback(StatusCallback string) *CreateIncomingPhoneNumberParams {
   113  	params.StatusCallback = &StatusCallback
   114  	return params
   115  }
   116  func (params *CreateIncomingPhoneNumberParams) SetStatusCallbackMethod(StatusCallbackMethod string) *CreateIncomingPhoneNumberParams {
   117  	params.StatusCallbackMethod = &StatusCallbackMethod
   118  	return params
   119  }
   120  func (params *CreateIncomingPhoneNumberParams) SetVoiceApplicationSid(VoiceApplicationSid string) *CreateIncomingPhoneNumberParams {
   121  	params.VoiceApplicationSid = &VoiceApplicationSid
   122  	return params
   123  }
   124  func (params *CreateIncomingPhoneNumberParams) SetVoiceCallerIdLookup(VoiceCallerIdLookup bool) *CreateIncomingPhoneNumberParams {
   125  	params.VoiceCallerIdLookup = &VoiceCallerIdLookup
   126  	return params
   127  }
   128  func (params *CreateIncomingPhoneNumberParams) SetVoiceFallbackMethod(VoiceFallbackMethod string) *CreateIncomingPhoneNumberParams {
   129  	params.VoiceFallbackMethod = &VoiceFallbackMethod
   130  	return params
   131  }
   132  func (params *CreateIncomingPhoneNumberParams) SetVoiceFallbackUrl(VoiceFallbackUrl string) *CreateIncomingPhoneNumberParams {
   133  	params.VoiceFallbackUrl = &VoiceFallbackUrl
   134  	return params
   135  }
   136  func (params *CreateIncomingPhoneNumberParams) SetVoiceMethod(VoiceMethod string) *CreateIncomingPhoneNumberParams {
   137  	params.VoiceMethod = &VoiceMethod
   138  	return params
   139  }
   140  func (params *CreateIncomingPhoneNumberParams) SetVoiceUrl(VoiceUrl string) *CreateIncomingPhoneNumberParams {
   141  	params.VoiceUrl = &VoiceUrl
   142  	return params
   143  }
   144  func (params *CreateIncomingPhoneNumberParams) SetEmergencyStatus(EmergencyStatus string) *CreateIncomingPhoneNumberParams {
   145  	params.EmergencyStatus = &EmergencyStatus
   146  	return params
   147  }
   148  func (params *CreateIncomingPhoneNumberParams) SetEmergencyAddressSid(EmergencyAddressSid string) *CreateIncomingPhoneNumberParams {
   149  	params.EmergencyAddressSid = &EmergencyAddressSid
   150  	return params
   151  }
   152  func (params *CreateIncomingPhoneNumberParams) SetTrunkSid(TrunkSid string) *CreateIncomingPhoneNumberParams {
   153  	params.TrunkSid = &TrunkSid
   154  	return params
   155  }
   156  func (params *CreateIncomingPhoneNumberParams) SetIdentitySid(IdentitySid string) *CreateIncomingPhoneNumberParams {
   157  	params.IdentitySid = &IdentitySid
   158  	return params
   159  }
   160  func (params *CreateIncomingPhoneNumberParams) SetAddressSid(AddressSid string) *CreateIncomingPhoneNumberParams {
   161  	params.AddressSid = &AddressSid
   162  	return params
   163  }
   164  func (params *CreateIncomingPhoneNumberParams) SetVoiceReceiveMode(VoiceReceiveMode string) *CreateIncomingPhoneNumberParams {
   165  	params.VoiceReceiveMode = &VoiceReceiveMode
   166  	return params
   167  }
   168  func (params *CreateIncomingPhoneNumberParams) SetBundleSid(BundleSid string) *CreateIncomingPhoneNumberParams {
   169  	params.BundleSid = &BundleSid
   170  	return params
   171  }
   172  func (params *CreateIncomingPhoneNumberParams) SetPhoneNumber(PhoneNumber string) *CreateIncomingPhoneNumberParams {
   173  	params.PhoneNumber = &PhoneNumber
   174  	return params
   175  }
   176  func (params *CreateIncomingPhoneNumberParams) SetAreaCode(AreaCode string) *CreateIncomingPhoneNumberParams {
   177  	params.AreaCode = &AreaCode
   178  	return params
   179  }
   180  
   181  // Purchase a phone-number for the account.
   182  func (c *ApiService) CreateIncomingPhoneNumber(params *CreateIncomingPhoneNumberParams) (*ApiV2010IncomingPhoneNumber, error) {
   183  	path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json"
   184  	if params != nil && params.PathAccountSid != nil {
   185  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
   186  	} else {
   187  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
   188  	}
   189  
   190  	data := url.Values{}
   191  	headers := make(map[string]interface{})
   192  
   193  	if params != nil && params.ApiVersion != nil {
   194  		data.Set("ApiVersion", *params.ApiVersion)
   195  	}
   196  	if params != nil && params.FriendlyName != nil {
   197  		data.Set("FriendlyName", *params.FriendlyName)
   198  	}
   199  	if params != nil && params.SmsApplicationSid != nil {
   200  		data.Set("SmsApplicationSid", *params.SmsApplicationSid)
   201  	}
   202  	if params != nil && params.SmsFallbackMethod != nil {
   203  		data.Set("SmsFallbackMethod", *params.SmsFallbackMethod)
   204  	}
   205  	if params != nil && params.SmsFallbackUrl != nil {
   206  		data.Set("SmsFallbackUrl", *params.SmsFallbackUrl)
   207  	}
   208  	if params != nil && params.SmsMethod != nil {
   209  		data.Set("SmsMethod", *params.SmsMethod)
   210  	}
   211  	if params != nil && params.SmsUrl != nil {
   212  		data.Set("SmsUrl", *params.SmsUrl)
   213  	}
   214  	if params != nil && params.StatusCallback != nil {
   215  		data.Set("StatusCallback", *params.StatusCallback)
   216  	}
   217  	if params != nil && params.StatusCallbackMethod != nil {
   218  		data.Set("StatusCallbackMethod", *params.StatusCallbackMethod)
   219  	}
   220  	if params != nil && params.VoiceApplicationSid != nil {
   221  		data.Set("VoiceApplicationSid", *params.VoiceApplicationSid)
   222  	}
   223  	if params != nil && params.VoiceCallerIdLookup != nil {
   224  		data.Set("VoiceCallerIdLookup", fmt.Sprint(*params.VoiceCallerIdLookup))
   225  	}
   226  	if params != nil && params.VoiceFallbackMethod != nil {
   227  		data.Set("VoiceFallbackMethod", *params.VoiceFallbackMethod)
   228  	}
   229  	if params != nil && params.VoiceFallbackUrl != nil {
   230  		data.Set("VoiceFallbackUrl", *params.VoiceFallbackUrl)
   231  	}
   232  	if params != nil && params.VoiceMethod != nil {
   233  		data.Set("VoiceMethod", *params.VoiceMethod)
   234  	}
   235  	if params != nil && params.VoiceUrl != nil {
   236  		data.Set("VoiceUrl", *params.VoiceUrl)
   237  	}
   238  	if params != nil && params.EmergencyStatus != nil {
   239  		data.Set("EmergencyStatus", *params.EmergencyStatus)
   240  	}
   241  	if params != nil && params.EmergencyAddressSid != nil {
   242  		data.Set("EmergencyAddressSid", *params.EmergencyAddressSid)
   243  	}
   244  	if params != nil && params.TrunkSid != nil {
   245  		data.Set("TrunkSid", *params.TrunkSid)
   246  	}
   247  	if params != nil && params.IdentitySid != nil {
   248  		data.Set("IdentitySid", *params.IdentitySid)
   249  	}
   250  	if params != nil && params.AddressSid != nil {
   251  		data.Set("AddressSid", *params.AddressSid)
   252  	}
   253  	if params != nil && params.VoiceReceiveMode != nil {
   254  		data.Set("VoiceReceiveMode", *params.VoiceReceiveMode)
   255  	}
   256  	if params != nil && params.BundleSid != nil {
   257  		data.Set("BundleSid", *params.BundleSid)
   258  	}
   259  	if params != nil && params.PhoneNumber != nil {
   260  		data.Set("PhoneNumber", *params.PhoneNumber)
   261  	}
   262  	if params != nil && params.AreaCode != nil {
   263  		data.Set("AreaCode", *params.AreaCode)
   264  	}
   265  
   266  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
   267  	if err != nil {
   268  		return nil, err
   269  	}
   270  
   271  	defer resp.Body.Close()
   272  
   273  	ps := &ApiV2010IncomingPhoneNumber{}
   274  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   275  		return nil, err
   276  	}
   277  
   278  	return ps, err
   279  }
   280  
   281  // Optional parameters for the method 'DeleteIncomingPhoneNumber'
   282  type DeleteIncomingPhoneNumberParams struct {
   283  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the IncomingPhoneNumber resources to delete.
   284  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
   285  }
   286  
   287  func (params *DeleteIncomingPhoneNumberParams) SetPathAccountSid(PathAccountSid string) *DeleteIncomingPhoneNumberParams {
   288  	params.PathAccountSid = &PathAccountSid
   289  	return params
   290  }
   291  
   292  // Delete a phone-numbers belonging to the account used to make the request.
   293  func (c *ApiService) DeleteIncomingPhoneNumber(Sid string, params *DeleteIncomingPhoneNumberParams) error {
   294  	path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"
   295  	if params != nil && params.PathAccountSid != nil {
   296  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
   297  	} else {
   298  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
   299  	}
   300  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
   301  
   302  	data := url.Values{}
   303  	headers := make(map[string]interface{})
   304  
   305  	resp, err := c.requestHandler.Delete(c.baseURL+path, data, headers)
   306  	if err != nil {
   307  		return err
   308  	}
   309  
   310  	defer resp.Body.Close()
   311  
   312  	return nil
   313  }
   314  
   315  // Optional parameters for the method 'FetchIncomingPhoneNumber'
   316  type FetchIncomingPhoneNumberParams struct {
   317  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the IncomingPhoneNumber resource to fetch.
   318  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
   319  }
   320  
   321  func (params *FetchIncomingPhoneNumberParams) SetPathAccountSid(PathAccountSid string) *FetchIncomingPhoneNumberParams {
   322  	params.PathAccountSid = &PathAccountSid
   323  	return params
   324  }
   325  
   326  // Fetch an incoming-phone-number belonging to the account used to make the request.
   327  func (c *ApiService) FetchIncomingPhoneNumber(Sid string, params *FetchIncomingPhoneNumberParams) (*ApiV2010IncomingPhoneNumber, error) {
   328  	path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"
   329  	if params != nil && params.PathAccountSid != nil {
   330  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
   331  	} else {
   332  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
   333  	}
   334  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
   335  
   336  	data := url.Values{}
   337  	headers := make(map[string]interface{})
   338  
   339  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
   340  	if err != nil {
   341  		return nil, err
   342  	}
   343  
   344  	defer resp.Body.Close()
   345  
   346  	ps := &ApiV2010IncomingPhoneNumber{}
   347  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   348  		return nil, err
   349  	}
   350  
   351  	return ps, err
   352  }
   353  
   354  // Optional parameters for the method 'ListIncomingPhoneNumber'
   355  type ListIncomingPhoneNumberParams struct {
   356  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the IncomingPhoneNumber resources to read.
   357  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
   358  	// Whether to include phone numbers new to the Twilio platform. Can be: `true` or `false` and the default is `true`.
   359  	Beta *bool `json:"Beta,omitempty"`
   360  	// A string that identifies the IncomingPhoneNumber resources to read.
   361  	FriendlyName *string `json:"FriendlyName,omitempty"`
   362  	// The phone numbers of the IncomingPhoneNumber resources to read. You can specify partial numbers and use '*' as a wildcard for any digit.
   363  	PhoneNumber *string `json:"PhoneNumber,omitempty"`
   364  	// Whether to include phone numbers based on their origin. Can be: `twilio` or `hosted`. By default, phone numbers of all origin are included.
   365  	Origin *string `json:"Origin,omitempty"`
   366  	// How many resources to return in each list page. The default is 50, and the maximum is 1000.
   367  	PageSize *int `json:"PageSize,omitempty"`
   368  	// Max number of records to return.
   369  	Limit *int `json:"limit,omitempty"`
   370  }
   371  
   372  func (params *ListIncomingPhoneNumberParams) SetPathAccountSid(PathAccountSid string) *ListIncomingPhoneNumberParams {
   373  	params.PathAccountSid = &PathAccountSid
   374  	return params
   375  }
   376  func (params *ListIncomingPhoneNumberParams) SetBeta(Beta bool) *ListIncomingPhoneNumberParams {
   377  	params.Beta = &Beta
   378  	return params
   379  }
   380  func (params *ListIncomingPhoneNumberParams) SetFriendlyName(FriendlyName string) *ListIncomingPhoneNumberParams {
   381  	params.FriendlyName = &FriendlyName
   382  	return params
   383  }
   384  func (params *ListIncomingPhoneNumberParams) SetPhoneNumber(PhoneNumber string) *ListIncomingPhoneNumberParams {
   385  	params.PhoneNumber = &PhoneNumber
   386  	return params
   387  }
   388  func (params *ListIncomingPhoneNumberParams) SetOrigin(Origin string) *ListIncomingPhoneNumberParams {
   389  	params.Origin = &Origin
   390  	return params
   391  }
   392  func (params *ListIncomingPhoneNumberParams) SetPageSize(PageSize int) *ListIncomingPhoneNumberParams {
   393  	params.PageSize = &PageSize
   394  	return params
   395  }
   396  func (params *ListIncomingPhoneNumberParams) SetLimit(Limit int) *ListIncomingPhoneNumberParams {
   397  	params.Limit = &Limit
   398  	return params
   399  }
   400  
   401  // Retrieve a single page of IncomingPhoneNumber records from the API. Request is executed immediately.
   402  func (c *ApiService) PageIncomingPhoneNumber(params *ListIncomingPhoneNumberParams, pageToken, pageNumber string) (*ListIncomingPhoneNumberResponse, error) {
   403  	path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers.json"
   404  
   405  	if params != nil && params.PathAccountSid != nil {
   406  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
   407  	} else {
   408  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
   409  	}
   410  
   411  	data := url.Values{}
   412  	headers := make(map[string]interface{})
   413  
   414  	if params != nil && params.Beta != nil {
   415  		data.Set("Beta", fmt.Sprint(*params.Beta))
   416  	}
   417  	if params != nil && params.FriendlyName != nil {
   418  		data.Set("FriendlyName", *params.FriendlyName)
   419  	}
   420  	if params != nil && params.PhoneNumber != nil {
   421  		data.Set("PhoneNumber", *params.PhoneNumber)
   422  	}
   423  	if params != nil && params.Origin != nil {
   424  		data.Set("Origin", *params.Origin)
   425  	}
   426  	if params != nil && params.PageSize != nil {
   427  		data.Set("PageSize", fmt.Sprint(*params.PageSize))
   428  	}
   429  
   430  	if pageToken != "" {
   431  		data.Set("PageToken", pageToken)
   432  	}
   433  	if pageNumber != "" {
   434  		data.Set("Page", pageNumber)
   435  	}
   436  
   437  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
   438  	if err != nil {
   439  		return nil, err
   440  	}
   441  
   442  	defer resp.Body.Close()
   443  
   444  	ps := &ListIncomingPhoneNumberResponse{}
   445  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   446  		return nil, err
   447  	}
   448  
   449  	return ps, err
   450  }
   451  
   452  // Lists IncomingPhoneNumber records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning.
   453  func (c *ApiService) ListIncomingPhoneNumber(params *ListIncomingPhoneNumberParams) ([]ApiV2010IncomingPhoneNumber, error) {
   454  	response, errors := c.StreamIncomingPhoneNumber(params)
   455  
   456  	records := make([]ApiV2010IncomingPhoneNumber, 0)
   457  	for record := range response {
   458  		records = append(records, record)
   459  	}
   460  
   461  	if err := <-errors; err != nil {
   462  		return nil, err
   463  	}
   464  
   465  	return records, nil
   466  }
   467  
   468  // Streams IncomingPhoneNumber records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached.
   469  func (c *ApiService) StreamIncomingPhoneNumber(params *ListIncomingPhoneNumberParams) (chan ApiV2010IncomingPhoneNumber, chan error) {
   470  	if params == nil {
   471  		params = &ListIncomingPhoneNumberParams{}
   472  	}
   473  	params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit))
   474  
   475  	recordChannel := make(chan ApiV2010IncomingPhoneNumber, 1)
   476  	errorChannel := make(chan error, 1)
   477  
   478  	response, err := c.PageIncomingPhoneNumber(params, "", "")
   479  	if err != nil {
   480  		errorChannel <- err
   481  		close(recordChannel)
   482  		close(errorChannel)
   483  	} else {
   484  		go c.streamIncomingPhoneNumber(response, params, recordChannel, errorChannel)
   485  	}
   486  
   487  	return recordChannel, errorChannel
   488  }
   489  
   490  func (c *ApiService) streamIncomingPhoneNumber(response *ListIncomingPhoneNumberResponse, params *ListIncomingPhoneNumberParams, recordChannel chan ApiV2010IncomingPhoneNumber, errorChannel chan error) {
   491  	curRecord := 1
   492  
   493  	for response != nil {
   494  		responseRecords := response.IncomingPhoneNumbers
   495  		for item := range responseRecords {
   496  			recordChannel <- responseRecords[item]
   497  			curRecord += 1
   498  			if params.Limit != nil && *params.Limit < curRecord {
   499  				close(recordChannel)
   500  				close(errorChannel)
   501  				return
   502  			}
   503  		}
   504  
   505  		record, err := client.GetNext(c.baseURL, response, c.getNextListIncomingPhoneNumberResponse)
   506  		if err != nil {
   507  			errorChannel <- err
   508  			break
   509  		} else if record == nil {
   510  			break
   511  		}
   512  
   513  		response = record.(*ListIncomingPhoneNumberResponse)
   514  	}
   515  
   516  	close(recordChannel)
   517  	close(errorChannel)
   518  }
   519  
   520  func (c *ApiService) getNextListIncomingPhoneNumberResponse(nextPageUrl string) (interface{}, error) {
   521  	if nextPageUrl == "" {
   522  		return nil, nil
   523  	}
   524  	resp, err := c.requestHandler.Get(nextPageUrl, nil, nil)
   525  	if err != nil {
   526  		return nil, err
   527  	}
   528  
   529  	defer resp.Body.Close()
   530  
   531  	ps := &ListIncomingPhoneNumberResponse{}
   532  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   533  		return nil, err
   534  	}
   535  	return ps, nil
   536  }
   537  
   538  // Optional parameters for the method 'UpdateIncomingPhoneNumber'
   539  type UpdateIncomingPhoneNumberParams struct {
   540  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the IncomingPhoneNumber resource to update.  For more information, see [Exchanging Numbers Between Subaccounts](https://www.twilio.com/docs/iam/api/subaccounts#exchanging-numbers).
   541  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
   542  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) that created the IncomingPhoneNumber resource to update.  For more information, see [Exchanging Numbers Between Subaccounts](https://www.twilio.com/docs/iam/api/subaccounts#exchanging-numbers).
   543  	AccountSid *string `json:"AccountSid,omitempty"`
   544  	// The API version to use for incoming calls made to the phone number. The default is `2010-04-01`.
   545  	ApiVersion *string `json:"ApiVersion,omitempty"`
   546  	// A descriptive string that you created to describe this phone number. It can be up to 64 characters long. By default, this is a formatted version of the phone number.
   547  	FriendlyName *string `json:"FriendlyName,omitempty"`
   548  	// The SID of the application that should handle SMS messages sent to the number. If an `sms_application_sid` is present, we ignore all of the `sms_*_url` urls and use those set on the application.
   549  	SmsApplicationSid *string `json:"SmsApplicationSid,omitempty"`
   550  	// The HTTP method that we should use to call `sms_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`.
   551  	SmsFallbackMethod *string `json:"SmsFallbackMethod,omitempty"`
   552  	// The URL that we should call when an error occurs while requesting or executing the TwiML defined by `sms_url`.
   553  	SmsFallbackUrl *string `json:"SmsFallbackUrl,omitempty"`
   554  	// The HTTP method that we should use to call `sms_url`. Can be: `GET` or `POST` and defaults to `POST`.
   555  	SmsMethod *string `json:"SmsMethod,omitempty"`
   556  	// The URL we should call when the phone number receives an incoming SMS message.
   557  	SmsUrl *string `json:"SmsUrl,omitempty"`
   558  	// The URL we should call using the `status_callback_method` to send status information to your application.
   559  	StatusCallback *string `json:"StatusCallback,omitempty"`
   560  	// The HTTP method we should use to call `status_callback`. Can be: `GET` or `POST` and defaults to `POST`.
   561  	StatusCallbackMethod *string `json:"StatusCallbackMethod,omitempty"`
   562  	// The SID of the application we should use to handle phone calls to the 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.
   563  	VoiceApplicationSid *string `json:"VoiceApplicationSid,omitempty"`
   564  	// 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`.
   565  	VoiceCallerIdLookup *bool `json:"VoiceCallerIdLookup,omitempty"`
   566  	// The HTTP method that we should use to call `voice_fallback_url`. Can be: `GET` or `POST` and defaults to `POST`.
   567  	VoiceFallbackMethod *string `json:"VoiceFallbackMethod,omitempty"`
   568  	// The URL that we should call when an error occurs retrieving or executing the TwiML requested by `url`.
   569  	VoiceFallbackUrl *string `json:"VoiceFallbackUrl,omitempty"`
   570  	// The HTTP method that we should use to call `voice_url`. Can be: `GET` or `POST` and defaults to `POST`.
   571  	VoiceMethod *string `json:"VoiceMethod,omitempty"`
   572  	// The URL that we should call to answer a call to the phone number. The `voice_url` will not be called if a `voice_application_sid` or a `trunk_sid` is set.
   573  	VoiceUrl *string `json:"VoiceUrl,omitempty"`
   574  	//
   575  	EmergencyStatus *string `json:"EmergencyStatus,omitempty"`
   576  	// The SID of the emergency address configuration to use for emergency calling from this phone number.
   577  	EmergencyAddressSid *string `json:"EmergencyAddressSid,omitempty"`
   578  	// The SID of the Trunk we should use to handle phone calls to the 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.
   579  	TrunkSid *string `json:"TrunkSid,omitempty"`
   580  	//
   581  	VoiceReceiveMode *string `json:"VoiceReceiveMode,omitempty"`
   582  	// The SID of the Identity resource that we should associate with the phone number. Some regions require an identity to meet local regulations.
   583  	IdentitySid *string `json:"IdentitySid,omitempty"`
   584  	// The SID of the Address resource we should associate with the phone number. Some regions require addresses to meet local regulations.
   585  	AddressSid *string `json:"AddressSid,omitempty"`
   586  	// The SID of the Bundle resource that you associate with the phone number. Some regions require a Bundle to meet local Regulations.
   587  	BundleSid *string `json:"BundleSid,omitempty"`
   588  }
   589  
   590  func (params *UpdateIncomingPhoneNumberParams) SetPathAccountSid(PathAccountSid string) *UpdateIncomingPhoneNumberParams {
   591  	params.PathAccountSid = &PathAccountSid
   592  	return params
   593  }
   594  func (params *UpdateIncomingPhoneNumberParams) SetAccountSid(AccountSid string) *UpdateIncomingPhoneNumberParams {
   595  	params.AccountSid = &AccountSid
   596  	return params
   597  }
   598  func (params *UpdateIncomingPhoneNumberParams) SetApiVersion(ApiVersion string) *UpdateIncomingPhoneNumberParams {
   599  	params.ApiVersion = &ApiVersion
   600  	return params
   601  }
   602  func (params *UpdateIncomingPhoneNumberParams) SetFriendlyName(FriendlyName string) *UpdateIncomingPhoneNumberParams {
   603  	params.FriendlyName = &FriendlyName
   604  	return params
   605  }
   606  func (params *UpdateIncomingPhoneNumberParams) SetSmsApplicationSid(SmsApplicationSid string) *UpdateIncomingPhoneNumberParams {
   607  	params.SmsApplicationSid = &SmsApplicationSid
   608  	return params
   609  }
   610  func (params *UpdateIncomingPhoneNumberParams) SetSmsFallbackMethod(SmsFallbackMethod string) *UpdateIncomingPhoneNumberParams {
   611  	params.SmsFallbackMethod = &SmsFallbackMethod
   612  	return params
   613  }
   614  func (params *UpdateIncomingPhoneNumberParams) SetSmsFallbackUrl(SmsFallbackUrl string) *UpdateIncomingPhoneNumberParams {
   615  	params.SmsFallbackUrl = &SmsFallbackUrl
   616  	return params
   617  }
   618  func (params *UpdateIncomingPhoneNumberParams) SetSmsMethod(SmsMethod string) *UpdateIncomingPhoneNumberParams {
   619  	params.SmsMethod = &SmsMethod
   620  	return params
   621  }
   622  func (params *UpdateIncomingPhoneNumberParams) SetSmsUrl(SmsUrl string) *UpdateIncomingPhoneNumberParams {
   623  	params.SmsUrl = &SmsUrl
   624  	return params
   625  }
   626  func (params *UpdateIncomingPhoneNumberParams) SetStatusCallback(StatusCallback string) *UpdateIncomingPhoneNumberParams {
   627  	params.StatusCallback = &StatusCallback
   628  	return params
   629  }
   630  func (params *UpdateIncomingPhoneNumberParams) SetStatusCallbackMethod(StatusCallbackMethod string) *UpdateIncomingPhoneNumberParams {
   631  	params.StatusCallbackMethod = &StatusCallbackMethod
   632  	return params
   633  }
   634  func (params *UpdateIncomingPhoneNumberParams) SetVoiceApplicationSid(VoiceApplicationSid string) *UpdateIncomingPhoneNumberParams {
   635  	params.VoiceApplicationSid = &VoiceApplicationSid
   636  	return params
   637  }
   638  func (params *UpdateIncomingPhoneNumberParams) SetVoiceCallerIdLookup(VoiceCallerIdLookup bool) *UpdateIncomingPhoneNumberParams {
   639  	params.VoiceCallerIdLookup = &VoiceCallerIdLookup
   640  	return params
   641  }
   642  func (params *UpdateIncomingPhoneNumberParams) SetVoiceFallbackMethod(VoiceFallbackMethod string) *UpdateIncomingPhoneNumberParams {
   643  	params.VoiceFallbackMethod = &VoiceFallbackMethod
   644  	return params
   645  }
   646  func (params *UpdateIncomingPhoneNumberParams) SetVoiceFallbackUrl(VoiceFallbackUrl string) *UpdateIncomingPhoneNumberParams {
   647  	params.VoiceFallbackUrl = &VoiceFallbackUrl
   648  	return params
   649  }
   650  func (params *UpdateIncomingPhoneNumberParams) SetVoiceMethod(VoiceMethod string) *UpdateIncomingPhoneNumberParams {
   651  	params.VoiceMethod = &VoiceMethod
   652  	return params
   653  }
   654  func (params *UpdateIncomingPhoneNumberParams) SetVoiceUrl(VoiceUrl string) *UpdateIncomingPhoneNumberParams {
   655  	params.VoiceUrl = &VoiceUrl
   656  	return params
   657  }
   658  func (params *UpdateIncomingPhoneNumberParams) SetEmergencyStatus(EmergencyStatus string) *UpdateIncomingPhoneNumberParams {
   659  	params.EmergencyStatus = &EmergencyStatus
   660  	return params
   661  }
   662  func (params *UpdateIncomingPhoneNumberParams) SetEmergencyAddressSid(EmergencyAddressSid string) *UpdateIncomingPhoneNumberParams {
   663  	params.EmergencyAddressSid = &EmergencyAddressSid
   664  	return params
   665  }
   666  func (params *UpdateIncomingPhoneNumberParams) SetTrunkSid(TrunkSid string) *UpdateIncomingPhoneNumberParams {
   667  	params.TrunkSid = &TrunkSid
   668  	return params
   669  }
   670  func (params *UpdateIncomingPhoneNumberParams) SetVoiceReceiveMode(VoiceReceiveMode string) *UpdateIncomingPhoneNumberParams {
   671  	params.VoiceReceiveMode = &VoiceReceiveMode
   672  	return params
   673  }
   674  func (params *UpdateIncomingPhoneNumberParams) SetIdentitySid(IdentitySid string) *UpdateIncomingPhoneNumberParams {
   675  	params.IdentitySid = &IdentitySid
   676  	return params
   677  }
   678  func (params *UpdateIncomingPhoneNumberParams) SetAddressSid(AddressSid string) *UpdateIncomingPhoneNumberParams {
   679  	params.AddressSid = &AddressSid
   680  	return params
   681  }
   682  func (params *UpdateIncomingPhoneNumberParams) SetBundleSid(BundleSid string) *UpdateIncomingPhoneNumberParams {
   683  	params.BundleSid = &BundleSid
   684  	return params
   685  }
   686  
   687  // Update an incoming-phone-number instance.
   688  func (c *ApiService) UpdateIncomingPhoneNumber(Sid string, params *UpdateIncomingPhoneNumberParams) (*ApiV2010IncomingPhoneNumber, error) {
   689  	path := "/2010-04-01/Accounts/{AccountSid}/IncomingPhoneNumbers/{Sid}.json"
   690  	if params != nil && params.PathAccountSid != nil {
   691  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
   692  	} else {
   693  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
   694  	}
   695  	path = strings.Replace(path, "{"+"Sid"+"}", Sid, -1)
   696  
   697  	data := url.Values{}
   698  	headers := make(map[string]interface{})
   699  
   700  	if params != nil && params.AccountSid != nil {
   701  		data.Set("AccountSid", *params.AccountSid)
   702  	}
   703  	if params != nil && params.ApiVersion != nil {
   704  		data.Set("ApiVersion", *params.ApiVersion)
   705  	}
   706  	if params != nil && params.FriendlyName != nil {
   707  		data.Set("FriendlyName", *params.FriendlyName)
   708  	}
   709  	if params != nil && params.SmsApplicationSid != nil {
   710  		data.Set("SmsApplicationSid", *params.SmsApplicationSid)
   711  	}
   712  	if params != nil && params.SmsFallbackMethod != nil {
   713  		data.Set("SmsFallbackMethod", *params.SmsFallbackMethod)
   714  	}
   715  	if params != nil && params.SmsFallbackUrl != nil {
   716  		data.Set("SmsFallbackUrl", *params.SmsFallbackUrl)
   717  	}
   718  	if params != nil && params.SmsMethod != nil {
   719  		data.Set("SmsMethod", *params.SmsMethod)
   720  	}
   721  	if params != nil && params.SmsUrl != nil {
   722  		data.Set("SmsUrl", *params.SmsUrl)
   723  	}
   724  	if params != nil && params.StatusCallback != nil {
   725  		data.Set("StatusCallback", *params.StatusCallback)
   726  	}
   727  	if params != nil && params.StatusCallbackMethod != nil {
   728  		data.Set("StatusCallbackMethod", *params.StatusCallbackMethod)
   729  	}
   730  	if params != nil && params.VoiceApplicationSid != nil {
   731  		data.Set("VoiceApplicationSid", *params.VoiceApplicationSid)
   732  	}
   733  	if params != nil && params.VoiceCallerIdLookup != nil {
   734  		data.Set("VoiceCallerIdLookup", fmt.Sprint(*params.VoiceCallerIdLookup))
   735  	}
   736  	if params != nil && params.VoiceFallbackMethod != nil {
   737  		data.Set("VoiceFallbackMethod", *params.VoiceFallbackMethod)
   738  	}
   739  	if params != nil && params.VoiceFallbackUrl != nil {
   740  		data.Set("VoiceFallbackUrl", *params.VoiceFallbackUrl)
   741  	}
   742  	if params != nil && params.VoiceMethod != nil {
   743  		data.Set("VoiceMethod", *params.VoiceMethod)
   744  	}
   745  	if params != nil && params.VoiceUrl != nil {
   746  		data.Set("VoiceUrl", *params.VoiceUrl)
   747  	}
   748  	if params != nil && params.EmergencyStatus != nil {
   749  		data.Set("EmergencyStatus", *params.EmergencyStatus)
   750  	}
   751  	if params != nil && params.EmergencyAddressSid != nil {
   752  		data.Set("EmergencyAddressSid", *params.EmergencyAddressSid)
   753  	}
   754  	if params != nil && params.TrunkSid != nil {
   755  		data.Set("TrunkSid", *params.TrunkSid)
   756  	}
   757  	if params != nil && params.VoiceReceiveMode != nil {
   758  		data.Set("VoiceReceiveMode", *params.VoiceReceiveMode)
   759  	}
   760  	if params != nil && params.IdentitySid != nil {
   761  		data.Set("IdentitySid", *params.IdentitySid)
   762  	}
   763  	if params != nil && params.AddressSid != nil {
   764  		data.Set("AddressSid", *params.AddressSid)
   765  	}
   766  	if params != nil && params.BundleSid != nil {
   767  		data.Set("BundleSid", *params.BundleSid)
   768  	}
   769  
   770  	resp, err := c.requestHandler.Post(c.baseURL+path, data, headers)
   771  	if err != nil {
   772  		return nil, err
   773  	}
   774  
   775  	defer resp.Body.Close()
   776  
   777  	ps := &ApiV2010IncomingPhoneNumber{}
   778  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   779  		return nil, err
   780  	}
   781  
   782  	return ps, err
   783  }