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 CallSummariesList(ListResource): 17 18 def __init__(self, version): 19 """ 20 Initialize the CallSummariesList 21 22 :param Version version: Version that contains the resource 23 24 :returns: twilio.rest.insights.v1.call_summaries.CallSummariesList 25 :rtype: twilio.rest.insights.v1.call_summaries.CallSummariesList 26 """ 27 super(CallSummariesList, self).__init__(version) 28 29 # Path Solution 30 self._solution = {} 31 self._uri = '/Voice/Summaries'.format(**self._solution) 32 33 def stream(self, from_=values.unset, to=values.unset, from_carrier=values.unset, 34 to_carrier=values.unset, from_country_code=values.unset, 35 to_country_code=values.unset, branded=values.unset, 36 verified_caller=values.unset, has_tag=values.unset, 37 start_time=values.unset, end_time=values.unset, 38 call_type=values.unset, call_state=values.unset, 39 direction=values.unset, processing_state=values.unset, 40 sort_by=values.unset, subaccount=values.unset, 41 abnormal_session=values.unset, limit=None, page_size=None): 42 """ 43 Streams CallSummariesInstance records from the API as a generator stream. 44 This operation lazily loads records as efficiently as possible until the limit 45 is reached. 46 The results are returned as a generator, so this operation is memory efficient. 47 48 :param unicode from_: The from 49 :param unicode to: The to 50 :param unicode from_carrier: The from_carrier 51 :param unicode to_carrier: The to_carrier 52 :param unicode from_country_code: The from_country_code 53 :param unicode to_country_code: The to_country_code 54 :param bool branded: The branded 55 :param bool verified_caller: The verified_caller 56 :param bool has_tag: The has_tag 57 :param unicode start_time: The start_time 58 :param unicode end_time: The end_time 59 :param unicode call_type: The call_type 60 :param unicode call_state: The call_state 61 :param unicode direction: The direction 62 :param CallSummariesInstance.ProcessingStateRequest processing_state: The processing_state 63 :param CallSummariesInstance.SortBy sort_by: The sort_by 64 :param unicode subaccount: The subaccount 65 :param bool abnormal_session: The abnormal_session 66 :param int limit: Upper limit for the number of records to return. stream() 67 guarantees to never 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, stream() will attempt to read the 71 limit 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.call_summaries.CallSummariesInstance] 75 """ 76 limits = self._version.read_limits(limit, page_size) 77 78 page = self.page( 79 from_=from_, 80 to=to, 81 from_carrier=from_carrier, 82 to_carrier=to_carrier, 83 from_country_code=from_country_code, 84 to_country_code=to_country_code, 85 branded=branded, 86 verified_caller=verified_caller, 87 has_tag=has_tag, 88 start_time=start_time, 89 end_time=end_time, 90 call_type=call_type, 91 call_state=call_state, 92 direction=direction, 93 processing_state=processing_state, 94 sort_by=sort_by, 95 subaccount=subaccount, 96 abnormal_session=abnormal_session, 97 page_size=limits['page_size'], 98 ) 99 100 return self._version.stream(page, limits['limit']) 101 102 def list(self, from_=values.unset, to=values.unset, from_carrier=values.unset, 103 to_carrier=values.unset, from_country_code=values.unset, 104 to_country_code=values.unset, branded=values.unset, 105 verified_caller=values.unset, has_tag=values.unset, 106 start_time=values.unset, end_time=values.unset, call_type=values.unset, 107 call_state=values.unset, direction=values.unset, 108 processing_state=values.unset, sort_by=values.unset, 109 subaccount=values.unset, abnormal_session=values.unset, limit=None, 110 page_size=None): 111 """ 112 Lists CallSummariesInstance records from the API as a list. 113 Unlike stream(), this operation is eager and will load `limit` records into 114 memory before returning. 115 116 :param unicode from_: The from 117 :param unicode to: The to 118 :param unicode from_carrier: The from_carrier 119 :param unicode to_carrier: The to_carrier 120 :param unicode from_country_code: The from_country_code 121 :param unicode to_country_code: The to_country_code 122 :param bool branded: The branded 123 :param bool verified_caller: The verified_caller 124 :param bool has_tag: The has_tag 125 :param unicode start_time: The start_time 126 :param unicode end_time: The end_time 127 :param unicode call_type: The call_type 128 :param unicode call_state: The call_state 129 :param unicode direction: The direction 130 :param CallSummariesInstance.ProcessingStateRequest processing_state: The processing_state 131 :param CallSummariesInstance.SortBy sort_by: The sort_by 132 :param unicode subaccount: The subaccount 133 :param bool abnormal_session: The abnormal_session 134 :param int limit: Upper limit for the number of records to return. list() guarantees 135 never to return more than limit. Default is no limit 136 :param int page_size: Number of records to fetch per request, when not set will use 137 the default value of 50 records. If no page_size is defined 138 but a limit is defined, list() will attempt to read the limit 139 with the most efficient page size, i.e. min(limit, 1000) 140 141 :returns: Generator that will yield up to limit results 142 :rtype: list[twilio.rest.insights.v1.call_summaries.CallSummariesInstance] 143 """ 144 return list(self.stream( 145 from_=from_, 146 to=to, 147 from_carrier=from_carrier, 148 to_carrier=to_carrier, 149 from_country_code=from_country_code, 150 to_country_code=to_country_code, 151 branded=branded, 152 verified_caller=verified_caller, 153 has_tag=has_tag, 154 start_time=start_time, 155 end_time=end_time, 156 call_type=call_type, 157 call_state=call_state, 158 direction=direction, 159 processing_state=processing_state, 160 sort_by=sort_by, 161 subaccount=subaccount, 162 abnormal_session=abnormal_session, 163 limit=limit, 164 page_size=page_size, 165 )) 166 167 def page(self, from_=values.unset, to=values.unset, from_carrier=values.unset, 168 to_carrier=values.unset, from_country_code=values.unset, 169 to_country_code=values.unset, branded=values.unset, 170 verified_caller=values.unset, has_tag=values.unset, 171 start_time=values.unset, end_time=values.unset, call_type=values.unset, 172 call_state=values.unset, direction=values.unset, 173 processing_state=values.unset, sort_by=values.unset, 174 subaccount=values.unset, abnormal_session=values.unset, 175 page_token=values.unset, page_number=values.unset, 176 page_size=values.unset): 177 """ 178 Retrieve a single page of CallSummariesInstance records from the API. 179 Request is executed immediately 180 181 :param unicode from_: The from 182 :param unicode to: The to 183 :param unicode from_carrier: The from_carrier 184 :param unicode to_carrier: The to_carrier 185 :param unicode from_country_code: The from_country_code 186 :param unicode to_country_code: The to_country_code 187 :param bool branded: The branded 188 :param bool verified_caller: The verified_caller 189 :param bool has_tag: The has_tag 190 :param unicode start_time: The start_time 191 :param unicode end_time: The end_time 192 :param unicode call_type: The call_type 193 :param unicode call_state: The call_state 194 :param unicode direction: The direction 195 :param CallSummariesInstance.ProcessingStateRequest processing_state: The processing_state 196 :param CallSummariesInstance.SortBy sort_by: The sort_by 197 :param unicode subaccount: The subaccount 198 :param bool abnormal_session: The abnormal_session 199 :param str page_token: PageToken provided by the API 200 :param int page_number: Page Number, this value is simply for client state 201 :param int page_size: Number of records to return, defaults to 50 202 203 :returns: Page of CallSummariesInstance 204 :rtype: twilio.rest.insights.v1.call_summaries.CallSummariesPage 205 """ 206 data = values.of({ 207 'From': from_, 208 'To': to, 209 'FromCarrier': from_carrier, 210 'ToCarrier': to_carrier, 211 'FromCountryCode': from_country_code, 212 'ToCountryCode': to_country_code, 213 'Branded': branded, 214 'VerifiedCaller': verified_caller, 215 'HasTag': has_tag, 216 'StartTime': start_time, 217 'EndTime': end_time, 218 'CallType': call_type, 219 'CallState': call_state, 220 'Direction': direction, 221 'ProcessingState': processing_state, 222 'SortBy': sort_by, 223 'Subaccount': subaccount, 224 'AbnormalSession': abnormal_session, 225 'PageToken': page_token, 226 'Page': page_number, 227 'PageSize': page_size, 228 }) 229 230 response = self._version.page(method='GET', uri=self._uri, params=data, ) 231 232 return CallSummariesPage(self._version, response, self._solution) 233 234 def get_page(self, target_url): 235 """ 236 Retrieve a specific page of CallSummariesInstance records from the API. 237 Request is executed immediately 238 239 :param str target_url: API-generated URL for the requested results page 240 241 :returns: Page of CallSummariesInstance 242 :rtype: twilio.rest.insights.v1.call_summaries.CallSummariesPage 243 """ 244 response = self._version.domain.twilio.request( 245 'GET', 246 target_url, 247 ) 248 249 return CallSummariesPage(self._version, response, self._solution) 250 251 def __repr__(self): 252 """ 253 Provide a friendly representation 254 255 :returns: Machine friendly representation 256 :rtype: str 257 """ 258 return '<Twilio.Insights.V1.CallSummariesList>' 259 260 261class CallSummariesPage(Page): 262 263 def __init__(self, version, response, solution): 264 """ 265 Initialize the CallSummariesPage 266 267 :param Version version: Version that contains the resource 268 :param Response response: Response from the API 269 270 :returns: twilio.rest.insights.v1.call_summaries.CallSummariesPage 271 :rtype: twilio.rest.insights.v1.call_summaries.CallSummariesPage 272 """ 273 super(CallSummariesPage, self).__init__(version, response) 274 275 # Path Solution 276 self._solution = solution 277 278 def get_instance(self, payload): 279 """ 280 Build an instance of CallSummariesInstance 281 282 :param dict payload: Payload response from the API 283 284 :returns: twilio.rest.insights.v1.call_summaries.CallSummariesInstance 285 :rtype: twilio.rest.insights.v1.call_summaries.CallSummariesInstance 286 """ 287 return CallSummariesInstance(self._version, payload, ) 288 289 def __repr__(self): 290 """ 291 Provide a friendly representation 292 293 :returns: Machine friendly representation 294 :rtype: str 295 """ 296 return '<Twilio.Insights.V1.CallSummariesPage>' 297 298 299class CallSummariesInstance(InstanceResource): 300 301 class CallType(object): 302 CARRIER = "carrier" 303 SIP = "sip" 304 TRUNKING = "trunking" 305 CLIENT = "client" 306 307 class CallState(object): 308 RINGING = "ringing" 309 COMPLETED = "completed" 310 BUSY = "busy" 311 FAIL = "fail" 312 NOANSWER = "noanswer" 313 CANCELED = "canceled" 314 ANSWERED = "answered" 315 UNDIALED = "undialed" 316 317 class ProcessingState(object): 318 COMPLETE = "complete" 319 PARTIAL = "partial" 320 321 class CallDirection(object): 322 OUTBOUND_API = "outbound_api" 323 OUTBOUND_DIAL = "outbound_dial" 324 INBOUND = "inbound" 325 TRUNKING_ORIGINATING = "trunking_originating" 326 TRUNKING_TERMINATING = "trunking_terminating" 327 328 class SortBy(object): 329 START_TIME = "start_time" 330 END_TIME = "end_time" 331 332 class ProcessingStateRequest(object): 333 COMPLETED = "completed" 334 STARTED = "started" 335 PARTIAL = "partial" 336 ALL = "all" 337 338 def __init__(self, version, payload): 339 """ 340 Initialize the CallSummariesInstance 341 342 :returns: twilio.rest.insights.v1.call_summaries.CallSummariesInstance 343 :rtype: twilio.rest.insights.v1.call_summaries.CallSummariesInstance 344 """ 345 super(CallSummariesInstance, self).__init__(version) 346 347 # Marshaled Properties 348 self._properties = { 349 'account_sid': payload.get('account_sid'), 350 'call_sid': payload.get('call_sid'), 351 'call_type': payload.get('call_type'), 352 'call_state': payload.get('call_state'), 353 'processing_state': payload.get('processing_state'), 354 'created_time': deserialize.iso8601_datetime(payload.get('created_time')), 355 'start_time': deserialize.iso8601_datetime(payload.get('start_time')), 356 'end_time': deserialize.iso8601_datetime(payload.get('end_time')), 357 'duration': deserialize.integer(payload.get('duration')), 358 'connect_duration': deserialize.integer(payload.get('connect_duration')), 359 'from_': payload.get('from'), 360 'to': payload.get('to'), 361 'carrier_edge': payload.get('carrier_edge'), 362 'client_edge': payload.get('client_edge'), 363 'sdk_edge': payload.get('sdk_edge'), 364 'sip_edge': payload.get('sip_edge'), 365 'tags': payload.get('tags'), 366 'url': payload.get('url'), 367 'attributes': payload.get('attributes'), 368 'properties': payload.get('properties'), 369 'trust': payload.get('trust'), 370 } 371 372 # Context 373 self._context = None 374 self._solution = {} 375 376 @property 377 def account_sid(self): 378 """ 379 :returns: The account_sid 380 :rtype: unicode 381 """ 382 return self._properties['account_sid'] 383 384 @property 385 def call_sid(self): 386 """ 387 :returns: The call_sid 388 :rtype: unicode 389 """ 390 return self._properties['call_sid'] 391 392 @property 393 def call_type(self): 394 """ 395 :returns: The call_type 396 :rtype: CallSummariesInstance.CallType 397 """ 398 return self._properties['call_type'] 399 400 @property 401 def call_state(self): 402 """ 403 :returns: The call_state 404 :rtype: CallSummariesInstance.CallState 405 """ 406 return self._properties['call_state'] 407 408 @property 409 def processing_state(self): 410 """ 411 :returns: The processing_state 412 :rtype: CallSummariesInstance.ProcessingState 413 """ 414 return self._properties['processing_state'] 415 416 @property 417 def created_time(self): 418 """ 419 :returns: The created_time 420 :rtype: datetime 421 """ 422 return self._properties['created_time'] 423 424 @property 425 def start_time(self): 426 """ 427 :returns: The start_time 428 :rtype: datetime 429 """ 430 return self._properties['start_time'] 431 432 @property 433 def end_time(self): 434 """ 435 :returns: The end_time 436 :rtype: datetime 437 """ 438 return self._properties['end_time'] 439 440 @property 441 def duration(self): 442 """ 443 :returns: The duration 444 :rtype: unicode 445 """ 446 return self._properties['duration'] 447 448 @property 449 def connect_duration(self): 450 """ 451 :returns: The connect_duration 452 :rtype: unicode 453 """ 454 return self._properties['connect_duration'] 455 456 @property 457 def from_(self): 458 """ 459 :returns: The from 460 :rtype: dict 461 """ 462 return self._properties['from_'] 463 464 @property 465 def to(self): 466 """ 467 :returns: The to 468 :rtype: dict 469 """ 470 return self._properties['to'] 471 472 @property 473 def carrier_edge(self): 474 """ 475 :returns: The carrier_edge 476 :rtype: dict 477 """ 478 return self._properties['carrier_edge'] 479 480 @property 481 def client_edge(self): 482 """ 483 :returns: The client_edge 484 :rtype: dict 485 """ 486 return self._properties['client_edge'] 487 488 @property 489 def sdk_edge(self): 490 """ 491 :returns: The sdk_edge 492 :rtype: dict 493 """ 494 return self._properties['sdk_edge'] 495 496 @property 497 def sip_edge(self): 498 """ 499 :returns: The sip_edge 500 :rtype: dict 501 """ 502 return self._properties['sip_edge'] 503 504 @property 505 def tags(self): 506 """ 507 :returns: The tags 508 :rtype: list[unicode] 509 """ 510 return self._properties['tags'] 511 512 @property 513 def url(self): 514 """ 515 :returns: The url 516 :rtype: unicode 517 """ 518 return self._properties['url'] 519 520 @property 521 def attributes(self): 522 """ 523 :returns: The attributes 524 :rtype: dict 525 """ 526 return self._properties['attributes'] 527 528 @property 529 def properties(self): 530 """ 531 :returns: The properties 532 :rtype: dict 533 """ 534 return self._properties['properties'] 535 536 @property 537 def trust(self): 538 """ 539 :returns: The trust 540 :rtype: dict 541 """ 542 return self._properties['trust'] 543 544 def __repr__(self): 545 """ 546 Provide a friendly representation 547 548 :returns: Machine friendly representation 549 :rtype: str 550 """ 551 return '<Twilio.Insights.V1.CallSummariesInstance>' 552