|
| 1 | +from .. import InstanceResource, ListResource |
| 2 | + |
| 3 | + |
| 4 | +class Voice(object): |
| 5 | + """Holds references to the Voice pricing resources.""" |
| 6 | + |
| 7 | + name = "Voice" |
| 8 | + key = "voice" |
| 9 | + |
| 10 | + def __init__(self, base_uri, auth, timeout): |
| 11 | + self.uri = "%s/Voice" % base_uri |
| 12 | + self.countries = VoiceCountries(self.uri, auth, timeout) |
| 13 | + self.numbers = VoiceNumbers(self.uri, auth, timeout) |
| 14 | + |
| 15 | + |
| 16 | +class VoiceCountry(InstanceResource): |
| 17 | + """Pricing information for Twilio Voice services in a specific country. |
| 18 | +
|
| 19 | + .. attribute:: country |
| 20 | +
|
| 21 | + The full name of the country. |
| 22 | +
|
| 23 | + .. attribute:: iso_country |
| 24 | +
|
| 25 | + The country's 2-character ISO code. |
| 26 | +
|
| 27 | + .. attribute:: price_unit |
| 28 | +
|
| 29 | + The currency in which prices are measured, in ISO 4127 format |
| 30 | + (e.g. 'usd', 'eur', 'jpy'). |
| 31 | +
|
| 32 | + .. attribute:: outbound_prefix_prices |
| 33 | +
|
| 34 | + A list of dicts containing pricing information as follows: |
| 35 | + - prefix_list: a list of number prefixes in the requested country |
| 36 | + that have the same pricing |
| 37 | + - friendly_name: a descriptive name for this prefix set |
| 38 | + - call_base_price: the base price per minute for calls to numbers |
| 39 | + matching any of these prefixes |
| 40 | + - call_current_price: the current price per minute (including |
| 41 | + volume discounts, etc.) for your account to make calls to |
| 42 | + numbers matching these prefixes |
| 43 | +
|
| 44 | + .. attribute:: inbound_call_prices |
| 45 | +
|
| 46 | + A list of dicts containing pricing information for inbound calls: |
| 47 | + - number_type: 'local', 'mobile', 'national', or 'toll_free' |
| 48 | + - call_base_price: the base price per minute to receive a call |
| 49 | + to this number type |
| 50 | + - call_current_price: the current price per minute (including |
| 51 | + volume discounts, etc.) for your account to receive a call |
| 52 | + to this number type |
| 53 | + """ |
| 54 | + |
| 55 | + id_key = "iso_country" |
| 56 | + |
| 57 | + |
| 58 | +class VoiceCountries(ListResource): |
| 59 | + |
| 60 | + instance = VoiceCountry |
| 61 | + key = "countries" |
| 62 | + name = "Countries" |
| 63 | + |
| 64 | + def get(self, iso_country): |
| 65 | + """Retrieve pricing information for Twilio Voice in the specified |
| 66 | + country. |
| 67 | +
|
| 68 | + :param iso_country: The two-letter ISO code for the country |
| 69 | + """ |
| 70 | + return self.get_instance(iso_country) |
| 71 | + |
| 72 | + def list(self): |
| 73 | + """Retrieve the list of countries in which Twilio Voice is available.""" |
| 74 | + |
| 75 | + resp, page = self.request("GET", self.uri) |
| 76 | + |
| 77 | + return [self.load_instance(i) for i in page[self.key]] |
| 78 | + |
| 79 | + |
| 80 | +class VoiceNumber(InstanceResource): |
| 81 | + """Pricing information for Twilio Voice services to and from a given |
| 82 | + phone number. |
| 83 | +
|
| 84 | + .. attribute:: phone_number |
| 85 | +
|
| 86 | + The E.164-formatted phone number this pricing information applies to |
| 87 | +
|
| 88 | + .. attribute:: country |
| 89 | +
|
| 90 | + The name of the country this phone number belongs to |
| 91 | +
|
| 92 | + .. attribute:: iso_country |
| 93 | +
|
| 94 | + The two-character ISO code for the country |
| 95 | +
|
| 96 | + .. attribute:: outbound_call_price |
| 97 | +
|
| 98 | + A dict containing pricing information for outbound calls to this number: |
| 99 | + - base_price: the base price per minute for a call to this number |
| 100 | + - current_price: the current price per minute (including discounts, |
| 101 | + etc.) for a call to this number |
| 102 | +
|
| 103 | + .. attribute:: inbound_call_price |
| 104 | +
|
| 105 | + A dict containing pricing information for inbound call to this number, |
| 106 | + or null if this number is not Twilio-hosted. |
| 107 | +
|
| 108 | + - number_type: "local", "mobile", "national", or "toll_free" |
| 109 | + - call_base_price: the base price per minute to receive a call to |
| 110 | + this number |
| 111 | + - call_current_price: the current price per minute (including |
| 112 | + discounts, etc.) to receive a call to this number |
| 113 | + """ |
| 114 | + |
| 115 | + id_key = "phone_number" |
| 116 | + |
| 117 | + |
| 118 | +class VoiceNumbers(ListResource): |
| 119 | + |
| 120 | + instance = VoiceNumber |
| 121 | + key = "numbers" |
| 122 | + name = "Numbers" |
| 123 | + |
| 124 | + def get(self, phone_number): |
| 125 | + """ Retrieve pricing information for a specific phone number. |
| 126 | + :param phone_number: the E.164-formatted number to retrieve info for |
| 127 | + :return: a :class:`VoiceNumber` instance |
| 128 | + """ |
| 129 | + |
| 130 | + return self.get_instance(phone_number) |
0 commit comments