8000 add support for number types to incoming_phone_numbers · Web5design/twilio-python@bdf30b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit bdf30b3

Browse files
author
Doug Black
committed
add support for number types to incoming_phone_numbers
1 parent bda3b9c commit bdf30b3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

twilio/rest/resources/phone_numbers.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from twilio.rest.resources import InstanceResource, ListResource
77

88

9+
TYPES = {"local": "Local", "tollfree": "TollFree", "mobile": "Mobile"}
10+
11+
912
class AvailablePhoneNumber(InstanceResource):
1013
""" An available phone number resource
1114
@@ -63,8 +66,6 @@ class AvailablePhoneNumbers(ListResource):
6366
key = "available_phone_numbers"
6467
instance = AvailablePhoneNumber
6568

66-
types = {"local": "Local", "tollfree": "TollFree", "mobile": "Mobile"}
67-
6869
def __init__(self, base_uri, auth, timeout, phone_numbers):
6970
super(AvailablePhoneNumbers, self).__init__(base_uri, auth, timeout)
7071
self.phone_numbers = phone_numbers
@@ -83,7 +84,7 @@ def list(self, type="local", country="US", region=None, postal_code=None,
8384
kwargs["in_rate_center"] = kwargs.get("in_rate_center", rate_center)
8485
params = transform_params(kwargs)
8586

86-
uri = "%s/%s/%s" % (self.uri, country, self.types[type])
87+
uri = "%s/%s/%s" % (self.uri, country, TYPES[type])
8788
resp, page = self.request("GET", uri, params=params)
8889

8990
return [self.load_instance(i) for i in page[self.key]]
@@ -262,10 +263,20 @@ def list(self, **kwargs):
262263
"""
263264
:param phone_number: Show phone numbers that match this pattern.
264265
:param friendly_name: Show phone numbers with this friendly name
266+
:param type: Filter numbers by type. Available types are
267+
'local', 'mobile', or 'toll_free'
265268
266269
You can specify partial numbers and use '*' as a wildcard.
267270
"""
268-
return self.get_instances(kwargs)
271+
272+
type = kwargs.get("type", None)
273+
if type:
274+
uri = "%s/%s" % (self.uri, TYPES[type])
275+
276+
params = transform_params(kwargs)
277+
resp, page = self.request("GET", uri, params=params)
278+
279+
return [self.load_instance(i) for i in page[self.key]]
269280

270281
def purchase(self, status_callback_url=None, **kwargs):
271282
"""

0 commit comments

Comments
 (0)
0