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 ParticipantList(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, room_sid):
22        """
23        Initialize the ParticipantList
24
25        :param Version version: Version that contains the resource
26        :param room_sid: Unique identifier for the room.
27
28        :returns: twilio.rest.insights.v1.room.participant.ParticipantList
29        :rtype: twilio.rest.insights.v1.room.participant.ParticipantList
30        """
31        super(ParticipantList, self).__init__(version)
32
33        # Path Solution
34        self._solution = {'room_sid': room_sid, }
35        self._uri = '/Video/Rooms/{room_sid}/Participants'.format(**self._solution)
36
37    def stream(self, limit=None, page_size=None):
38        """
39        Streams ParticipantInstance records from the API as a generator stream.
40        This operation lazily loads records as efficiently as possible until the limit
41        is reached.
42        The results are returned as a generator, so this operation is memory efficient.
43
44        :param int limit: Upper limit for the number of records to return. stream()
45                          guarantees to never return more than limit.  Default is no limit
46        :param int page_size: Number of records to fetch per request, when not set will use
47                              the default value of 50 records.  If no page_size is defined
48                              but a limit is defined, stream() will attempt to read the
49                              limit with the most efficient page size, i.e. min(limit, 1000)
50
51        :returns: Generator that will yield up to limit results
52        :rtype: list[twilio.rest.insights.v1.room.participant.ParticipantInstance]
53        """
54        limits = self._version.read_limits(limit, page_size)
55
56        page = self.page(page_size=limits['page_size'], )
57
58        return self._version.stream(page, limits['limit'])
59
60    def list(self, limit=None, page_size=None):
61        """
62        Lists ParticipantInstance records from the API as a list.
63        Unlike stream(), this operation is eager and will load `limit` records into
64        memory before returning.
65
66        :param int limit: Upper limit for the number of records to return. list() guarantees
67                          never to return more than limit.  Default is no limit
68        :param int page_size: Number of records to fetch per request, when not set will use
69                              the default value of 50 records.  If no page_size is defined
70                              but a limit is defined, list() will attempt to read the limit
71                              with the most efficient page size, i.e. min(limit, 1000)
72
73        :returns: Generator that will yield up to limit results
74        :rtype: list[twilio.rest.insights.v1.room.participant.ParticipantInstance]
75        """
76        return list(self.stream(limit=limit, page_size=page_size, ))
77
78    def page(self, page_token=values.unset, page_number=values.unset,
79             page_size=values.unset):
80        """
81        Retrieve a single page of ParticipantInstance records from the API.
82        Request is executed immediately
83
84        :param str page_token: PageToken provided by the API
85        :param int page_number: Page Number, this value is simply for client state
86        :param int page_size: Number of records to return, defaults to 50
87
88        :returns: Page of ParticipantInstance
89        :rtype: twilio.rest.insights.v1.room.participant.ParticipantPage
90        """
91        data = values.of({'PageToken': page_token, 'Page': page_number, 'PageSize': page_size, })
92
93        response = self._version.page(method='GET', uri=self._uri, params=data, )
94
95        return ParticipantPage(self._version, response, self._solution)
96
97    def get_page(self, target_url):
98        """
99        Retrieve a specific page of ParticipantInstance records from the API.
100        Request is executed immediately
101
102        :param str target_url: API-generated URL for the requested results page
103
104        :returns: Page of ParticipantInstance
105        :rtype: twilio.rest.insights.v1.room.participant.ParticipantPage
106        """
107        response = self._version.domain.twilio.request(
108            'GET',
109            target_url,
110        )
111
112        return ParticipantPage(self._version, response, self._solution)
113
114    def get(self, participant_sid):
115        """
116        Constructs a ParticipantContext
117
118        :param participant_sid: The SID of the Participant resource.
119
120        :returns: twilio.rest.insights.v1.room.participant.ParticipantContext
121        :rtype: twilio.rest.insights.v1.room.participant.ParticipantContext
122        """
123        return ParticipantContext(
124            self._version,
125            room_sid=self._solution['room_sid'],
126            participant_sid=participant_sid,
127        )
128
129    def __call__(self, participant_sid):
130        """
131        Constructs a ParticipantContext
132
133        :param participant_sid: The SID of the Participant resource.
134
135        :returns: twilio.rest.insights.v1.room.participant.ParticipantContext
136        :rtype: twilio.rest.insights.v1.room.participant.ParticipantContext
137        """
138        return ParticipantContext(
139            self._version,
140            room_sid=self._solution['room_sid'],
141            participant_sid=participant_sid,
142        )
143
144    def __repr__(self):
145        """
146        Provide a friendly representation
147
148        :returns: Machine friendly representation
149        :rtype: str
150        """
151        return '<Twilio.Insights.V1.ParticipantList>'
152
153
154class ParticipantPage(Page):
155    """ PLEASE NOTE that this class contains beta products that are subject to
156    change. Use them with caution. """
157
158    def __init__(self, version, response, solution):
159        """
160        Initialize the ParticipantPage
161
162        :param Version version: Version that contains the resource
163        :param Response response: Response from the API
164        :param room_sid: Unique identifier for the room.
165
166        :returns: twilio.rest.insights.v1.room.participant.ParticipantPage
167        :rtype: twilio.rest.insights.v1.room.participant.ParticipantPage
168        """
169        super(ParticipantPage, self).__init__(version, response)
170
171        # Path Solution
172        self._solution = solution
173
174    def get_instance(self, payload):
175        """
176        Build an instance of ParticipantInstance
177
178        :param dict payload: Payload response from the API
179
180        :returns: twilio.rest.insights.v1.room.participant.ParticipantInstance
181        :rtype: twilio.rest.insights.v1.room.participant.ParticipantInstance
182        """
183        return ParticipantInstance(self._version, payload, room_sid=self._solution['room_sid'], )
184
185    def __repr__(self):
186        """
187        Provide a friendly representation
188
189        :returns: Machine friendly representation
190        :rtype: str
191        """
192        return '<Twilio.Insights.V1.ParticipantPage>'
193
194
195class ParticipantContext(InstanceContext):
196    """ PLEASE NOTE that this class contains beta products that are subject to
197    change. Use them with caution. """
198
199    def __init__(self, version, room_sid, participant_sid):
200        """
201        Initialize the ParticipantContext
202
203        :param Version version: Version that contains the resource
204        :param room_sid: The SID of the Room resource.
205        :param participant_sid: The SID of the Participant resource.
206
207        :returns: twilio.rest.insights.v1.room.participant.ParticipantContext
208        :rtype: twilio.rest.insights.v1.room.participant.ParticipantContext
209        """
210        super(ParticipantContext, self).__init__(version)
211
212        # Path Solution
213        self._solution = {'room_sid': room_sid, 'participant_sid': participant_sid, }
214        self._uri = '/Video/Rooms/{room_sid}/Participants/{participant_sid}'.format(**self._solution)
215
216    def fetch(self):
217        """
218        Fetch the ParticipantInstance
219
220        :returns: The fetched ParticipantInstance
221        :rtype: twilio.rest.insights.v1.room.participant.ParticipantInstance
222        """
223        payload = self._version.fetch(method='GET', uri=self._uri, )
224
225        return ParticipantInstance(
226            self._version,
227            payload,
228            room_sid=self._solution['room_sid'],
229            participant_sid=self._solution['participant_sid'],
230        )
231
232    def __repr__(self):
233        """
234        Provide a friendly representation
235
236        :returns: Machine friendly representation
237        :rtype: str
238        """
239        context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
240        return '<Twilio.Insights.V1.ParticipantContext {}>'.format(context)
241
242
243class ParticipantInstance(InstanceResource):
244    """ PLEASE NOTE that this class contains beta products that are subject to
245    change. Use them with caution. """
246
247    class RoomStatus(object):
248        IN_PROGRESS = "in_progress"
249        COMPLETED = "completed"
250
251    class Codec(object):
252        VP8 = "VP8"
253        H264 = "H264"
254        VP9 = "VP9"
255
256    class TwilioRealm(object):
257        US1 = "us1"
258        US2 = "us2"
259        AU1 = "au1"
260        BR1 = "br1"
261        IE1 = "ie1"
262        JP1 = "jp1"
263        SG1 = "sg1"
264        IN1 = "in1"
265        DE1 = "de1"
266        GLL = "gll"
267
268    class EdgeLocation(object):
269        ASHBURN = "ashburn"
270        DUBLIN = "dublin"
271        FRANKFURT = "frankfurt"
272        SINGAPORE = "singapore"
273        SYDNEY = "sydney"
274        SAO_PAULO = "sao_paulo"
275        ROAMING = "roaming"
276        UMATILLA = "umatilla"
277        TOKYO = "tokyo"
278
279    def __init__(self, version, payload, room_sid, participant_sid=None):
280        """
281        Initialize the ParticipantInstance
282
283        :returns: twilio.rest.insights.v1.room.participant.ParticipantInstance
284        :rtype: twilio.rest.insights.v1.room.participant.ParticipantInstance
285        """
286        super(ParticipantInstance, self).__init__(version)
287
288        # Marshaled Properties
289        self._properties = {
290            'participant_sid': payload.get('participant_sid'),
291            'participant_identity': payload.get('participant_identity'),
292            'join_time': deserialize.iso8601_datetime(payload.get('join_time')),
293            'leave_time': deserialize.iso8601_datetime(payload.get('leave_time')),
294            'duration_sec': deserialize.integer(payload.get('duration_sec')),
295            'account_sid': payload.get('account_sid'),
296            'room_sid': payload.get('room_sid'),
297            'status': payload.get('status'),
298            'codecs': payload.get('codecs'),
299            'end_reason': payload.get('end_reason'),
300            'error_code': deserialize.integer(payload.get('error_code')),
301            'error_code_url': payload.get('error_code_url'),
302            'media_region': payload.get('media_region'),
303            'properties': payload.get('properties'),
304            'edge_location': payload.get('edge_location'),
305            'publisher_info': payload.get('publisher_info'),
306            'url': payload.get('url'),
307        }
308
309        # Context
310        self._context = None
311        self._solution = {
312            'room_sid': room_sid,
313            'participant_sid': participant_sid or self._properties['participant_sid'],
314        }
315
316    @property
317    def _proxy(self):
318        """
319        Generate an instance context for the instance, the context is capable of
320        performing various actions.  All instance actions are proxied to the context
321
322        :returns: ParticipantContext for this ParticipantInstance
323        :rtype: twilio.rest.insights.v1.room.participant.ParticipantContext
324        """
325        if self._context is None:
326            self._context = ParticipantContext(
327                self._version,
328                room_sid=self._solution['room_sid'],
329                participant_sid=self._solution['participant_sid'],
330            )
331        return self._context
332
333    @property
334    def participant_sid(self):
335        """
336        :returns: Unique identifier for the participant.
337        :rtype: unicode
338        """
339        return self._properties['participant_sid']
340
341    @property
342    def participant_identity(self):
343        """
344        :returns: The application-defined string that uniquely identifies the participant within a Room.
345        :rtype: unicode
346        """
347        return self._properties['participant_identity']
348
349    @property
350    def join_time(self):
351        """
352        :returns: When the participant joined the room.
353        :rtype: datetime
354        """
355        return self._properties['join_time']
356
357    @property
358    def leave_time(self):
359        """
360        :returns: When the participant left the room
361        :rtype: datetime
362        """
363        return self._properties['leave_time']
364
365    @property
366    def duration_sec(self):
367        """
368        :returns: Amount of time in seconds the participant was in the room.
369        :rtype: unicode
370        """
371        return self._properties['duration_sec']
372
373    @property
374    def account_sid(self):
375        """
376        :returns: Account SID associated with the room.
377        :rtype: unicode
378        """
379        return self._properties['account_sid']
380
381    @property
382    def room_sid(self):
383        """
384        :returns: Unique identifier for the room.
385        :rtype: unicode
386        """
387        return self._properties['room_sid']
388
389    @property
390    def status(self):
391        """
392        :returns: Status of the room.
393        :rtype: ParticipantInstance.RoomStatus
394        """
395        return self._properties['status']
396
397    @property
398    def codecs(self):
399        """
400        :returns: Codecs detected from the participant.
401        :rtype: list[ParticipantInstance.Codec]
402        """
403        return self._properties['codecs']
404
405    @property
406    def end_reason(self):
407        """
408        :returns: Reason the participant left the room.
409        :rtype: unicode
410        """
411        return self._properties['end_reason']
412
413    @property
414    def error_code(self):
415        """
416        :returns: Errors encountered by the participant.
417        :rtype: unicode
418        """
419        return self._properties['error_code']
420
421    @property
422    def error_code_url(self):
423        """
424        :returns: Twilio error code dictionary link.
425        :rtype: unicode
426        """
427        return self._properties['error_code_url']
428
429    @property
430    def media_region(self):
431        """
432        :returns: Twilio media region the participant connected to.
433        :rtype: ParticipantInstance.TwilioRealm
434        """
435        return self._properties['media_region']
436
437    @property
438    def properties(self):
439        """
440        :returns: Object containing information about the participant's data from the room.
441        :rtype: dict
442        """
443        return self._properties['properties']
444
445    @property
446    def edge_location(self):
447        """
448        :returns: Name of the edge location the participant connected to.
449        :rtype: ParticipantInstance.EdgeLocation
450        """
451        return self._properties['edge_location']
452
453    @property
454    def publisher_info(self):
455        """
456        :returns: Object containing information about the SDK name and version.
457        :rtype: dict
458        """
459        return self._properties['publisher_info']
460
461    @property
462    def url(self):
463        """
464        :returns: URL of the participant resource.
465        :rtype: unicode
466        """
467        return self._properties['url']
468
469    def fetch(self):
470        """
471        Fetch the ParticipantInstance
472
473        :returns: The fetched ParticipantInstance
474        :rtype: twilio.rest.insights.v1.room.participant.ParticipantInstance
475        """
476        return self._proxy.fetch()
477
478    def __repr__(self):
479        """
480        Provide a friendly representation
481
482        :returns: Machine friendly representation
483        :rtype: str
484        """
485        context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
486        return '<Twilio.Insights.V1.ParticipantInstance {}>'.format(context)
487