github.com/twilio/twilio-go@v1.20.1/rest/lookups/v1/phone_numbers.go (about) 1 /* 2 * This code was generated by 3 * ___ _ _ _ _ _ _ ____ ____ ____ _ ____ ____ _ _ ____ ____ ____ ___ __ __ 4 * | | | | | | | | | __ | | |__| | __ | __ |___ |\ | |___ |__/ |__| | | | |__/ 5 * | |_|_| | |___ | |__| |__| | | | |__] |___ | \| |___ | \ | | | |__| | \ 6 * 7 * Twilio - Lookups 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 "net/url" 20 "strings" 21 ) 22 23 // Optional parameters for the method 'FetchPhoneNumber' 24 type FetchPhoneNumberParams struct { 25 // The [ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the phone number to fetch. This is used to specify the country when the phone number is provided in a national format. 26 CountryCode *string `json:"CountryCode,omitempty"` 27 // The type of information to return. Can be: `carrier` or `caller-name`. The default is null. Carrier information costs $0.005 per phone number looked up. Caller Name information is currently available only in the US and costs $0.01 per phone number looked up. To retrieve both types on information, specify this parameter twice; once with `carrier` and once with `caller-name` as the value. 28 Type *[]string `json:"Type,omitempty"` 29 // The `unique_name` of an Add-on you would like to invoke. Can be the `unique_name` of an Add-on that is installed on your account. You can specify multiple instances of this parameter to invoke multiple Add-ons. For more information about Add-ons, see the [Add-ons documentation](https://www.twilio.com/docs/add-ons). 30 AddOns *[]string `json:"AddOns,omitempty"` 31 // Data specific to the add-on you would like to invoke. The content and format of this value depends on the add-on. 32 AddOnsData *map[string]interface{} `json:"AddOnsData,omitempty"` 33 } 34 35 func (params *FetchPhoneNumberParams) SetCountryCode(CountryCode string) *FetchPhoneNumberParams { 36 params.CountryCode = &CountryCode 37 return params 38 } 39 func (params *FetchPhoneNumberParams) SetType(Type []string) *FetchPhoneNumberParams { 40 params.Type = &Type 41 return params 42 } 43 func (params *FetchPhoneNumberParams) SetAddOns(AddOns []string) *FetchPhoneNumberParams { 44 params.AddOns = &AddOns 45 return params 46 } 47 func (params *FetchPhoneNumberParams) SetAddOnsData(AddOnsData map[string]interface{}) *FetchPhoneNumberParams { 48 params.AddOnsData = &AddOnsData 49 return params 50 } 51 52 // 53 func (c *ApiService) FetchPhoneNumber(PhoneNumber string, params *FetchPhoneNumberParams) (*LookupsV1PhoneNumber, error) { 54 path := "/v1/PhoneNumbers/{PhoneNumber}" 55 path = strings.Replace(path, "{"+"PhoneNumber"+"}", PhoneNumber, -1) 56 57 data := url.Values{} 58 headers := make(map[string]interface{}) 59 60 if params != nil && params.CountryCode != nil { 61 data.Set("CountryCode", *params.CountryCode) 62 } 63 if params != nil && params.Type != nil { 64 for _, item := range *params.Type { 65 data.Add("Type", item) 66 } 67 } 68 if params != nil && params.AddOns != nil { 69 for _, item := range *params.AddOns { 70 data.Add("AddOns", item) 71 } 72 } 73 if params != nil && params.AddOnsData != nil { 74 v, err := json.Marshal(params.AddOnsData) 75 76 if err != nil { 77 return nil, err 78 } 79 80 data.Set("AddOnsData", string(v)) 81 } 82 83 resp, err := c.requestHandler.Get(c.baseURL+path, data, headers) 84 if err != nil { 85 return nil, err 86 } 87 88 defer resp.Body.Close() 89 90 ps := &LookupsV1PhoneNumber{} 91 if err := json.NewDecoder(resp.Body).Decode(ps); err != nil { 92 return nil, err 93 } 94 95 return ps, err 96 }