6
6
from twilio .rest .resources import InstanceResource , ListResource
7
7
8
8
9
+ TYPES = {"local" : "Local" , "tollfree" : "TollFree" , "mobile" : "Mobile" }
10
+
11
+
9
12
class AvailablePhoneNumber (InstanceResource ):
10
13
""" An available phone number resource
11
14
@@ -63,8 +66,6 @@ class AvailablePhoneNumbers(ListResource):
63
66
key = "available_phone_numbers"
64
67
instance = AvailablePhoneNumber
65
68
66
- types = {"local" : "Local" , "tollfree" : "TollFree" , "mobile" : "Mobile" }
67
-
68
69
def __init__ (self , base_uri , auth , timeout , phone_numbers ):
69
70
super (AvailablePhoneNumbers , self ).__init__ (base_uri , auth , timeout )
70
71
self .phone_numbers = phone_numbers
@@ -83,7 +84,7 @@ def list(self, type="local", country="US", region=None, postal_code=None,
83
84
kwargs ["in_rate_center" ] = kwargs .get ("in_rate_center" , rate_center )
84
85
params = transform_params (kwargs )
85
86
86
- uri = "%s/%s/%s" % (self .uri , country , self . types [type ])
87
+ uri = "%s/%s/%s" % (self .uri , country , TYPES [type ])
87
88
resp , page = self .request ("GET" , uri , params = params )
88
89
89
90
return [self .load_instance (i ) for i in page [self .key ]]
@@ -262,10 +263,20 @@ def list(self, **kwargs):
262
263
"""
263
264
:param phone_number: Show phone numbers that match this pattern.
264
265
: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'
265
268
266
269
You can specify partial numbers and use '*' as a wildcard.
267
270
"""
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 ]]
269
280
270
281
def purchase (self , status_callback_url = None , ** kwargs ):
271
282
"""
0 commit comments