1# coding=utf-8 2r""" 3This code was generated by 4\ / _ _ _| _ _ 5 | (_)\/(_)(_|\/| |(/_ v1.0.0 6 / / 7""" 8 9from twilio.base import values 10from twilio.base.instance_resource import InstanceResource 11from twilio.base.list_resource import ListResource 12from twilio.base.page import Page 13 14 15class EventList(ListResource): 16 """ PLEASE NOTE that this class contains preview products that are subject 17 to change. Use them with caution. If you currently do not have developer 18 preview access, please contact help@twilio.com. """ 19 20 def __init__(self, version, call_sid): 21 """ 22 Initialize the EventList 23 24 :param Version version: Version that contains the resource 25 :param call_sid: The call_sid 26 27 :returns: twilio.rest.insights.v1.call.event.EventList 28 :rtype: twilio.rest.insights.v1.call.event.EventList 29 """ 30 super(EventList, self).__init__(version) 31 32 # Path Solution 33 self._solution = {'call_sid': call_sid, } 34 self._uri = '/Voice/{call_sid}/Events'.format(**self._solution) 35 36 def stream(self, edge=values.unset, limit=None, page_size=None): 37 """ 38 Streams EventInstance records from the API as a generator stream. 39 This operation lazily loads records as efficiently as possible until the limit 40 is reached. 41 The results are returned as a generator, so this operation is memory efficient. 42 43 :param EventInstance.TwilioEdge edge: The edge 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.call.event.EventInstance] 53 """ 54 limits = self._version.read_limits(limit, page_size) 55 56 page = self.page(edge=edge, page_size=limits['page_size'], ) 57 58 return self._version.stream(page, limits['limit']) 59 60 def list(self, edge=values.unset, limit=None, page_size=None): 61 """ 62 Lists EventInstance 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 EventInstance.TwilioEdge edge: The edge 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.insights.v1.call.event.EventInstance] 76 """ 77 return list(self.stream(edge=edge, limit=limit, page_size=page_size, )) 78 79 def page(self, edge=values.unset, page_token=values.unset, 80 page_number=values.unset, page_size=values.unset): 81 """ 82 Retrieve a single page of EventInstance records from the API. 83 Request is executed immediately 84 85 :param EventInstance.TwilioEdge edge: The edge 86 :param str page_token: PageToken provided by the API 87 :param int page_number: Page Number, this value is simply for client state 88 :param int page_size: Number of records to return, defaults to 50 89 90 :returns: Page of EventInstance 91 :rtype: twilio.rest.insights.v1.call.event.EventPage 92 """ 93 data = values.of({ 94 'Edge': edge, 95 'PageToken': page_token, 96 'Page': page_number, 97 'PageSize': page_size, 98 }) 99 100 response = self._version.page(method='GET', uri=self._uri, params=data, ) 101 102 return EventPage(self._version, response, self._solution) 103 104 def get_page(self, target_url): 105 """ 106 Retrieve a specific page of EventInstance records from the API. 107 Request is executed immediately 108 109 :param str target_url: API-generated URL for the requested results page 110 111 :returns: Page of EventInstance 112 :rtype: twilio.rest.insights.v1.call.event.EventPage 113 """ 114 response = self._version.domain.twilio.request( 115 'GET', 116 target_url, 117 ) 118 119 return EventPage(self._version, response, self._solution) 120 121 def __repr__(self): 122 """ 123 Provide a friendly representation 124 125 :returns: Machine friendly representation 126 :rtype: str 127 """ 128 return '<Twilio.Insights.V1.EventList>' 129 130 131class EventPage(Page): 132 """ PLEASE NOTE that this class contains preview products that are subject 133 to change. Use them with caution. If you currently do not have developer 134 preview access, please contact help@twilio.com. """ 135 136 def __init__(self, version, response, solution): 137 """ 138 Initialize the EventPage 139 140 :param Version version: Version that contains the resource 141 :param Response response: Response from the API 142 :param call_sid: The call_sid 143 144 :returns: twilio.rest.insights.v1.call.event.EventPage 145 :rtype: twilio.rest.insights.v1.call.event.EventPage 146 """ 147 super(EventPage, self).__init__(version, response) 148 149 # Path Solution 150 self._solution = solution 151 152 def get_instance(self, payload): 153 """ 154 Build an instance of EventInstance 155 156 :param dict payload: Payload response from the API 157 158 :returns: twilio.rest.insights.v1.call.event.EventInstance 159 :rtype: twilio.rest.insights.v1.call.event.EventInstance 160 """ 161 return EventInstance(self._version, payload, call_sid=self._solution['call_sid'], ) 162 163 def __repr__(self): 164 """ 165 Provide a friendly representation 166 167 :returns: Machine friendly representation 168 :rtype: str 169 """ 170 return '<Twilio.Insights.V1.EventPage>' 171 172 173class EventInstance(InstanceResource): 174 """ PLEASE NOTE that this class contains preview products that are subject 175 to change. Use them with caution. If you currently do not have developer 176 preview access, please contact help@twilio.com. """ 177 178 class TwilioEdge(object): 179 UNKNOWN_EDGE = "unknown_edge" 180 CARRIER_EDGE = "carrier_edge" 181 SIP_EDGE = "sip_edge" 182 SDK_EDGE = "sdk_edge" 183 CLIENT_EDGE = "client_edge" 184 185 class Level(object): 186 UNKNOWN = "UNKNOWN" 187 DEBUG = "DEBUG" 188 INFO = "INFO" 189 WARNING = "WARNING" 190 ERROR = "ERROR" 191 192 def __init__(self, version, payload, call_sid): 193 """ 194 Initialize the EventInstance 195 196 :returns: twilio.rest.insights.v1.call.event.EventInstance 197 :rtype: twilio.rest.insights.v1.call.event.EventInstance 198 """ 199 super(EventInstance, self).__init__(version) 200 201 # Marshaled Properties 202 self._properties = { 203 'timestamp': payload.get('timestamp'), 204 'call_sid': payload.get('call_sid'), 205 'account_sid': payload.get('account_sid'), 206 'edge': payload.get('edge'), 207 'group': payload.get('group'), 208 'level': payload.get('level'), 209 'name': payload.get('name'), 210 'carrier_edge': payload.get('carrier_edge'), 211 'sip_edge': payload.get('sip_edge'), 212 'sdk_edge': payload.get('sdk_edge'), 213 'client_edge': payload.get('client_edge'), 214 } 215 216 # Context 217 self._context = None 218 self._solution = {'call_sid': call_sid, } 219 220 @property 221 def timestamp(self): 222 """ 223 :returns: The timestamp 224 :rtype: unicode 225 """ 226 return self._properties['timestamp'] 227 228 @property 229 def call_sid(self): 230 """ 231 :returns: The call_sid 232 :rtype: unicode 233 """ 234 return self._properties['call_sid'] 235 236 @property 237 def account_sid(self): 238 """ 239 :returns: The account_sid 240 :rtype: unicode 241 """ 242 return self._properties['account_sid'] 243 244 @property 245 def edge(self): 246 """ 247 :returns: The edge 248 :rtype: EventInstance.TwilioEdge 249 """ 250 return self._properties['edge'] 251 252 @property 253 def group(self): 254 """ 255 :returns: The group 256 :rtype: unicode 257 """ 258 return self._properties['group'] 259 260 @property 261 def level(self): 262 """ 263 :returns: The level 264 :rtype: EventInstance.Level 265 """ 266 return self._properties['level'] 267 268 @property 269 def name(self): 270 """ 271 :returns: The name 272 :rtype: unicode 273 """ 274 return self._properties['name'] 275 276 @property 277 def carrier_edge(self): 278 """ 279 :returns: The carrier_edge 280 :rtype: dict 281 """ 282 return self._properties['carrier_edge'] 283 284 @property 285 def sip_edge(self): 286 """ 287 :returns: The sip_edge 288 :rtype: dict 289 """ 290 return self._properties['sip_edge'] 291 292 @property 293 def sdk_edge(self): 294 """ 295 :returns: The sdk_edge 296 :rtype: dict 297 """ 298 return self._properties['sdk_edge'] 299 300 @property 301 def client_edge(self): 302 """ 303 :returns: The client_edge 304 :rtype: dict 305 """ 306 return self._properties['client_edge'] 307 308 def __repr__(self): 309 """ 310 Provide a friendly representation 311 312 :returns: Machine friendly representation 313 :rtype: str 314 """ 315 return '<Twilio.Insights.V1.EventInstance>' 316