github.com/twilio/twilio-go@v1.20.1/rest/api/v2010/accounts_available_phone_numbers_shared_cost.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 'ListAvailablePhoneNumberSharedCost'
    27  type ListAvailablePhoneNumberSharedCostParams struct {
    28  	// The SID of the [Account](https://www.twilio.com/docs/iam/api/account) requesting the AvailablePhoneNumber resources.
    29  	PathAccountSid *string `json:"PathAccountSid,omitempty"`
    30  	// The area code of the phone numbers to read. Applies to only phone numbers in the US and Canada.
    31  	AreaCode *int `json:"AreaCode,omitempty"`
    32  	// The pattern on which to match phone numbers. Valid characters are `*`, `0-9`, `a-z`, and `A-Z`. The `*` character matches any single digit. For examples, see [Example 2](https://www.twilio.com/docs/phone-numbers/api/availablephonenumber-resource#local-get-basic-example-2) and [Example 3](https://www.twilio.com/docs/phone-numbers/api/availablephonenumber-resource#local-get-basic-example-3). If specified, this value must have at least two characters.
    33  	Contains *string `json:"Contains,omitempty"`
    34  	// Whether the phone numbers can receive text messages. Can be: `true` or `false`.
    35  	SmsEnabled *bool `json:"SmsEnabled,omitempty"`
    36  	// Whether the phone numbers can receive MMS messages. Can be: `true` or `false`.
    37  	MmsEnabled *bool `json:"MmsEnabled,omitempty"`
    38  	// Whether the phone numbers can receive calls. Can be: `true` or `false`.
    39  	VoiceEnabled *bool `json:"VoiceEnabled,omitempty"`
    40  	// Whether to exclude phone numbers that require an [Address](https://www.twilio.com/docs/usage/api/address). Can be: `true` or `false` and the default is `false`.
    41  	ExcludeAllAddressRequired *bool `json:"ExcludeAllAddressRequired,omitempty"`
    42  	// Whether to exclude phone numbers that require a local [Address](https://www.twilio.com/docs/usage/api/address). Can be: `true` or `false` and the default is `false`.
    43  	ExcludeLocalAddressRequired *bool `json:"ExcludeLocalAddressRequired,omitempty"`
    44  	// Whether to exclude phone numbers that require a foreign [Address](https://www.twilio.com/docs/usage/api/address). Can be: `true` or `false` and the default is `false`.
    45  	ExcludeForeignAddressRequired *bool `json:"ExcludeForeignAddressRequired,omitempty"`
    46  	// Whether to read phone numbers that are new to the Twilio platform. Can be: `true` or `false` and the default is `true`.
    47  	Beta *bool `json:"Beta,omitempty"`
    48  	// Given a phone number, find a geographically close number within `distance` miles. Distance defaults to 25 miles. Applies to only phone numbers in the US and Canada.
    49  	NearNumber *string `json:"NearNumber,omitempty"`
    50  	// Given a latitude/longitude pair `lat,long` find geographically close numbers within `distance` miles. Applies to only phone numbers in the US and Canada.
    51  	NearLatLong *string `json:"NearLatLong,omitempty"`
    52  	// The search radius, in miles, for a `near_` query.  Can be up to `500` and the default is `25`. Applies to only phone numbers in the US and Canada.
    53  	Distance *int `json:"Distance,omitempty"`
    54  	// Limit results to a particular postal code. Given a phone number, search within the same postal code as that number. Applies to only phone numbers in the US and Canada.
    55  	InPostalCode *string `json:"InPostalCode,omitempty"`
    56  	// Limit results to a particular region, state, or province. Given a phone number, search within the same region as that number. Applies to only phone numbers in the US and Canada.
    57  	InRegion *string `json:"InRegion,omitempty"`
    58  	// Limit results to a specific rate center, or given a phone number search within the same rate center as that number. Requires `in_lata` to be set as well. Applies to only phone numbers in the US and Canada.
    59  	InRateCenter *string `json:"InRateCenter,omitempty"`
    60  	// Limit results to a specific local access and transport area ([LATA](https://en.wikipedia.org/wiki/Local_access_and_transport_area)). Given a phone number, search within the same [LATA](https://en.wikipedia.org/wiki/Local_access_and_transport_area) as that number. Applies to only phone numbers in the US and Canada.
    61  	InLata *string `json:"InLata,omitempty"`
    62  	// Limit results to a particular locality or city. Given a phone number, search within the same Locality as that number.
    63  	InLocality *string `json:"InLocality,omitempty"`
    64  	// Whether the phone numbers can receive faxes. Can be: `true` or `false`.
    65  	FaxEnabled *bool `json:"FaxEnabled,omitempty"`
    66  	// How many resources to return in each list page. The default is 50, and the maximum is 1000.
    67  	PageSize *int `json:"PageSize,omitempty"`
    68  	// Max number of records to return.
    69  	Limit *int `json:"limit,omitempty"`
    70  }
    71  
    72  func (params *ListAvailablePhoneNumberSharedCostParams) SetPathAccountSid(PathAccountSid string) *ListAvailablePhoneNumberSharedCostParams {
    73  	params.PathAccountSid = &PathAccountSid
    74  	return params
    75  }
    76  func (params *ListAvailablePhoneNumberSharedCostParams) SetAreaCode(AreaCode int) *ListAvailablePhoneNumberSharedCostParams {
    77  	params.AreaCode = &AreaCode
    78  	return params
    79  }
    80  func (params *ListAvailablePhoneNumberSharedCostParams) SetContains(Contains string) *ListAvailablePhoneNumberSharedCostParams {
    81  	params.Contains = &Contains
    82  	return params
    83  }
    84  func (params *ListAvailablePhoneNumberSharedCostParams) SetSmsEnabled(SmsEnabled bool) *ListAvailablePhoneNumberSharedCostParams {
    85  	params.SmsEnabled = &SmsEnabled
    86  	return params
    87  }
    88  func (params *ListAvailablePhoneNumberSharedCostParams) SetMmsEnabled(MmsEnabled bool) *ListAvailablePhoneNumberSharedCostParams {
    89  	params.MmsEnabled = &MmsEnabled
    90  	return params
    91  }
    92  func (params *ListAvailablePhoneNumberSharedCostParams) SetVoiceEnabled(VoiceEnabled bool) *ListAvailablePhoneNumberSharedCostParams {
    93  	params.VoiceEnabled = &VoiceEnabled
    94  	return params
    95  }
    96  func (params *ListAvailablePhoneNumberSharedCostParams) SetExcludeAllAddressRequired(ExcludeAllAddressRequired bool) *ListAvailablePhoneNumberSharedCostParams {
    97  	params.ExcludeAllAddressRequired = &ExcludeAllAddressRequired
    98  	return params
    99  }
   100  func (params *ListAvailablePhoneNumberSharedCostParams) SetExcludeLocalAddressRequired(ExcludeLocalAddressRequired bool) *ListAvailablePhoneNumberSharedCostParams {
   101  	params.ExcludeLocalAddressRequired = &ExcludeLocalAddressRequired
   102  	return params
   103  }
   104  func (params *ListAvailablePhoneNumberSharedCostParams) SetExcludeForeignAddressRequired(ExcludeForeignAddressRequired bool) *ListAvailablePhoneNumberSharedCostParams {
   105  	params.ExcludeForeignAddressRequired = &ExcludeForeignAddressRequired
   106  	return params
   107  }
   108  func (params *ListAvailablePhoneNumberSharedCostParams) SetBeta(Beta bool) *ListAvailablePhoneNumberSharedCostParams {
   109  	params.Beta = &Beta
   110  	return params
   111  }
   112  func (params *ListAvailablePhoneNumberSharedCostParams) SetNearNumber(NearNumber string) *ListAvailablePhoneNumberSharedCostParams {
   113  	params.NearNumber = &NearNumber
   114  	return params
   115  }
   116  func (params *ListAvailablePhoneNumberSharedCostParams) SetNearLatLong(NearLatLong string) *ListAvailablePhoneNumberSharedCostParams {
   117  	params.NearLatLong = &NearLatLong
   118  	return params
   119  }
   120  func (params *ListAvailablePhoneNumberSharedCostParams) SetDistance(Distance int) *ListAvailablePhoneNumberSharedCostParams {
   121  	params.Distance = &Distance
   122  	return params
   123  }
   124  func (params *ListAvailablePhoneNumberSharedCostParams) SetInPostalCode(InPostalCode string) *ListAvailablePhoneNumberSharedCostParams {
   125  	params.InPostalCode = &InPostalCode
   126  	return params
   127  }
   128  func (params *ListAvailablePhoneNumberSharedCostParams) SetInRegion(InRegion string) *ListAvailablePhoneNumberSharedCostParams {
   129  	params.InRegion = &InRegion
   130  	return params
   131  }
   132  func (params *ListAvailablePhoneNumberSharedCostParams) SetInRateCenter(InRateCenter string) *ListAvailablePhoneNumberSharedCostParams {
   133  	params.InRateCenter = &InRateCenter
   134  	return params
   135  }
   136  func (params *ListAvailablePhoneNumberSharedCostParams) SetInLata(InLata string) *ListAvailablePhoneNumberSharedCostParams {
   137  	params.InLata = &InLata
   138  	return params
   139  }
   140  func (params *ListAvailablePhoneNumberSharedCostParams) SetInLocality(InLocality string) *ListAvailablePhoneNumberSharedCostParams {
   141  	params.InLocality = &InLocality
   142  	return params
   143  }
   144  func (params *ListAvailablePhoneNumberSharedCostParams) SetFaxEnabled(FaxEnabled bool) *ListAvailablePhoneNumberSharedCostParams {
   145  	params.FaxEnabled = &FaxEnabled
   146  	return params
   147  }
   148  func (params *ListAvailablePhoneNumberSharedCostParams) SetPageSize(PageSize int) *ListAvailablePhoneNumberSharedCostParams {
   149  	params.PageSize = &PageSize
   150  	return params
   151  }
   152  func (params *ListAvailablePhoneNumberSharedCostParams) SetLimit(Limit int) *ListAvailablePhoneNumberSharedCostParams {
   153  	params.Limit = &Limit
   154  	return params
   155  }
   156  
   157  // Retrieve a single page of AvailablePhoneNumberSharedCost records from the API. Request is executed immediately.
   158  func (c *ApiService) PageAvailablePhoneNumberSharedCost(CountryCode string, params *ListAvailablePhoneNumberSharedCostParams, pageToken, pageNumber string) (*ListAvailablePhoneNumberSharedCostResponse, error) {
   159  	path := "/2010-04-01/Accounts/{AccountSid}/AvailablePhoneNumbers/{CountryCode}/SharedCost.json"
   160  
   161  	if params != nil && params.PathAccountSid != nil {
   162  		path = strings.Replace(path, "{"+"AccountSid"+"}", *params.PathAccountSid, -1)
   163  	} else {
   164  		path = strings.Replace(path, "{"+"AccountSid"+"}", c.requestHandler.Client.AccountSid(), -1)
   165  	}
   166  	path = strings.Replace(path, "{"+"CountryCode"+"}", CountryCode, -1)
   167  
   168  	data := url.Values{}
   169  	headers := make(map[string]interface{})
   170  
   171  	if params != nil && params.AreaCode != nil {
   172  		data.Set("AreaCode", fmt.Sprint(*params.AreaCode))
   173  	}
   174  	if params != nil && params.Contains != nil {
   175  		data.Set("Contains", *params.Contains)
   176  	}
   177  	if params != nil && params.SmsEnabled != nil {
   178  		data.Set("SmsEnabled", fmt.Sprint(*params.SmsEnabled))
   179  	}
   180  	if params != nil && params.MmsEnabled != nil {
   181  		data.Set("MmsEnabled", fmt.Sprint(*params.MmsEnabled))
   182  	}
   183  	if params != nil && params.VoiceEnabled != nil {
   184  		data.Set("VoiceEnabled", fmt.Sprint(*params.VoiceEnabled))
   185  	}
   186  	if params != nil && params.ExcludeAllAddressRequired != nil {
   187  		data.Set("ExcludeAllAddressRequired", fmt.Sprint(*params.ExcludeAllAddressRequired))
   188  	}
   189  	if params != nil && params.ExcludeLocalAddressRequired != nil {
   190  		data.Set("ExcludeLocalAddressRequired", fmt.Sprint(*params.ExcludeLocalAddressRequired))
   191  	}
   192  	if params != nil && params.ExcludeForeignAddressRequired != nil {
   193  		data.Set("ExcludeForeignAddressRequired", fmt.Sprint(*params.ExcludeForeignAddressRequired))
   194  	}
   195  	if params != nil && params.Beta != nil {
   196  		data.Set("Beta", fmt.Sprint(*params.Beta))
   197  	}
   198  	if params != nil && params.NearNumber != nil {
   199  		data.Set("NearNumber", *params.NearNumber)
   200  	}
   201  	if params != nil && params.NearLatLong != nil {
   202  		data.Set("NearLatLong", *params.NearLatLong)
   203  	}
   204  	if params != nil && params.Distance != nil {
   205  		data.Set("Distance", fmt.Sprint(*params.Distance))
   206  	}
   207  	if params != nil && params.InPostalCode != nil {
   208  		data.Set("InPostalCode", *params.InPostalCode)
   209  	}
   210  	if params != nil && params.InRegion != nil {
   211  		data.Set("InRegion", *params.InRegion)
   212  	}
   213  	if params != nil && params.InRateCenter != nil {
   214  		data.Set("InRateCenter", *params.InRateCenter)
   215  	}
   216  	if params != nil && params.InLata != nil {
   217  		data.Set("InLata", *params.InLata)
   218  	}
   219  	if params != nil && params.InLocality != nil {
   220  		data.Set("InLocality", *params.InLocality)
   221  	}
   222  	if params != nil && params.FaxEnabled != nil {
   223  		data.Set("FaxEnabled", fmt.Sprint(*params.FaxEnabled))
   224  	}
   225  	if params != nil && params.PageSize != nil {
   226  		data.Set("PageSize", fmt.Sprint(*params.PageSize))
   227  	}
   228  
   229  	if pageToken != "" {
   230  		data.Set("PageToken", pageToken)
   231  	}
   232  	if pageNumber != "" {
   233  		data.Set("Page", pageNumber)
   234  	}
   235  
   236  	resp, err := c.requestHandler.Get(c.baseURL+path, data, headers)
   237  	if err != nil {
   238  		return nil, err
   239  	}
   240  
   241  	defer resp.Body.Close()
   242  
   243  	ps := &ListAvailablePhoneNumberSharedCostResponse{}
   244  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   245  		return nil, err
   246  	}
   247  
   248  	return ps, err
   249  }
   250  
   251  // Lists AvailablePhoneNumberSharedCost records from the API as a list. Unlike stream, this operation is eager and loads 'limit' records into memory before returning.
   252  func (c *ApiService) ListAvailablePhoneNumberSharedCost(CountryCode string, params *ListAvailablePhoneNumberSharedCostParams) ([]ApiV2010AvailablePhoneNumberSharedCost, error) {
   253  	response, errors := c.StreamAvailablePhoneNumberSharedCost(CountryCode, params)
   254  
   255  	records := make([]ApiV2010AvailablePhoneNumberSharedCost, 0)
   256  	for record := range response {
   257  		records = append(records, record)
   258  	}
   259  
   260  	if err := <-errors; err != nil {
   261  		return nil, err
   262  	}
   263  
   264  	return records, nil
   265  }
   266  
   267  // Streams AvailablePhoneNumberSharedCost records from the API as a channel stream. This operation lazily loads records as efficiently as possible until the limit is reached.
   268  func (c *ApiService) StreamAvailablePhoneNumberSharedCost(CountryCode string, params *ListAvailablePhoneNumberSharedCostParams) (chan ApiV2010AvailablePhoneNumberSharedCost, chan error) {
   269  	if params == nil {
   270  		params = &ListAvailablePhoneNumberSharedCostParams{}
   271  	}
   272  	params.SetPageSize(client.ReadLimits(params.PageSize, params.Limit))
   273  
   274  	recordChannel := make(chan ApiV2010AvailablePhoneNumberSharedCost, 1)
   275  	errorChannel := make(chan error, 1)
   276  
   277  	response, err := c.PageAvailablePhoneNumberSharedCost(CountryCode, params, "", "")
   278  	if err != nil {
   279  		errorChannel <- err
   280  		close(recordChannel)
   281  		close(errorChannel)
   282  	} else {
   283  		go c.streamAvailablePhoneNumberSharedCost(response, params, recordChannel, errorChannel)
   284  	}
   285  
   286  	return recordChannel, errorChannel
   287  }
   288  
   289  func (c *ApiService) streamAvailablePhoneNumberSharedCost(response *ListAvailablePhoneNumberSharedCostResponse, params *ListAvailablePhoneNumberSharedCostParams, recordChannel chan ApiV2010AvailablePhoneNumberSharedCost, errorChannel chan error) {
   290  	curRecord := 1
   291  
   292  	for response != nil {
   293  		responseRecords := response.AvailablePhoneNumbers
   294  		for item := range responseRecords {
   295  			recordChannel <- responseRecords[item]
   296  			curRecord += 1
   297  			if params.Limit != nil && *params.Limit < curRecord {
   298  				close(recordChannel)
   299  				close(errorChannel)
   300  				return
   301  			}
   302  		}
   303  
   304  		record, err := client.GetNext(c.baseURL, response, c.getNextListAvailablePhoneNumberSharedCostResponse)
   305  		if err != nil {
   306  			errorChannel <- err
   307  			break
   308  		} else if record == nil {
   309  			break
   310  		}
   311  
   312  		response = record.(*ListAvailablePhoneNumberSharedCostResponse)
   313  	}
   314  
   315  	close(recordChannel)
   316  	close(errorChannel)
   317  }
   318  
   319  func (c *ApiService) getNextListAvailablePhoneNumberSharedCostResponse(nextPageUrl string) (interface{}, error) {
   320  	if nextPageUrl == "" {
   321  		return nil, nil
   322  	}
   323  	resp, err := c.requestHandler.Get(nextPageUrl, nil, nil)
   324  	if err != nil {
   325  		return nil, err
   326  	}
   327  
   328  	defer resp.Body.Close()
   329  
   330  	ps := &ListAvailablePhoneNumberSharedCostResponse{}
   331  	if err := json.NewDecoder(resp.Body).Decode(ps); err != nil {
   332  		return nil, err
   333  	}
   334  	return ps, nil
   335  }