-
Notifications
You must be signed in to change notification settings - Fork 103
/
prices_number.go
78 lines (64 loc) · 2.23 KB
/
prices_number.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
package twilio
import (
"net/url"
"golang.org/x/net/context"
)
const phoneNumbersPathPart = "PhoneNumbers"
type PhoneNumberPriceService struct {
Countries *CountryPhoneNumberPriceService
}
type CountryPhoneNumberPriceService struct {
client *Client
}
type PhoneNumberPrice struct {
BasePrice string `json:"base_price"`
CurrentPrice string `json:"current_price"`
NumberType string `json:"number_type"`
}
type NumberPrice struct {
Country string `json:"country"`
IsoCountry string `json:"iso_country"`
PhoneNumberPrices []PhoneNumberPrice `json:"phone_number_prices"`
PriceUnit string `json:"price_unit"`
URL string `json:"url"`
}
type PriceCountry struct {
Country string `json:"country"`
IsoCountry string `json:"iso_country"`
URL string `json:"url"`
}
type CountriesPricePage struct {
Meta Meta `json:"meta"`
Countries []*PriceCountry `json:"countries"`
}
// returns the phone number price by country
func (cpnps *CountryPhoneNumberPriceService) Get(ctx context.Context, isoCountry string) (*NumberPrice, error) {
numberPrice := new(NumberPrice)
err := cpnps.client.GetResource(ctx, phoneNumbersPathPart+"/Countries", isoCountry, numberPrice)
return numberPrice, err
}
// returns a list of countries where Twilio phone numbers are supported
func (cpnps *CountryPhoneNumberPriceService) GetPage(ctx context.Context, data url.Values) (*CountriesPricePage, error) {
return cpnps.GetPageIterator(data).Next(ctx)
}
type CountryPricePageIterator struct {
p *PageIterator
}
// GetPageIterator returns an iterator which can be used to retrieve pages.
func (cpnps *CountryPhoneNumberPriceService) GetPageIterator(data url.Values) *CountryPricePageIterator {
iter := NewPageIterator(cpnps.client, data, phoneNumbersPathPart+"/Countries")
return &CountryPricePageIterator{
p: iter,
}
}
// Next returns the next page of resources. If there are no more resources,
// NoMoreResults is returned.
func (c *CountryPricePageIterator) Next(ctx context.Context) (*CountriesPricePage, error) {
cp := new(CountriesPricePage)
err := c.p.Next(ctx, cp)
if err != nil {
return nil, err
}
c.p.SetNextPageURI(cp.Meta.NextPageURL)
return cp, nil
}