8000 Add usage docs for Pricing resources · ShowLowTechnology/twilio-python@ad6ce70 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad6ce70

Browse files
committed
Add usage docs for Pricing resources
1 parent e0eed51 commit ad6ce70

File tree

2 files changed

+176
-2
lines changed

2 files changed

+176
-2
lines changed

docs/usage/pricing.rst

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
.. module::twilio.rest
2+
3+
======================================
4+
Accessing Twilio Pricing API Resources
5+
======================================
6+
7+
To access the Twilio Pricing API resources, you'll first need to instantiate
8+
a :class:`TwilioPricingClient`.
9+
10+
Authentication
11+
--------------
12+
13+
The :class:`TwilioPricingClient` needs your Twilio credentials. While these can be
14+
passed in directly to the constructor, we suggest storing your credentials as
15+
environment variables. Why? You'll never have to worry about committing your
16+
credentials and accidentally posting them somewhere public.
17+
18+
The :class:`TwilioPricingClient` looks for :const:`TWILIO_ACCOUNT_SID` and
19+
:const:`TWILIO_AUTH_TOKEN` inside the current environment.
20+
21+
With those two values set, create a new :class:`TwilioPricingClient`.
22+
23+
.. code-block:: python
24+
25+
from twilio.rest import TwilioPricingClient
26+
27+
conn = TwilioPricingClient()
28+
29+
If you'd rather not use environment variables, pass your account credentials
30+
directly to the the constructor.
31+
32+
.. code-block:: python
33+
34+
from twilio.rest import TwilioPricingClient
35+
36+
ACCOUNT_SID = "AXXXXXXXXXXXXXXXXX"
37+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
38+
client = TwilioPricingClient(ACCOUNT_SID, AUTH_TOKEN)
39+
40+
41+
For more advanced options to use with the :class:`TwilioPricingClient`,
42+
including proxy configuration, see the :doc:`/usage/basics` page.
43+
:class:`TwilioPricingClient` accepts the same options as
44+
:class:`TwilioRestClient`.
45+
46+
=============
47+
Voice Pricing
48+
=============
49+
50+
Twilio Voice pricing is available by country and by phone number.
51+
52+
Voice calls are priced per minute and reflect the current Twilio list price
53+
and any discounts available to the requesting account at the time of the
54+
request.
55+
56+
Voice Countries
57+
---------------
58+
59+
To retrieve a list of countries where Twilio Voice services are available:
60+
61+
.. code-block:: python
62+
63+
from twilio.rest import TwilioPricingClient
64+
65+
# To find these visit https://www.twilio.com/user/account
66+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
67+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
68+
69+
client = TwilioPricingClient(ACCOUNT_SID, AUTH_TOKEN)
70+
countries = client.voice.countries.list()
71+
for c in countries:
72+
print c.iso_country
73+
74+
Note that the returned list of countries will not have actual prices populated.
75+
You will need to retrieve the pricing information for each country you are
76+
interested in individually:
77+
78+
.. code-block:: python
79+
80+
from twilio.rest import TwilioPricingClient
81+
82+
# To find these visit https://www.twilio.com/user/account
83+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
84+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
85+
86+
client = TwilioPricingClient(ACCOUNT_SID, AUTH_TOKEN)
87+
country = client.voice.countries.get('GB')
88+
print country.iso_country
89+
print country.price_unit
90+
91+
# A list of price rates for inbound calls to each type of Twilio
92+
# Number available in this country
93+
for p in country.inbound_call_prices:
94+
print p.number_type
95+
print p.call_base_price # Base price per minute
96+
print p.current_base_price # Price per minute after discounts
97+
98+
# A list of price rates for outbound calls, organized by number prefixes.
99+
for p in country.outbound_prefix_prices:
100+
print p.prefixes # List of one or more prefixes this price applies to
101+
print p.call_base_price # Base price per minute
102+
print p.current_base_price # Price per minute after discounts
103+
104+
Voice Numbers
105+
-------------
106+
107+
To retrieve pricing information for Twilio Voice calls to and from a specific
108+
number:
109+
110+
.. code-block:: python
111+
112+
from twilio.rest import TwilioPricingClient
113+
114+
# To find these visit https://www.twilio.com/user/account
115+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
116+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
117+
118+
client = TwilioPricingClient(ACCOUNT_SID, AUTH_TOKEN)
119+
number = client.voice.numbers.get('+15105551234')
120+
121+
print number.iso_country
122+
print number.price_unit
123+
print number.outbound_call_price.call_base_price
124+
print number.inbound_call_price.call_base_price # None if the number is not Twilio-hosted
125+
126+
Phone Number Pricing
127+
====================
128+
129+
To retrieve a list of countries where Twilio phone numbers are available:
130+
131+
.. code-block:: python
132+
133+
from twilio.rest import TwilioPricingClient
134+
135+
# To find these visit https://www.twilio.com/user/account
136+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
137+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
138+
139+
client = TwilioPricingClient(ACCOUNT_SID, AUTH_TOKEN)
140+
countries = client.phone_numbers.countries.list()
141+
for c in countries:
142+
print c.iso_country
143+
144+
Note that the country objects in the returned list will not have pricing
145+
information populated; you will need to retrieve the specific information for
146+
each country you are interested in individually:
147+
148+
.. code-block:: python
149+
150+
from twilio.rest import TwilioPricingClient
151+
152+
# To find these visit https://www.twilio.com/user/account
153+
ACCOUNT_SID = "ACXXXXXXXXXXXXXXXXX"
154+
AUTH_TOKEN = "YYYYYYYYYYYYYYYYYY"
155+
156+
client = TwilioPricingClient(ACCOUNT_SID, AUTH_TOKEN)
157+
country = client.phone_numbers.countries.get('GB')
158+
print country.price_unit
159+
160+
for p in country.phone_number_prices:
161+
print p.type
162+
print p.base_price
163+
print p.current_price
164+

twilio/rest/resources/pricing/phone_numbers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ def __init__(self, base_uri, auth, timeout):
1515
class PhoneNumberCountry(InstanceResource):
1616
"""Pricing information for Twilio Phone Numbers in a specific country.
1717
18+
Twilio numbers are billed monthly, and the prices returned reflect
19+
current Twilio list pricing before and after any discounts available for
20+
the requesting account are applied.
21+
1822
.. attribute:: country
1923
2024
The full name of the country.
2125
2226
.. attribute:: iso_country
2327
24-
The country's 2-character ISO code.
28+
The country's 2-character ISO 3166-1 code.
2529
2630
.. attribute:: price_unit
2731
@@ -41,13 +45,19 @@ class PhoneNumberCountry(InstanceResource):
4145

4246

4347
class PhoneNumberCountries(ListResource):
48+
"""A list of countries where Twilio Phone Numbers are available.
49+
50+
The returned list of PhoneNumberCountry objects will not have pricing
51+
information populated. To get pricing information for a specific country,
52+
retrieve it with the :meth:`get` method.
53+
"""
4454

4555
instance = PhoneNumberCountry
4656
key = "countries"
4757
name = "Countries"
4858

4959
def get(self, iso_country):
50-
"""Retrieve pricing information for Twilio Number in the specified
60+
"""Retrieve pricing information for Twilio Numbers in the specified
5161
country.
5262
5363
:param iso_country: The two-letter ISO code for the country

0 commit comments

Comments
 (0)
0