forked from saintpete/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 69
/
available_phone_numbers.go
101 lines (87 loc) · 3.37 KB
/
available_phone_numbers.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
package twilio
import (
"context"
"net/url"
)
const availableNumbersPath = "AvailablePhoneNumbers"
type AvailableNumberBase struct {
client *Client
pathPart string
}
type AvailableNumberService struct {
Local *AvailableNumberBase
Mobile *AvailableNumberBase
TollFree *AvailableNumberBase
SupportedCountries *SupportedCountriesService
}
// The subresources of the AvailableNumbers resource let you search for local, toll-free and
// mobile phone numbers that are available for you to purchase.
// See https://www.twilio.com/docs/api/rest/available-phone-numbers for details
type AvailableNumber struct {
FriendlyName string `json:"friendly_name"`
PhoneNumber PhoneNumber `json:"phone_number"`
Lata string `json:"lata"`
RateCenter string `json:"rate_center"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
Region string `json:"region"`
PostalCode string `json:"postal_code"`
ISOCountry string `json:"iso_country"`
Capabilities *NumberCapability `json:"capabilities"`
AddressRequirements string `json:"address_requirements"`
Beta bool `json:"beta"`
}
type AvailableNumberPage struct {
URI string `json:"uri"`
Numbers []*AvailableNumber `json:"available_phone_numbers"`
}
// GetPage returns a page of available phone numbers.
//
// For more information, see the Twilio documentation:
// https://www.twilio.com/docs/api/rest/available-phone-numbers#local
// https://www.twilio.com/docs/api/rest/available-phone-numbers#toll-free
// https://www.twilio.com/docs/api/rest/available-phone-numbers#mobile
func (s *AvailableNumberBase) GetPage(ctx context.Context, isoCountry string, filters url.Values) (*AvailableNumberPage, error) {
sr := new(AvailableNumberPage)
path := availableNumbersPath + "/" + isoCountry + "/" + s.pathPart
err := s.client.ListResource(ctx, path, filters, sr)
if err != nil {
return nil, err
}
return sr, nil
}
type SupportedCountriesService struct {
client *Client
}
type SupportedCountry struct {
// The ISO Country code to lookup phone numbers for.
CountryCode string `json:"country_code"`
Country string `json:"country"`
URI string `json:"uri"`
// If true, all phone numbers available in this country are new to the Twilio platform.
// If false, all numbers are not in the Twilio Phone Number Beta program.
Beta bool `json:"beta"`
SubresourceURIs map[string]string `json:"subresource_uris"`
}
type SupportedCountries struct {
URI string `json:"uri"`
Countries []*SupportedCountry `json:"countries"`
}
// Get returns supported countries.
// If beta is true, only include countries where phone numbers new to the Twilio platform are available.
// If false, do not include new inventory.
//
// See https://www.twilio.com/docs/phone-numbers/api/available-phone-numbers#countries
func (s *SupportedCountriesService) Get(ctx context.Context, beta bool) (*SupportedCountries, error) {
sc := new(SupportedCountries)
path := availableNumbersPath
data := url.Values{}
if beta {
data.Set("Beta", "true")
}
err := s.client.ListResource(ctx, path, data, sc)
if err != nil {
return nil, err
}
return sc, nil
}