8000 Merge branch 'master' of github.com:twilio/python-private · sangsiri/twilio-python@8e73936 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e73936

Browse files
author
Carlos Diaz-Padron
committed
Merge branch 'master' of github.com:twilio/python-private
2 parents f4ed073 + 4eabc57 commit 8e73936

File tree

7 files changed

+226
-3
lines changed

7 files changed

+226
-3
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ twilio-python Changelog
33

44
Here you can see the full list of changes between each twilio-python release.
55

6+
Version 4.7.0
7+
-------------
8+
9+
- Add support for SMS pricing
10+
11+
612
Version 4.6.0
713
-------------
814

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import unittest
2+
from mock import patch
3+
from nose.tools import assert_equal
4+
from tests.tools import create_mock_json
5+
from twilio.rest.resources.pricing.messaging_countries import (
6+
MessagingCountries
7+
)
8+
9+
AUTH = ("AC123", "token")
10+
BASE_URI = "https://pricing.twilio.com/v1"
11+
12+
13+
class MessagingCountriesTest(unittest.TestCase):
14+
15+
@patch('twilio.rest.resources.base.make_twilio_request')
16+
def test_messaging_countries(self, request):
17+
resp = create_mock_json(
18+
'tests/resources/pricing/messaging_countries_list.json')
19+
resp.status_code = 200
20+
request.return_value = resp
21+
22+
countries = MessagingCountries(BASE_URI + "/Messaging", AUTH)
23+
result = countries.list()
24+
25+
assert_equal(result[0].iso_country, "AT")
26+
assert_equal(len(result), 2)
27+
28+
request.assert_called_with(
29+
"GET",
30+
"{0}/Messaging/Countries".format(BASE_URI),
31+
auth=AUTH,
32+
use_json_extension=False,
33+
params={}
34+
)
35+
36+
@patch('twilio.rest.resources.base.make_twilio_request')
37+
def test_messaging_country(self, request):
38+
resp = create_mock_json(
39+
'tests/resources/pricing/messaging_countries_instance.json')
40+
resp.status_code = 200
41+
request.return_value = resp
42+
43+
countries = MessagingCountries(BASE_URI + "/Messaging", AUTH)
44+
result = countries.get('US')
45+
46+
assert_equal(result.iso_country, "US")
47+
assert_equal(result.price_unit, "usd")
48+
assert_equal(result.outbound_sms_prices[0]['mcc'], "311")
49+
assert_equal(result.outbound_sms_prices[0]['mnc'], "484")
50+
assert_equal(result.outbound_sms_prices[0]['carrier'], "Verizon")
51+
prices = result.outbound_sms_prices[0]['prices']
52+
53+
assert_equal(prices[0]['number_type'], "mobile")
54+
assert_equal(prices[0]['base_price'], "0.0075")
55+
assert_equal(prices[0]['current_price'], "0.0070")
56+
57+
assert_equal(prices[1]['number_type'], "local")
58+
assert_equal(prices[1]['base_price'], "0.0075")
59+
assert_equal(prices[1]['current_price'], "0.0070")
60+
61+
assert_equal(prices[2]['number_type'], "shortcode")
62+
assert_equal(prices[2]['base_price'], "0.01")
63+
assert_equal(prices[2]['current_price'], "0.01")
64+
65+
assert_equal(prices[3]['number_type'], "toll-free")
66+
assert_equal(prices[3]['base_price'], "0.0075")
67+
assert_equal(prices[3]['current_price'], "0.0075")
68+
69+
inbound_sms_prices = result.inbound_sms_prices
70+
71+
assert_equal(inbound_sms_prices[0]['number_type'], "local")
72+
assert_equal(inbound_sms_prices[0]['base_price'], "0.0075")
73+
assert_equal(inbound_sms_prices[0]['current_price'], "0.0075")
74+
75+
assert_equal(inbound_sms_prices[1]['number_type'], "shortcode")
76+
assert_equal(inbound_sms_prices[1]['base_price'], "0.0075")
77+
assert_equal(inbound_sms_prices[1]['current_price'], "0.005")
78+
79+
assert_equal(inbound_sms_prices[2]['number_type'], "toll-free")
80+
assert_equal(inbound_sms_prices[2]['base_price'], "0.0075")
81+
assert_equal(inbound_sms_prices[2]['current_price'], "0.0075")
82+
83+
request.assert_called_with(
84+
"GET",
85+
"{0}/Messaging/Countries/US".format(BASE_URI),
86+
auth=AUTH,
87+
use_json_extension=False,
88+
)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"country": "United States",
3+
"iso_country": "US",
4+
"price_unit": "usd",
5+
"outbound_sms_prices": [
6+
{
7+
"mcc": "311",
8+
"mnc": "484",
9+
"carrier": "Verizon",
10+
"prices": [
11+
{
12+
"number_type": "mobile",
13+
"base_price": "0.0075",
14+
"current_price": "0.0070"
15+
},
16+
{
17+
"number_type": "local",
18+
"base_price": "0.0075",
19+
"current_price": "0.0070"
20+
},
21+
{
22+
"number_type": "shortcode",
23+
"base_price": "0.01",
24+
"current_price": "0.01"
25+
},
26+
{
27+
"number_type": "toll-free",
28+
"base_price": "0.0075",
29+
"current_price": "0.0075"
30+
}
31+
]
32+
}
33+
],
34+
"inbound_sms_prices": [
35+
{
36+
"number_type": "local",
37+
"base_price": "0.0075",
38+
"current_price": "0.0075"
39+
},
40+
{
41+
"number_type": "shortcode",
42+
"base_price": "0.0075",
43+
"current_price": "0.005"
44+
},
45+
{
46+
"number_type": "toll-free",
47+
"base_price": "0.0075",
48+
"current_price": "0.0075"
49+
}
50+
]
51+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"meta": {
3+
"first_page_url": "https://pricing.twilio.com/v1/Messaging/Countries?PageSize=50&Page=0",
4+
"key": "countries",
5+
"next_page_url": "https://pricing.twilio.com/v1/Messaging/Countries?PageSize=50&Page=1&PageToken=DNCZ",
6+
"page": 0,
7+
"page_size": 50,
8+
"previous_page_url": null,
9+
"url": "https://pricing.twilio.com/v1/Messaging/Countries?PageSize=50&Page=0"
10+
},
11+
"countries": [
12+
{
13+
"country": "Austria",
14+
"iso_country": "AT",
15+
"url": "https://pricing.twilio.com/v1/Messaging/Countries/AT"
16+
},
17+
{
18+
"country": "Australia",
19+
"iso_country": "AU",
20+
"url": "https://pricing.twilio.com/v1/Messaging/Countries/AU"
21+
}
22+
]
23+
}

