1# coding=utf-8
2r"""
3This code was generated by
4\ / _    _  _|   _  _
5 | (_)\/(_)(_|\/| |(/_  v1.0.0
6      /       /
7"""
8
9from twilio.base import deserialize
10from twilio.base import values
11from twilio.base.instance_resource import InstanceResource
12from twilio.base.list_resource import ListResource
13from twilio.base.page import Page
14
15
16class MobileList(ListResource):
17
18    def __init__(self, version, account_sid, country_code):
19        """
20        Initialize the MobileList
21
22        :param Version version: Version that contains the resource
23        :param account_sid: The account_sid
24        :param country_code: The ISO-3166-1 country code of the country.
25
26        :returns: twilio.rest.api.v2010.account.available_phone_number.mobile.MobileList
27        :rtype: twilio.rest.api.v2010.account.available_phone_number.mobile.MobileList
28        """
29        super(MobileList, self).__init__(version)
30
31        # Path Solution
32        self._solution = {'account_sid': account_sid, 'country_code': country_code, }
33        self._uri = '/Accounts/{account_sid}/AvailablePhoneNumbers/{country_code}/Mobile.json'.format(**self._solution)
34
35    def stream(self, area_code=values.unset, contains=values.unset,
36               sms_enabled=values.unset, mms_enabled=values.unset,
37               voice_enabled=values.unset,
38               exclude_all_address_required=values.unset,
39               exclude_local_address_required=values.unset,
40               exclude_foreign_address_required=values.unset, beta=values.unset,
41               near_number=values.unset, near_lat_long=values.unset,
42               distance=values.unset, in_postal_code=values.unset,
43               in_region=values.unset, in_rate_center=values.unset,
44               in_lata=values.unset, in_locality=values.unset,
45               fax_enabled=values.unset, limit=None, page_size=None):
46        """
47        Streams MobileInstance records from the API as a generator stream.
48        This operation lazily loads records as efficiently as possible until the limit
49        is reached.
50        The results are returned as a generator, so this operation is memory efficient.
51
52        :param unicode area_code: The area code of the phone numbers to read
53        :param unicode contains: The pattern on which to match phone numbers
54        :param bool sms_enabled: Whether the phone numbers can receive text messages
55        :param bool mms_enabled: Whether the phone numbers can receive MMS messages
56        :param bool voice_enabled: Whether the phone numbers can receive calls.
57        :param bool exclude_all_address_required: Whether to exclude phone numbers that require an Address
58        :param bool exclude_local_address_required: Whether to exclude phone numbers that require a local address
59        :param bool exclude_foreign_address_required: Whether to exclude phone numbers that require a foreign address
60        :param bool beta: Whether to read phone numbers new to the Twilio platform
61        :param unicode near_number: Given a phone number, find a geographically close number within distance miles. (US/Canada only)
62        :param unicode near_lat_long: Given a latitude/longitude pair lat,long find geographically close numbers within distance miles. (US/Canada only)
63        :param unicode distance: The search radius, in miles, for a near_ query. (US/Canada only)
64        :param unicode in_postal_code: Limit results to a particular postal code. (US/Canada only)
65        :param unicode in_region: Limit results to a particular region. (US/Canada only)
66        :param unicode in_rate_center: Limit results to a specific rate center, or given a phone number search within the same rate center as that number. (US/Canada only)
67        :param unicode in_lata: Limit results to a specific local access and transport area. (US/Canada only)
68        :param unicode in_locality: Limit results to a particular locality
69        :param bool fax_enabled: Whether the phone numbers can receive faxes
70        :param int limit: Upper limit for the number of records to return. stream()
71                          guarantees to never return more than limit.  Default is no limit
72        :param int page_size: Number of records to fetch per request, when not set will use
73                              the default value of 50 records.  If no page_size is defined
74                              but a limit is defined, stream() will attempt to read the
75                              limit with the most efficient page size, i.e. min(limit, 1000)
76
77        :returns: Generator that will yield up to limit results
78        :rtype: list[twilio.rest.api.v2010.account.available_phone_number.mobile.MobileInstance]
79        """
80        limits = self._version.read_limits(limit, page_size)
81
82        page = self.page(
83            area_code=area_code,
84            contains=contains,
85            sms_enabled=sms_enabled,
86            mms_enabled=mms_enabled,
87            voice_enabled=voice_enabled,
88            exclude_all_address_required=exclude_all_address_required,
89            exclude_local_address_required=exclude_local_address_required,
90            exclude_foreign_address_required=exclude_foreign_address_required,
91            beta=beta,
92            near_number=near_number,
93            near_lat_long=near_lat_long,
94            distance=distance,
95            in_postal_code=in_postal_code,
96            in_region=in_region,
97            in_rate_center=in_rate_center,
98            in_lata=in_lata,
99            in_locality=in_locality,
100            fax_enabled=fax_enabled,
101            page_size=limits['page_size'],
102        )
103
104        return self._version.stream(page, limits['limit'])
105
106    def list(self, area_code=values.unset, contains=values.unset,
107             sms_enabled=values.unset, mms_enabled=values.unset,
108             voice_enabled=values.unset, exclude_all_address_required=values.unset,
109             exclude_local_address_required=values.unset,
110             exclude_foreign_address_required=values.unset, beta=values.unset,
111             near_number=values.unset, near_lat_long=values.unset,
112             distance=values.unset, in_postal_code=values.unset,
113             in_region=values.unset, in_rate_center=values.unset,
114             in_lata=values.unset, in_locality=values.unset,
115             fax_enabled=values.unset, limit=None, page_size=None):
116        """
117        Lists MobileInstance records from the API as a list.
118        Unlike stream(), this operation is eager and will load `limit` records into
119        memory before returning.
120
121        :param unicode area_code: The area code of the phone numbers to read
122        :param unicode contains: The pattern on which to match phone numbers
123        :param bool sms_enabled: Whether the phone numbers can receive text messages
124        :param bool mms_enabled: Whether the phone numbers can receive MMS messages
125        :param bool voice_enabled: Whether the phone numbers can receive calls.
126        :param bool exclude_all_address_required: Whether to exclude phone numbers that require an Address
127        :param bool exclude_local_address_required: Whether to exclude phone numbers that require a local address
128        :param bool exclude_foreign_address_required: Whether to exclude phone numbers that require a foreign address
129        :param bool beta: Whether to read phone numbers new to the Twilio platform
130        :param unicode near_number: Given a phone number, find a geographically close number within distance miles. (US/Canada only)
131        :param unicode near_lat_long: Given a latitude/longitude pair lat,long find geographically close numbers within distance miles. (US/Canada only)
132        :param unicode distance: The search radius, in miles, for a near_ query. (US/Canada only)
133        :param unicode in_postal_code: Limit results to a particular postal code. (US/Canada only)
134        :param unicode in_region: Limit results to a particular region. (US/Canada only)
135        :param unicode in_rate_center: Limit results to a specific rate center, or given a phone number search within the same rate center as that number. (US/Canada only)
136        :param unicode in_lata: Limit results to a specific local access and transport area. (US/Canada only)
137        :param unicode in_locality: Limit results to a particular locality
138        :param bool fax_enabled: Whether the phone numbers can receive faxes
139        :param int limit: Upper limit for the number of records to return. list() guarantees
140                          never to return more than limit.  Default is no limit
141        :param int page_size: Number of records to fetch per request, when not set will use
142                              the default value of 50 records.  If no page_size is defined
143                              but a limit is defined, list() will attempt to read the limit
144                              with the most efficient page size, i.e. min(limit, 1000)
145
146        :returns: Generator that will yield up to limit results
147        :rtype: list[twilio.rest.api.v2010.account.available_phone_number.mobile.MobileInstance]
148        """
149        return list(self.stream(
150            area_code=area_code,
151            contains=contains,
152            sms_enabled=sms_enabled,
153            mms_enabled=mms_enabled,
154            voice_enabled=voice_enabled,
155            exclude_all_address_required=exclude_all_address_required,
156            exclude_local_address_required=exclude_local_address_required,
157            exclude_foreign_address_required=exclude_foreign_address_required,
158            beta=beta,
159            near_number=near_number,
160            near_lat_long=near_lat_long,
161            distance=distance,
162            in_postal_code=in_postal_code,
163            in_region=in_region,
164            in_rate_center=in_rate_center,
165            in_lata=in_lata,
166            in_locality=in_locality,
167            fax_enabled=fax_enabled,
168            limit=limit,
169            page_size=page_size,
170        ))
171
172    def page(self, area_code=values.unset, contains=values.unset,
173             sms_enabled=values.unset, mms_enabled=values.unset,
174             voice_enabled=values.unset, exclude_all_address_required=values.unset,
175             exclude_local_address_required=values.unset,
176             exclude_foreign_address_required=values.unset, beta=values.unset,
177             near_number=values.unset, near_lat_long=values.unset,
178             distance=values.unset, in_postal_code=values.unset,
179             in_region=values.unset, in_rate_center=values.unset,
180             in_lata=values.unset, in_locality=values.unset,
181             fax_enabled=values.unset, page_token=values.unset,
182             page_number=values.unset, page_size=values.unset):
183        """
184        Retrieve a single page of MobileInstance records from the API.
185        Request is executed immediately
186
187        :param unicode area_code: The area code of the phone numbers to read
188        :param unicode contains: The pattern on which to match phone numbers
189        :param bool sms_enabled: Whether the phone numbers can receive text messages
190        :param bool mms_enabled: Whether the phone numbers can receive MMS messages
191        :param bool voice_enabled: Whether the phone numbers can receive calls.
192        :param bool exclude_all_address_required: Whether to exclude phone numbers that require an Address
193        :param bool exclude_local_address_required: Whether to exclude phone numbers that require a local address
194        :param bool exclude_foreign_address_required: Whether to exclude phone numbers that require a foreign address
195        :param bool beta: Whether to read phone numbers new to the Twilio platform
196        :param unicode near_number: Given a phone number, find a geographically close number within distance miles. (US/Canada only)
197        :param unicode near_lat_long: Given a latitude/longitude pair lat,long find geographically close numbers within distance miles. (US/Canada only)
198        :param unicode distance: The search radius, in miles, for a near_ query. (US/Canada only)
199        :param unicode in_postal_code: Limit results to a particular postal code. (US/Canada only)
200        :param unicode in_region: Limit results to a particular region. (US/Canada only)
201        :param unicode in_rate_center: Limit results to a specific rate center, or given a phone number search within the same rate center as that number. (US/Canada only)
202        :param unicode in_lata: Limit results to a specific local access and transport area. (US/Canada only)
203        :param unicode in_locality: Limit results to a particular locality
204        :param bool fax_enabled: Whether the phone numbers can receive faxes
205        :param str page_token: PageToken provided by the API
206        :param int page_number: Page Number, this value is simply for client state
207        :param int page_size: Number of records to return, defaults to 50
208
209        :returns: Page of MobileInstance
210        :rtype: twilio.rest.api.v2010.account.available_phone_number.mobile.MobilePage
211        """
212        data = values.of({
213            'AreaCode': area_code,
214            'Contains': contains,
215            'SmsEnabled': sms_enabled,
216            'MmsEnabled': mms_enabled,
217            'VoiceEnabled': voice_enabled,
218            'ExcludeAllAddressRequired': exclude_all_address_required,
219            'ExcludeLocalAddressRequired': exclude_local_address_required,
220            'ExcludeForeignAddressRequired': exclude_foreign_address_required,
221            'Beta': beta,
222            'NearNumber': near_number,
223            'NearLatLong': near_lat_long,
224            'Distance': distance,
225            'InPostalCode': in_postal_code,
226            'InRegion': in_region,
227            'InRateCenter': in_rate_center,
228            'InLata': in_lata,
229            'InLocality': in_locality,
230            'FaxEnabled': fax_enabled,
231            'PageToken': page_token,
232            'Page': page_number,
233            'PageSize': page_size,
234        })
235
236        response = self._version.page(method='GET', uri=self._uri, params=data, )
237
238        return MobilePage(self._version, response, self._solution)
239
240    def get_page(self, target_url):
241        """
242        Retrieve a specific page of MobileInstance records from the API.
243        Request is executed immediately
244
245        :param str target_url: API-generated URL for the requested results page
246
247        :returns: Page of MobileInstance
248        :rtype: twilio.rest.api.v2010.account.available_phone_number.mobile.MobilePage
249        """
250        response = self._version.domain.twilio.request(
251            'GET',
252            target_url,
253        )
254
255        return MobilePage(self._version, response, self._solution)
256
257    def __repr__(self):
258        """
259        Provide a friendly representation
260
261        :returns: Machine friendly representation
262        :rtype: str
263        """
264        return '<Twilio.Api.V2010.MobileList>'
265
266
267class MobilePage(Page):
268
269    def __init__(self, version, response, solution):
270        """
271        Initialize the MobilePage
272
273        :param Version version: Version that contains the resource
274        :param Response response: Response from the API
275        :param account_sid: The account_sid
276        :param country_code: The ISO-3166-1 country code of the country.
277
278        :returns: twilio.rest.api.v2010.account.available_phone_number.mobile.MobilePage
279        :rtype: twilio.rest.api.v2010.account.available_phone_number.mobile.MobilePage
280        """
281        super(MobilePage, self).__init__(version, response)
282
283        # Path Solution
284        self._solution = solution
285
286    def get_instance(self, payload):
287        """
288        Build an instance of MobileInstance
289
290        :param dict payload: Payload response from the API
291
292        :returns: twilio.rest.api.v2010.account.available_phone_number.mobile.MobileInstance
293        :rtype: twilio.rest.api.v2010.account.available_phone_number.mobile.MobileInstance
294        """
295        return MobileInstance(
296            self._version,
297            payload,
298            account_sid=self._solution['account_sid'],
299            country_code=self._solution['country_code'],
300        )
301
302    def __repr__(self):
303        """
304        Provide a friendly representation
305
306        :returns: Machine friendly representation
307        :rtype: str
308        """
309        return '<Twilio.Api.V2010.MobilePage>'
310
311
312class MobileInstance(InstanceResource):
313
314    def __init__(self, version, payload, account_sid, country_code):
315        """
316        Initialize the MobileInstance
317
318        :returns: twilio.rest.api.v2010.account.available_phone_number.mobile.MobileInstance
319        :rtype: twilio.rest.api.v2010.account.available_phone_number.mobile.MobileInstance
320        """
321        super(MobileInstance, self).__init__(version)
322
323        # Marshaled Properties
324        self._properties = {
325            'friendly_name': payload.get('friendly_name'),
326            'phone_number': payload.get('phone_number'),
327            'lata': payload.get('lata'),
328            'locality': payload.get('locality'),
329            'rate_center': payload.get('rate_center'),
330            'latitude': deserialize.decimal(payload.get('latitude')),
331            'longitude': deserialize.decimal(payload.get('longitude')),
332            'region': payload.get('region'),
333            'postal_code': payload.get('postal_code'),
334            'iso_country': payload.get('iso_country'),
335            'address_requirements': payload.get('address_requirements'),
336            'beta': payload.get('beta'),
337            'capabilities': payload.get('capabilities'),
338        }
339
340        # Context
341        self._context = None
342        self._solution = {'account_sid': account_sid, 'country_code': country_code, }
343
344    @property
345    def friendly_name(self):
346        """
347        :returns: A formatted version of the phone number
348        :rtype: unicode
349        """
350        return self._properties['friendly_name']
351
352    @property
353    def phone_number(self):
354        """
355        :returns: The phone number in E.164 format
356        :rtype: unicode
357        """
358        return self._properties['phone_number']
359
360    @property
361    def lata(self):
362        """
363        :returns: The LATA of this phone number
364        :rtype: unicode
365        """
366        return self._properties['lata']
367
368    @property
369    def locality(self):
370        """
371        :returns: The locality or city of this phone number's location
372        :rtype: unicode
373        """
374        return self._properties['locality']
375
376    @property
377    def rate_center(self):
378        """
379        :returns: The rate center of this phone number
380        :rtype: unicode
381        """
382        return self._properties['rate_center']
383
384    @property
385    def latitude(self):
386        """
387        :returns: The latitude of this phone number's location
388        :rtype: unicode
389        """
390        return self._properties['latitude']
391
392    @property
393    def longitude(self):
394        """
395        :returns: The longitude of this phone number's location
396        :rtype: unicode
397        """
398        return self._properties['longitude']
399
400    @property
401    def region(self):
402        """
403        :returns: The two-letter state or province abbreviation of this phone number's location
404        :rtype: unicode
405        """
406        return self._properties['region']
407
408    @property
409    def postal_code(self):
410        """
411        :returns: The postal or ZIP code of this phone number's location
412        :rtype: unicode
413        """
414        return self._properties['postal_code']
415
416    @property
417    def iso_country(self):
418        """
419        :returns: The ISO country code of this phone number
420        :rtype: unicode
421        """
422        return self._properties['iso_country']
423
424    @property
425    def address_requirements(self):
426        """
427        :returns: The type of Address resource the phone number requires
428        :rtype: unicode
429        """
430        return self._properties['address_requirements']
431
432    @property
433    def beta(self):
434        """
435        :returns: Whether the phone number is new to the Twilio platform
436        :rtype: bool
437        """
438        return self._properties['beta']
439
440    @property
441    def capabilities(self):
442        """
443        :returns: Whether a phone number can receive calls or messages
444        :rtype: unicode
445        """
446        return self._properties['capabilities']
447
448    def __repr__(self):
449        """
450        Provide a friendly representation
451
452        :returns: Machine friendly representation
453        :rtype: str
454        """
455        return '<Twilio.Api.V2010.MobileInstance>'
456