forked from saintpete/twilio-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prices_voice.go
86 lines (72 loc) · 2.74 KB
/
prices_voice.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
package twilio
import (
"context"
"net/url"
)
const voicePathPart = "Voice"
type VoicePriceService struct {
Countries *CountryVoicePriceService
Numbers *NumberVoicePriceService
}
type CountryVoicePriceService struct {
client *Client
}
type NumberVoicePriceService struct {
client *Client
}
type PrefixPrice struct {
BasePrice string `json:"base_price"`
CurrentPrice string `json:"current_price"`
FriendlyName string `json:"friendly_name"`
Prefixes []string `json:"prefixes"`
}
type InboundPrice struct {
BasePrice string `json:"base_price"`
CurrentPrice string `json:"current_price"`
NumberType string `json:"number_type"`
}
type OutboundCallPrice struct {
BasePrice string `json:"base_price"`
CurrentPrice string `json:"current_price"`
}
type VoicePrice struct {
Country string `json:"country"`
IsoCountry string `json:"iso_country"`
OutboundPrefixPrices []PrefixPrice `json:"outbound_prefix_prices"`
InboundCallPrices []InboundPrice `json:"inbound_call_prices"`
PriceUnit string `json:"price_unit"`
URL string `json:"url"`
}
type VoiceNumberPrice struct {
Country string `json:"country"`
IsoCountry string `json:"iso_country"`
Number string `json:"number"`
InboundCallPrice InboundPrice `json:"inbound_call_price"`
OutboundCallPrice OutboundCallPrice `json:"outbound_call_price"`
PriceUnit string `json:"price_unit"`
URL string `json:"url"`
}
// returns the call price by country
func (cvps *CountryVoicePriceService) Get(ctx context.Context, isoCountry string) (*VoicePrice, error) {
voicePrice := new(VoicePrice)
err := cvps.client.GetResource(ctx, voicePathPart+"/Countries", isoCountry, voicePrice)
return voicePrice, err
}
// returns the call price by number
func (nvps *NumberVoicePriceService) Get(ctx context.Context, number string) (*VoiceNumberPrice, error) {
voiceNumPrice := new(VoiceNumberPrice)
err := nvps.client.GetResource(ctx, voicePathPart+"/Numbers", number, voiceNumPrice)
return voiceNumPrice, err
}
// returns a list of countries where Twilio voice services are available and the corresponding URL
// for retrieving the country specific voice prices.
func (cvps *CountryVoicePriceService) GetPage(ctx context.Context, data url.Values) (*CountriesPricePage, error) {
return cvps.GetPageIterator(data).Next(ctx)
}
// GetPageIterator returns an iterator which can be used to retrieve pages.
func (cvps *CountryVoicePriceService) GetPageIterator(data url.Values) *CountryPricePageIterator {
iter := NewPageIterator(cvps.client, data, voicePathPart+"/Countries")
return &CountryPricePageIterator{
p: iter,
}
}