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
15
16
17class InteractionList(ListResource):
18    """ PLEASE NOTE that this class contains beta products that are subject to
19    change. Use them with caution. """
20
21    def __init__(self, version, service_sid, session_sid):
22        """
23        Initialize the InteractionList
24
25        :param Version version: Version that contains the resource
26        :param service_sid: The SID of the resource's parent Service
27        :param session_sid: The SID of the resource's parent Session
28
29        :returns: twilio.rest.proxy.v1.service.session.interaction.InteractionList
30        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionList
31        """
32        super(InteractionList, self).__init__(version)
33
34        # Path Solution
35        self._solution = {'service_sid': service_sid, 'session_sid': session_sid, }
36        self._uri = '/Services/{service_sid}/Sessions/{session_sid}/Interactions'.format(**self._solution)
37
38    def stream(self, limit=None, page_size=None):
39        """
40        Streams InteractionInstance records from the API as a generator stream.
41        This operation lazily loads records as efficiently as possible until the limit
42        is reached.
43        The results are returned as a generator, so this operation is memory efficient.
44
45        :param int limit: Upper limit for the number of records to return. stream()
46                          guarantees to never return more than limit.  Default is no limit
47        :param int page_size: Number of records to fetch per request, when not set will use
48                              the default value of 50 records.  If no page_size is defined
49                              but a limit is defined, stream() will attempt to read the
50                              limit with the most efficient page size, i.e. min(limit, 1000)
51
52        :returns: Generator that will yield up to limit results
53        :rtype: list[twilio.rest.proxy.v1.service.session.interaction.InteractionInstance]
54        """
55        limits = self._version.read_limits(limit, page_size)
56
57        page = self.page(page_size=limits['page_size'], )
58
59        return self._version.stream(page, limits['limit'])
60
61    def list(self, limit=None, page_size=None):
62        """
63        Lists InteractionInstance records from the API as a list.
64        Unlike stream(), this operation is eager and will load `limit` records into
65        memory before returning.
66
67        :param int limit: Upper limit for the number of records to return. list() guarantees
68                          never to return more than limit.  Default is no limit
69        :param int page_size: Number of records to fetch per request, when not set will use
70                              the default value of 50 records.  If no page_size is defined
71                              but a limit is defined, list() will attempt to read the limit
72                              with the most efficient page size, i.e. min(limit, 1000)
73
74        :returns: Generator that will yield up to limit results
75        :rtype: list[twilio.rest.proxy.v1.service.session.interaction.InteractionInstance]
76        """
77        return list(self.stream(limit=limit, page_size=page_size, ))
78
79    def page(self, page_token=values.unset, page_number=values.unset,
80             page_size=values.unset):
81        """
82        Retrieve a single page of InteractionInstance records from the API.
83        Request is executed immediately
84
85        :param str page_token: PageToken provided by the API
86        :param int page_number: Page Number, this value is simply for client state
87        :param int page_size: Number of records to return, defaults to 50
88
89        :returns: Page of InteractionInstance
90        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionPage
91        """
92        data = values.of({'PageToken': page_token, 'Page': page_number, 'PageSize': page_size, })
93
94        response = self._version.page(method='GET', uri=self._uri, params=data, )
95
96        return InteractionPage(self._version, response, self._solution)
97
98    def get_page(self, target_url):
99        """
100        Retrieve a specific page of InteractionInstance records from the API.
101        Request is executed immediately
102
103        :param str target_url: API-generated URL for the requested results page
104
105        :returns: Page of InteractionInstance
106        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionPage
107        """
108        response = self._version.domain.twilio.request(
109            'GET',
110            target_url,
111        )
112
113        return InteractionPage(self._version, response, self._solution)
114
115    def get(self, sid):
116        """
117        Constructs a InteractionContext
118
119        :param sid: The unique string that identifies the resource
120
121        :returns: twilio.rest.proxy.v1.service.session.interaction.InteractionContext
122        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionContext
123        """
124        return InteractionContext(
125            self._version,
126            service_sid=self._solution['service_sid'],
127            session_sid=self._solution['session_sid'],
128            sid=sid,
129        )
130
131    def __call__(self, sid):
132        """
133        Constructs a InteractionContext
134
135        :param sid: The unique string that identifies the resource
136
137        :returns: twilio.rest.proxy.v1.service.session.interaction.InteractionContext
138        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionContext
139        """
140        return InteractionContext(
141            self._version,
142            service_sid=self._solution['service_sid'],
143            session_sid=self._solution['session_sid'],
144            sid=sid,
145        )
146
147    def __repr__(self):
148        """
149        Provide a friendly representation
150
151        :returns: Machine friendly representation
152        :rtype: str
153        """
154        return '<Twilio.Proxy.V1.InteractionList>'
155
156
157class InteractionPage(Page):
158    """ PLEASE NOTE that this class contains beta products that are subject to
159    change. Use them with caution. """
160
161    def __init__(self, version, response, solution):
162        """
163        Initialize the InteractionPage
164
165        :param Version version: Version that contains the resource
166        :param Response response: Response from the API
167        :param service_sid: The SID of the resource's parent Service
168        :param session_sid: The SID of the resource's parent Session
169
170        :returns: twilio.rest.proxy.v1.service.session.interaction.InteractionPage
171        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionPage
172        """
173        super(InteractionPage, self).__init__(version, response)
174
175        # Path Solution
176        self._solution = solution
177
178    def get_instance(self, payload):
179        """
180        Build an instance of InteractionInstance
181
182        :param dict payload: Payload response from the API
183
184        :returns: twilio.rest.proxy.v1.service.session.interaction.InteractionInstance
185        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionInstance
186        """
187        return InteractionInstance(
188            self._version,
189            payload,
190            service_sid=self._solution['service_sid'],
191            session_sid=self._solution['session_sid'],
192        )
193
194    def __repr__(self):
195        """
196        Provide a friendly representation
197
198        :returns: Machine friendly representation
199        :rtype: str
200        """
201        return '<Twilio.Proxy.V1.InteractionPage>'
202
203
204class InteractionContext(InstanceContext):
205    """ PLEASE NOTE that this class contains beta products that are subject to
206    change. Use them with caution. """
207
208    def __init__(self, version, service_sid, session_sid, sid):
209        """
210        Initialize the InteractionContext
211
212        :param Version version: Version that contains the resource
213        :param service_sid: The SID of the parent Service of the resource to fetch
214        :param session_sid: he SID of the parent Session of the resource to fetch
215        :param sid: The unique string that identifies the resource
216
217        :returns: twilio.rest.proxy.v1.service.session.interaction.InteractionContext
218        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionContext
219        """
220        super(InteractionContext, self).__init__(version)
221
222        # Path Solution
223        self._solution = {'service_sid': service_sid, 'session_sid': session_sid, 'sid': sid, }
224        self._uri = '/Services/{service_sid}/Sessions/{session_sid}/Interactions/{sid}'.format(**self._solution)
225
226    def fetch(self):
227        """
228        Fetch the InteractionInstance
229
230        :returns: The fetched InteractionInstance
231        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionInstance
232        """
233        payload = self._version.fetch(method='GET', uri=self._uri, )
234
235        return InteractionInstance(
236            self._version,
237            payload,
238            service_sid=self._solution['service_sid'],
239            session_sid=self._solution['session_sid'],
240            sid=self._solution['sid'],
241        )
242
243    def delete(self):
244        """
245        Deletes the InteractionInstance
246
247        :returns: True if delete succeeds, False otherwise
248        :rtype: bool
249        """
250        return self._version.delete(method='DELETE', uri=self._uri, )
251
252    def __repr__(self):
253        """
254        Provide a friendly representation
255
256        :returns: Machine friendly representation
257        :rtype: str
258        """
259        context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
260        return '<Twilio.Proxy.V1.InteractionContext {}>'.format(context)
261
262
263class InteractionInstance(InstanceResource):
264    """ PLEASE NOTE that this class contains beta products that are subject to
265    change. Use them with caution. """
266
267    class Type(object):
268        MESSAGE = "message"
269        VOICE = "voice"
270        UNKNOWN = "unknown"
271
272    class ResourceStatus(object):
273        ACCEPTED = "accepted"
274        ANSWERED = "answered"
275        BUSY = "busy"
276        CANCELED = "canceled"
277        COMPLETED = "completed"
278        DELETED = "deleted"
279        DELIVERED = "delivered"
280        DELIVERY_UNKNOWN = "delivery-unknown"
281        FAILED = "failed"
282        IN_PROGRESS = "in-progress"
283        INITIATED = "initiated"
284        NO_ANSWER = "no-answer"
285        QUEUED = "queued"
286        RECEIVED = "received"
287        RECEIVING = "receiving"
288        RINGING = "ringing"
289        SCHEDULED = "scheduled"
290        SENDING = "sending"
291        SENT = "sent"
292        UNDELIVERED = "undelivered"
293        UNKNOWN = "unknown"
294
295    def __init__(self, version, payload, service_sid, session_sid, sid=None):
296        """
297        Initialize the InteractionInstance
298
299        :returns: twilio.rest.proxy.v1.service.session.interaction.InteractionInstance
300        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionInstance
301        """
302        super(InteractionInstance, self).__init__(version)
303
304        # Marshaled Properties
305        self._properties = {
306            'sid': payload.get('sid'),
307            'session_sid': payload.get('session_sid'),
308            'service_sid': payload.get('service_sid'),
309            'account_sid': payload.get('account_sid'),
310            'data': payload.get('data'),
311            'type': payload.get('type'),
312            'inbound_participant_sid': payload.get('inbound_participant_sid'),
313            'inbound_resource_sid': payload.get('inbound_resource_sid'),
314            'inbound_resource_status': payload.get('inbound_resource_status'),
315            'inbound_resource_type': payload.get('inbound_resource_type'),
316            'inbound_resource_url': payload.get('inbound_resource_url'),
317            'outbound_participant_sid': payload.get('outbound_participant_sid'),
318            'outbound_resource_sid': payload.get('outbound_resource_sid'),
319            'outbound_resource_status': payload.get('outbound_resource_status'),
320            'outbound_resource_type': payload.get('outbound_resource_type'),
321            'outbound_resource_url': payload.get('outbound_resource_url'),
322            'date_created': deserialize.iso8601_datetime(payload.get('date_created')),
323            'date_updated': deserialize.iso8601_datetime(payload.get('date_updated')),
324            'url': payload.get('url'),
325        }
326
327        # Context
328        self._context = None
329        self._solution = {
330            'service_sid': service_sid,
331            'session_sid': session_sid,
332            'sid': sid or self._properties['sid'],
333        }
334
335    @property
336    def _proxy(self):
337        """
338        Generate an instance context for the instance, the context is capable of
339        performing various actions.  All instance actions are proxied to the context
340
341        :returns: InteractionContext for this InteractionInstance
342        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionContext
343        """
344        if self._context is None:
345            self._context = InteractionContext(
346                self._version,
347                service_sid=self._solution['service_sid'],
348                session_sid=self._solution['session_sid'],
349                sid=self._solution['sid'],
350            )
351        return self._context
352
353    @property
354    def sid(self):
355        """
356        :returns: The unique string that identifies the resource
357        :rtype: unicode
358        """
359        return self._properties['sid']
360
361    @property
362    def session_sid(self):
363        """
364        :returns: The SID of the resource's parent Session
365        :rtype: unicode
366        """
367        return self._properties['session_sid']
368
369    @property
370    def service_sid(self):
371        """
372        :returns: The SID of the resource's parent Service
373        :rtype: unicode
374        """
375        return self._properties['service_sid']
376
377    @property
378    def account_sid(self):
379        """
380        :returns: The SID of the Account that created the resource
381        :rtype: unicode
382        """
383        return self._properties['account_sid']
384
385    @property
386    def data(self):
387        """
388        :returns: A JSON string that includes the message body of message interactions
389        :rtype: unicode
390        """
391        return self._properties['data']
392
393    @property
394    def type(self):
395        """
396        :returns: The Type of the Interaction
397        :rtype: InteractionInstance.Type
398        """
399        return self._properties['type']
400
401    @property
402    def inbound_participant_sid(self):
403        """
404        :returns: The SID of the inbound Participant resource
405        :rtype: unicode
406        """
407        return self._properties['inbound_participant_sid']
408
409    @property
410    def inbound_resource_sid(self):
411        """
412        :returns: The SID of the inbound resource
413        :rtype: unicode
414        """
415        return self._properties['inbound_resource_sid']
416
417    @property
418    def inbound_resource_status(self):
419        """
420        :returns: The inbound resource status of the Interaction
421        :rtype: InteractionInstance.ResourceStatus
422        """
423        return self._properties['inbound_resource_status']
424
425    @property
426    def inbound_resource_type(self):
427        """
428        :returns: The inbound resource type
429        :rtype: unicode
430        """
431        return self._properties['inbound_resource_type']
432
433    @property
434    def inbound_resource_url(self):
435        """
436        :returns: The URL of the Twilio inbound resource
437        :rtype: unicode
438        """
439        return self._properties['inbound_resource_url']
440
441    @property
442    def outbound_participant_sid(self):
443        """
444        :returns: The SID of the outbound Participant
445        :rtype: unicode
446        """
447        return self._properties['outbound_participant_sid']
448
449    @property
450    def outbound_resource_sid(self):
451        """
452        :returns: The SID of the outbound resource
453        :rtype: unicode
454        """
455        return self._properties['outbound_resource_sid']
456
457    @property
458    def outbound_resource_status(self):
459        """
460        :returns: The outbound resource status of the Interaction
461        :rtype: InteractionInstance.ResourceStatus
462        """
463        return self._properties['outbound_resource_status']
464
465    @property
466    def outbound_resource_type(self):
467        """
468        :returns: The outbound resource type
469        :rtype: unicode
470        """
471        return self._properties['outbound_resource_type']
472
473    @property
474    def outbound_resource_url(self):
475        """
476        :returns: The URL of the Twilio outbound resource
477        :rtype: unicode
478        """
479        return self._properties['outbound_resource_url']
480
481    @property
482    def date_created(self):
483        """
484        :returns: The ISO 8601 date and time in GMT when the Interaction was created
485        :rtype: datetime
486        """
487        return self._properties['date_created']
488
489    @property
490    def date_updated(self):
491        """
492        :returns: The ISO 8601 date and time in GMT when the resource was last updated
493        :rtype: datetime
494        """
495        return self._properties['date_updated']
496
497    @property
498    def url(self):
499        """
500        :returns: The absolute URL of the Interaction resource
501        :rtype: unicode
502        """
503        return self._properties['url']
504
505    def fetch(self):
506        """
507        Fetch the InteractionInstance
508
509        :returns: The fetched InteractionInstance
510        :rtype: twilio.rest.proxy.v1.service.session.interaction.InteractionInstance
511        """
512        return self._proxy.fetch()
513
514    def delete(self):
515        """
516        Deletes the InteractionInstance
517
518        :returns: True if delete succeeds, False otherwise
519        :rtype: bool
520        """
521        return self._proxy.delete()
522
523    def __repr__(self):
524        """
525        Provide a friendly representation
526
527        :returns: Machine friendly representation
528        :rtype: str
529        """
530        context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
531        return '<Twilio.Proxy.V1.InteractionInstance {}>'.format(context)
532