twilio/rest/pricing.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from twilio.rest.resources.pricing import (
44
PhoneNumbers,
55
Voice,
6+
MessagingCountries,
67
)
78

89

@@ -24,7 +25,18 @@ def __init__(self, account=None, token=None,
2425
super(TwilioPricingClient, self).__init__(account, token, base,
2526
version, timeout)
2627

27-
uri_base = "{}/{}".format(base, version)
28+
self.uri_base = "{}/{}".format(base, version)
2829

29-
self.voice = Voice(uri_base, self.auth, self.timeout)
30-
self.phone_numbers = PhoneNumbers(uri_base, self.auth, self.timeout)
30+
self.voice = Voice(self.uri_base, self.auth, self.timeout)
31+
self.phone_numbers = PhoneNumbers(self.uri_base, self.auth,
32+
self.timeout)
33+
34+
def messaging_countries(self):
35+
"""
36+
Returns a :class:`MessagingCountries` resource
37+
:return: MessagingCountries
38+
"""
39+
messaging_countries_uri = "{0}/Messaging/Countries".format(
40+
self.uri_base)
41+
return MessagingCountries(messaging_countries_uri, self.auth,
42+
self.timeout)

twilio/rest/resources/pricing/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
PhoneNumberCountry,
1212
PhoneNumbers,
1313
)
14+
15+
from .messaging_countries import (
16+
MessagingCountries
17+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from .. import NextGenInstanceResource, NextGenListResource
2+
3+
4+
class MessagingCountry(NextGenInstanceResource):
5+
"""Pricing information for Twilio Messages in a specific country.
6+
7+
.. attribute:: iso_country
8+
9+
The country's 2-character ISO 3166-1 code.
10+
11+
"""
12+
id_key = "iso_country"
13+
14+
15+
class MessagingCountries(NextGenListResource):
16+
"""A list of countries where Twilio Messages are available.
17+
18+
The returned list of MessagingCountry objects will not have pricing
19+
information populated. To get pricing information for a specific country,
20+
retrieve it with the :meth:`get` method.
21+
"""
22+
23+
instance = MessagingCountry
24+
key = "countries"
25+
name = "Countries"
26+
27+
def get(self, iso_country):
28+
"""Retrieve pricing information for Twilio Messages in the specified
29+
country.
30+
31+
:param iso_country: The two-letter ISO code for the country
32+
"""
33+
return self.get_instance(iso_country)
34+
35+
def list(self, **kwargs):
36+
"""Retrieve the list of countries in which Twilio Messages are
37+
available."""
38+
39+
return super(MessagingCountries, self).list(**kwargs)

0 commit comments

Comments
 (0)
0