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_context import InstanceContext
12from twilio.base.instance_resource import InstanceResource
13from twilio.base.list_resource import ListResource
14from twilio.base.page import Page
15from twilio.rest.preview.wireless.sim.usage import UsageList
16
17
18class SimList(ListResource):
19    """ PLEASE NOTE that this class contains preview products that are subject
20    to change. Use them with caution. If you currently do not have developer
21    preview access, please contact help@twilio.com. """
22
23    def __init__(self, version):
24        """
25        Initialize the SimList
26
27        :param Version version: Version that contains the resource
28
29        :returns: twilio.rest.preview.wireless.sim.SimList
30        :rtype: twilio.rest.preview.wireless.sim.SimList
31        """
32        super(SimList, self).__init__(version)
33
34        # Path Solution
35        self._solution = {}
36        self._uri = '/Sims'.format(**self._solution)
37
38    def stream(self, status=values.unset, iccid=values.unset,
39               rate_plan=values.unset, e_id=values.unset,
40               sim_registration_code=values.unset, limit=None, page_size=None):
41        """
42        Streams SimInstance records from the API as a generator stream.
43        This operation lazily loads records as efficiently as possible until the limit
44        is reached.
45        The results are returned as a generator, so this operation is memory efficient.
46
47        :param unicode status: The status
48        :param unicode iccid: The iccid
49        :param unicode rate_plan: The rate_plan
50        :param unicode e_id: The e_id
51        :param unicode sim_registration_code: The sim_registration_code
52        :param int limit: Upper limit for the number of records to return. stream()
53                          guarantees to never return more than limit.  Default is no limit
54        :param int page_size: Number of records to fetch per request, when not set will use
55                              the default value of 50 records.  If no page_size is defined
56                              but a limit is defined, stream() will attempt to read the
57                              limit with the most efficient page size, i.e. min(limit, 1000)
58
59        :returns: Generator that will yield up to limit results
60        :rtype: list[twilio.rest.preview.wireless.sim.SimInstance]
61        """
62        limits = self._version.read_limits(limit, page_size)
63
64        page = self.page(
65            status=status,
66            iccid=iccid,
67            rate_plan=rate_plan,
68            e_id=e_id,
69            sim_registration_code=sim_registration_code,
70            page_size=limits['page_size'],
71        )
72
73        return self._version.stream(page, limits['limit'])
74
75    def list(self, status=values.unset, iccid=values.unset, rate_plan=values.unset,
76             e_id=values.unset, sim_registration_code=values.unset, limit=None,
77             page_size=None):
78        """
79        Lists SimInstance records from the API as a list.
80        Unlike stream(), this operation is eager and will load `limit` records into
81        memory before returning.
82
83        :param unicode status: The status
84        :param unicode iccid: The iccid
85        :param unicode rate_plan: The rate_plan
86        :param unicode e_id: The e_id
87        :param unicode sim_registration_code: The sim_registration_code
88        :param int limit: Upper limit for the number of records to return. list() guarantees
89                          never to return more than limit.  Default is no limit
90        :param int page_size: Number of records to fetch per request, when not set will use
91                              the default value of 50 records.  If no page_size is defined
92                              but a limit is defined, list() will attempt to read the limit
93                              with the most efficient page size, i.e. min(limit, 1000)
94
95        :returns: Generator that will yield up to limit results
96        :rtype: list[twilio.rest.preview.wireless.sim.SimInstance]
97        """
98        return list(self.stream(
99            status=status,
100            iccid=iccid,
101            rate_plan=rate_plan,
102            e_id=e_id,
103            sim_registration_code=sim_registration_code,
104            limit=limit,
105            page_size=page_size,
106        ))
107
108    def page(self, status=values.unset, iccid=values.unset, rate_plan=values.unset,
109             e_id=values.unset, sim_registration_code=values.unset,
110             page_token=values.unset, page_number=values.unset,
111             page_size=values.unset):
112        """
113        Retrieve a single page of SimInstance records from the API.
114        Request is executed immediately
115
116        :param unicode status: The status
117        :param unicode iccid: The iccid
118        :param unicode rate_plan: The rate_plan
119        :param unicode e_id: The e_id
120        :param unicode sim_registration_code: The sim_registration_code
121        :param str page_token: PageToken provided by the API
122        :param int page_number: Page Number, this value is simply for client state
123        :param int page_size: Number of records to return, defaults to 50
124
125        :returns: Page of SimInstance
126        :rtype: twilio.rest.preview.wireless.sim.SimPage
127        """
128        data = values.of({
129            'Status': status,
130            'Iccid': iccid,
131            'RatePlan': rate_plan,
132            'EId': e_id,
133            'SimRegistrationCode': sim_registration_code,
134            'PageToken': page_token,
135            'Page': page_number,
136            'PageSize': page_size,
137        })
138
139        response = self._version.page(method='GET', uri=self._uri, params=data, )
140
141        return SimPage(self._version, response, self._solution)
142
143    def get_page(self, target_url):
144        """
145        Retrieve a specific page of SimInstance records from the API.
146        Request is executed immediately
147
148        :param str target_url: API-generated URL for the requested results page
149
150        :returns: Page of SimInstance
151        :rtype: twilio.rest.preview.wireless.sim.SimPage
152        """
153        response = self._version.domain.twilio.request(
154            'GET',
155            target_url,
156        )
157
158        return SimPage(self._version, response, self._solution)
159
160    def get(self, sid):
161        """
162        Constructs a SimContext
163
164        :param sid: The sid
165
166        :returns: twilio.rest.preview.wireless.sim.SimContext
167        :rtype: twilio.rest.preview.wireless.sim.SimContext
168        """
169        return SimContext(self._version, sid=sid, )
170
171    def __call__(self, sid):
172        """
173        Constructs a SimContext
174
175        :param sid: The sid
176
177        :returns: twilio.rest.preview.wireless.sim.SimContext
178        :rtype: twilio.rest.preview.wireless.sim.SimContext
179        """
180        return SimContext(self._version, sid=sid, )
181
182    def __repr__(self):
183        """
184        Provide a friendly representation
185
186        :returns: Machine friendly representation
187        :rtype: str
188        """
189        return '<Twilio.Preview.Wireless.SimList>'
190
191
192class SimPage(Page):
193    """ PLEASE NOTE that this class contains preview products that are subject
194    to change. Use them with caution. If you currently do not have developer
195    preview access, please contact help@twilio.com. """
196
197    def __init__(self, version, response, solution):
198        """
199        Initialize the SimPage
200
201        :param Version version: Version that contains the resource
202        :param Response response: Response from the API
203
204        :returns: twilio.rest.preview.wireless.sim.SimPage
205        :rtype: twilio.rest.preview.wireless.sim.SimPage
206        """
207        super(SimPage, self).__init__(version, response)
208
209        # Path Solution
210        self._solution = solution
211
212    def get_instance(self, payload):
213        """
214        Build an instance of SimInstance
215
216        :param dict payload: Payload response from the API
217
218        :returns: twilio.rest.preview.wireless.sim.SimInstance
219        :rtype: twilio.rest.preview.wireless.sim.SimInstance
220        """
221        return SimInstance(self._version, payload, )
222
223    def __repr__(self):
224        """
225        Provide a friendly representation
226
227        :returns: Machine friendly representation
228        :rtype: str
229        """
230        return '<Twilio.Preview.Wireless.SimPage>'
231
232
233class SimContext(InstanceContext):
234    """ PLEASE NOTE that this class contains preview products that are subject
235    to change. Use them with caution. If you currently do not have developer
236    preview access, please contact help@twilio.com. """
237
238    def __init__(self, version, sid):
239        """
240        Initialize the SimContext
241
242        :param Version version: Version that contains the resource
243        :param sid: The sid
244
245        :returns: twilio.rest.preview.wireless.sim.SimContext
246        :rtype: twilio.rest.preview.wireless.sim.SimContext
247        """
248        super(SimContext, self).__init__(version)
249
250        # Path Solution
251        self._solution = {'sid': sid, }
252        self._uri = '/Sims/{sid}'.format(**self._solution)
253
254        # Dependents
255        self._usage = None
256
257    def fetch(self):
258        """
259        Fetch the SimInstance
260
261        :returns: The fetched SimInstance
262        :rtype: twilio.rest.preview.wireless.sim.SimInstance
263        """
264        payload = self._version.fetch(method='GET', uri=self._uri, )
265
266        return SimInstance(self._version, payload, sid=self._solution['sid'], )
267
268    def update(self, unique_name=values.unset, callback_method=values.unset,
269               callback_url=values.unset, friendly_name=values.unset,
270               rate_plan=values.unset, status=values.unset,
271               commands_callback_method=values.unset,
272               commands_callback_url=values.unset, sms_fallback_method=values.unset,
273               sms_fallback_url=values.unset, sms_method=values.unset,
274               sms_url=values.unset, voice_fallback_method=values.unset,
275               voice_fallback_url=values.unset, voice_method=values.unset,
276               voice_url=values.unset):
277        """
278        Update the SimInstance
279
280        :param unicode unique_name: The unique_name
281        :param unicode callback_method: The callback_method
282        :param unicode callback_url: The callback_url
283        :param unicode friendly_name: The friendly_name
284        :param unicode rate_plan: The rate_plan
285        :param unicode status: The status
286        :param unicode commands_callback_method: The commands_callback_method
287        :param unicode commands_callback_url: The commands_callback_url
288        :param unicode sms_fallback_method: The sms_fallback_method
289        :param unicode sms_fallback_url: The sms_fallback_url
290        :param unicode sms_method: The sms_method
291        :param unicode sms_url: The sms_url
292        :param unicode voice_fallback_method: The voice_fallback_method
293        :param unicode voice_fallback_url: The voice_fallback_url
294        :param unicode voice_method: The voice_method
295        :param unicode voice_url: The voice_url
296
297        :returns: The updated SimInstance
298        :rtype: twilio.rest.preview.wireless.sim.SimInstance
299        """
300        data = values.of({
301            'UniqueName': unique_name,
302            'CallbackMethod': callback_method,
303            'CallbackUrl': callback_url,
304            'FriendlyName': friendly_name,
305            'RatePlan': rate_plan,
306            'Status': status,
307            'CommandsCallbackMethod': commands_callback_method,
308            'CommandsCallbackUrl': commands_callback_url,
309            'SmsFallbackMethod': sms_fallback_method,
310            'SmsFallbackUrl': sms_fallback_url,
311            'SmsMethod': sms_method,
312            'SmsUrl': sms_url,
313            'VoiceFallbackMethod': voice_fallback_method,
314            'VoiceFallbackUrl': voice_fallback_url,
315            'VoiceMethod': voice_method,
316            'VoiceUrl': voice_url,
317        })
318
319        payload = self._version.update(method='POST', uri=self._uri, data=data, )
320
321        return SimInstance(self._version, payload, sid=self._solution['sid'], )
322
323    @property
324    def usage(self):
325        """
326        Access the usage
327
328        :returns: twilio.rest.preview.wireless.sim.usage.UsageList
329        :rtype: twilio.rest.preview.wireless.sim.usage.UsageList
330        """
331        if self._usage is None:
332            self._usage = UsageList(self._version, sim_sid=self._solution['sid'], )
333        return self._usage
334
335    def __repr__(self):
336        """
337        Provide a friendly representation
338
339        :returns: Machine friendly representation
340        :rtype: str
341        """
342        context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
343        return '<Twilio.Preview.Wireless.SimContext {}>'.format(context)
344
345
346class SimInstance(InstanceResource):
347    """ PLEASE NOTE that this class contains preview products that are subject
348    to change. Use them with caution. If you currently do not have developer
349    preview access, please contact help@twilio.com. """
350
351    def __init__(self, version, payload, sid=None):
352        """
353        Initialize the SimInstance
354
355        :returns: twilio.rest.preview.wireless.sim.SimInstance
356        :rtype: twilio.rest.preview.wireless.sim.SimInstance
357        """
358        super(SimInstance, self).__init__(version)
359
360        # Marshaled Properties
361        self._properties = {
362            'sid': payload.get('sid'),
363            'unique_name': payload.get('unique_name'),
364            'account_sid': payload.get('account_sid'),
365            'rate_plan_sid': payload.get('rate_plan_sid'),
366            'friendly_name': payload.get('friendly_name'),
367            'iccid': payload.get('iccid'),
368            'e_id': payload.get('e_id'),
369            'status': payload.get('status'),
370            'commands_callback_url': payload.get('commands_callback_url'),
371            'commands_callback_method': payload.get('commands_callback_method'),
372            'sms_fallback_method': payload.get('sms_fallback_method'),
373            'sms_fallback_url': payload.get('sms_fallback_url'),
374            'sms_method': payload.get('sms_method'),
375            'sms_url': payload.get('sms_url'),
376            'voice_fallback_method': payload.get('voice_fallback_method'),
377            'voice_fallback_url': payload.get('voice_fallback_url'),
378            'voice_method': payload.get('voice_method'),
379            'voice_url': payload.get('voice_url'),
380            'date_created': deserialize.iso8601_datetime(payload.get('date_created')),
381            'date_updated': deserialize.iso8601_datetime(payload.get('date_updated')),
382            'url': payload.get('url'),
383            'links': payload.get('links'),
384        }
385
386        # Context
387        self._context = None
388        self._solution = {'sid': sid or self._properties['sid'], }
389
390    @property
391    def _proxy(self):
392        """
393        Generate an instance context for the instance, the context is capable of
394        performing various actions.  All instance actions are proxied to the context
395
396        :returns: SimContext for this SimInstance
397        :rtype: twilio.rest.preview.wireless.sim.SimContext
398        """
399        if self._context is None:
400            self._context = SimContext(self._version, sid=self._solution['sid'], )
401        return self._context
402
403    @property
404    def sid(self):
405        """
406        :returns: The sid
407        :rtype: unicode
408        """
409        return self._properties['sid']
410
411    @property
412    def unique_name(self):
413        """
414        :returns: The unique_name
415        :rtype: unicode
416        """
417        return self._properties['unique_name']
418
419    @property
420    def account_sid(self):
421        """
422        :returns: The account_sid
423        :rtype: unicode
424        """
425        return self._properties['account_sid']
426
427    @property
428    def rate_plan_sid(self):
429        """
430        :returns: The rate_plan_sid
431        :rtype: unicode
432        """
433        return self._properties['rate_plan_sid']
434
435    @property
436    def friendly_name(self):
437        """
438        :returns: The friendly_name
439        :rtype: unicode
440        """
441        return self._properties['friendly_name']
442
443    @property
444    def iccid(self):
445        """
446        :returns: The iccid
447        :rtype: unicode
448        """
449        return self._properties['iccid']
450
451    @property
452    def e_id(self):
453        """
454        :returns: The e_id
455        :rtype: unicode
456        """
457        return self._properties['e_id']
458
459    @property
460    def status(self):
461        """
462        :returns: The status
463        :rtype: unicode
464        """
465        return self._properties['status']
466
467    @property
468    def commands_callback_url(self):
469        """
470        :returns: The commands_callback_url
471        :rtype: unicode
472        """
473        return self._properties['commands_callback_url']
474
475    @property
476    def commands_callback_method(self):
477        """
478        :returns: The commands_callback_method
479        :rtype: unicode
480        """
481        return self._properties['commands_callback_method']
482
483    @property
484    def sms_fallback_method(self):
485        """
486        :returns: The sms_fallback_method
487        :rtype: unicode
488        """
489        return self._properties['sms_fallback_method']
490
491    @property
492    def sms_fallback_url(self):
493        """
494        :returns: The sms_fallback_url
495        :rtype: unicode
496        """
497        return self._properties['sms_fallback_url']
498
499    @property
500    def sms_method(self):
501        """
502        :returns: The sms_method
503        :rtype: unicode
504        """
505        return self._properties['sms_method']
506
507    @property
508    def sms_url(self):
509        """
510        :returns: The sms_url
511        :rtype: unicode
512        """
513        return self._properties['sms_url']
514
515    @property
516    def voice_fallback_method(self):
517        """
518        :returns: The voice_fallback_method
519        :rtype: unicode
520        """
521        return self._properties['voice_fallback_method']
522
523    @property
524    def voice_fallback_url(self):
525        """
526        :returns: The voice_fallback_url
527        :rtype: unicode
528        """
529        return self._properties['voice_fallback_url']
530
531    @property
532    def voice_method(self):
533        """
534        :returns: The voice_method
535        :rtype: unicode
536        """
537        return self._properties['voice_method']
538
539    @property
540    def voice_url(self):
541        """
542        :returns: The voice_url
543        :rtype: unicode
544        """
545        return self._properties['voice_url']
546
547    @property
548    def date_created(self):
549        """
550        :returns: The date_created
551        :rtype: datetime
552        """
553        return self._properties['date_created']
554
555    @property
556    def date_updated(self):
557        """
558        :returns: The date_updated
559        :rtype: datetime
560        """
561        return self._properties['date_updated']
562
563    @property
564    def url(self):
565        """
566        :returns: The url
567        :rtype: unicode
568        """
569        return self._properties['url']
570
571    @property
572    def links(self):
573        """
574        :returns: The links
575        :rtype: unicode
576        """
577        return self._properties['links']
578
579    def fetch(self):
580        """
581        Fetch the SimInstance
582
583        :returns: The fetched SimInstance
584        :rtype: twilio.rest.preview.wireless.sim.SimInstance
585        """
586        return self._proxy.fetch()
587
588    def update(self, unique_name=values.unset, callback_method=values.unset,
589               callback_url=values.unset, friendly_name=values.unset,
590               rate_plan=values.unset, status=values.unset,
591               commands_callback_method=values.unset,
592               commands_callback_url=values.unset, sms_fallback_method=values.unset,
593               sms_fallback_url=values.unset, sms_method=values.unset,
594               sms_url=values.unset, voice_fallback_method=values.unset,
595               voice_fallback_url=values.unset, voice_method=values.unset,
596               voice_url=values.unset):
597        """
598        Update the SimInstance
599
600        :param unicode unique_name: The unique_name
601        :param unicode callback_method: The callback_method
602        :param unicode callback_url: The callback_url
603        :param unicode friendly_name: The friendly_name
604        :param unicode rate_plan: The rate_plan
605        :param unicode status: The status
606        :param unicode commands_callback_method: The commands_callback_method
607        :param unicode commands_callback_url: The commands_callback_url
608        :param unicode sms_fallback_method: The sms_fallback_method
609        :param unicode sms_fallback_url: The sms_fallback_url
610        :param unicode sms_method: The sms_method
611        :param unicode sms_url: The sms_url
612        :param unicode voice_fallback_method: The voice_fallback_method
613        :param unicode voice_fallback_url: The voice_fallback_url
614        :param unicode voice_method: The voice_method
615        :param unicode voice_url: The voice_url
616
617        :returns: The updated SimInstance
618        :rtype: twilio.rest.preview.wireless.sim.SimInstance
619        """
620        return self._proxy.update(
621            unique_name=unique_name,
622            callback_method=callback_method,
623            callback_url=callback_url,
624            friendly_name=friendly_name,
625            rate_plan=rate_plan,
626            status=status,
627            commands_callback_method=commands_callback_method,
628            commands_callback_url=commands_callback_url,
629            sms_fallback_method=sms_fallback_method,
630            sms_fallback_url=sms_fallback_url,
631            sms_method=sms_method,
632            sms_url=sms_url,
633            voice_fallback_method=voice_fallback_method,
634            voice_fallback_url=voice_fallback_url,
635            voice_method=voice_method,
636            voice_url=voice_url,
637        )
638
639    @property
640    def usage(self):
641        """
642        Access the usage
643
644        :returns: twilio.rest.preview.wireless.sim.usage.UsageList
645        :rtype: twilio.rest.preview.wireless.sim.usage.UsageList
646        """
647        return self._proxy.usage
648
649    def __repr__(self):
650        """
651        Provide a friendly representation
652
653        :returns: Machine friendly representation
654        :rtype: str
655        """
656        context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
657        return '<Twilio.Preview.Wireless.SimInstance {}>'.format(context)
658