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 CredentialListList(ListResource): 18 19 def __init__(self, version, trunk_sid): 20 """ 21 Initialize the CredentialListList 22 23 :param Version version: Version that contains the resource 24 :param trunk_sid: The SID of the Trunk the credential list in associated with 25 26 :returns: twilio.rest.trunking.v1.trunk.credential_list.CredentialListList 27 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListList 28 """ 29 super(CredentialListList, self).__init__(version) 30 31 # Path Solution 32 self._solution = {'trunk_sid': trunk_sid, } 33 self._uri = '/Trunks/{trunk_sid}/CredentialLists'.format(**self._solution) 34 35 def create(self, credential_list_sid): 36 """ 37 Create the CredentialListInstance 38 39 :param unicode credential_list_sid: The SID of the Credential List that you want to associate with the trunk 40 41 :returns: The created CredentialListInstance 42 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListInstance 43 """ 44 data = values.of({'CredentialListSid': credential_list_sid, }) 45 46 payload = self._version.create(method='POST', uri=self._uri, data=data, ) 47 48 return CredentialListInstance(self._version, payload, trunk_sid=self._solution['trunk_sid'], ) 49 50 def stream(self, limit=None, page_size=None): 51 """ 52 Streams CredentialListInstance records from the API as a generator stream. 53 This operation lazily loads records as efficiently as possible until the limit 54 is reached. 55 The results are returned as a generator, so this operation is memory efficient. 56 57 :param int limit: Upper limit for the number of records to return. stream() 58 guarantees to never return more than limit. Default is no limit 59 :param int page_size: Number of records to fetch per request, when not set will use 60 the default value of 50 records. If no page_size is defined 61 but a limit is defined, stream() will attempt to read the 62 limit with the most efficient page size, i.e. min(limit, 1000) 63 64 :returns: Generator that will yield up to limit results 65 :rtype: list[twilio.rest.trunking.v1.trunk.credential_list.CredentialListInstance] 66 """ 67 limits = self._version.read_limits(limit, page_size) 68 69 page = self.page(page_size=limits['page_size'], ) 70 71 return self._version.stream(page, limits['limit']) 72 73 def list(self, limit=None, page_size=None): 74 """ 75 Lists CredentialListInstance records from the API as a list. 76 Unlike stream(), this operation is eager and will load `limit` records into 77 memory before returning. 78 79 :param int limit: Upper limit for the number of records to return. list() guarantees 80 never to return more than limit. Default is no limit 81 :param int page_size: Number of records to fetch per request, when not set will use 82 the default value of 50 records. If no page_size is defined 83 but a limit is defined, list() will attempt to read the limit 84 with the most efficient page size, i.e. min(limit, 1000) 85 86 :returns: Generator that will yield up to limit results 87 :rtype: list[twilio.rest.trunking.v1.trunk.credential_list.CredentialListInstance] 88 """ 89 return list(self.stream(limit=limit, page_size=page_size, )) 90 91 def page(self, page_token=values.unset, page_number=values.unset, 92 page_size=values.unset): 93 """ 94 Retrieve a single page of CredentialListInstance records from the API. 95 Request is executed immediately 96 97 :param str page_token: PageToken provided by the API 98 :param int page_number: Page Number, this value is simply for client state 99 :param int page_size: Number of records to return, defaults to 50 100 101 :returns: Page of CredentialListInstance 102 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListPage 103 """ 104 data = values.of({'PageToken': page_token, 'Page': page_number, 'PageSize': page_size, }) 105 106 response = self._version.page(method='GET', uri=self._uri, params=data, ) 107 108 return CredentialListPage(self._version, response, self._solution) 109 110 def get_page(self, target_url): 111 """ 112 Retrieve a specific page of CredentialListInstance records from the API. 113 Request is executed immediately 114 115 :param str target_url: API-generated URL for the requested results page 116 117 :returns: Page of CredentialListInstance 118 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListPage 119 """ 120 response = self._version.domain.twilio.request( 121 'GET', 122 target_url, 123 ) 124 125 return CredentialListPage(self._version, response, self._solution) 126 127 def get(self, sid): 128 """ 129 Constructs a CredentialListContext 130 131 :param sid: The unique string that identifies the resource 132 133 :returns: twilio.rest.trunking.v1.trunk.credential_list.CredentialListContext 134 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListContext 135 """ 136 return CredentialListContext(self._version, trunk_sid=self._solution['trunk_sid'], sid=sid, ) 137 138 def __call__(self, sid): 139 """ 140 Constructs a CredentialListContext 141 142 :param sid: The unique string that identifies the resource 143 144 :returns: twilio.rest.trunking.v1.trunk.credential_list.CredentialListContext 145 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListContext 146 """ 147 return CredentialListContext(self._version, trunk_sid=self._solution['trunk_sid'], sid=sid, ) 148 149 def __repr__(self): 150 """ 151 Provide a friendly representation 152 153 :returns: Machine friendly representation 154 :rtype: str 155 """ 156 return '<Twilio.Trunking.V1.CredentialListList>' 157 158 159class CredentialListPage(Page): 160 161 def __init__(self, version, response, solution): 162 """ 163 Initialize the CredentialListPage 164 165 :param Version version: Version that contains the resource 166 :param Response response: Response from the API 167 :param trunk_sid: The SID of the Trunk the credential list in associated with 168 169 :returns: twilio.rest.trunking.v1.trunk.credential_list.CredentialListPage 170 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListPage 171 """ 172 super(CredentialListPage, self).__init__(version, response) 173 174 # Path Solution 175 self._solution = solution 176 177 def get_instance(self, payload): 178 """ 179 Build an instance of CredentialListInstance 180 181 :param dict payload: Payload response from the API 182 183 :returns: twilio.rest.trunking.v1.trunk.credential_list.CredentialListInstance 184 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListInstance 185 """ 186 return CredentialListInstance(self._version, payload, trunk_sid=self._solution['trunk_sid'], ) 187 188 def __repr__(self): 189 """ 190 Provide a friendly representation 191 192 :returns: Machine friendly representation 193 :rtype: str 194 """ 195 return '<Twilio.Trunking.V1.CredentialListPage>' 196 197 198class CredentialListContext(InstanceContext): 199 200 def __init__(self, version, trunk_sid, sid): 201 """ 202 Initialize the CredentialListContext 203 204 :param Version version: Version that contains the resource 205 :param trunk_sid: The SID of the Trunk from which to fetch the credential list 206 :param sid: The unique string that identifies the resource 207 208 :returns: twilio.rest.trunking.v1.trunk.credential_list.CredentialListContext 209 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListContext 210 """ 211 super(CredentialListContext, self).__init__(version) 212 213 # Path Solution 214 self._solution = {'trunk_sid': trunk_sid, 'sid': sid, } 215 self._uri = '/Trunks/{trunk_sid}/CredentialLists/{sid}'.format(**self._solution) 216 217 def fetch(self): 218 """ 219 Fetch the CredentialListInstance 220 221 :returns: The fetched CredentialListInstance 222 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListInstance 223 """ 224 payload = self._version.fetch(method='GET', uri=self._uri, ) 225 226 return CredentialListInstance( 227 self._version, 228 payload, 229 trunk_sid=self._solution['trunk_sid'], 230 sid=self._solution['sid'], 231 ) 232 233 def delete(self): 234 """ 235 Deletes the CredentialListInstance 236 237 :returns: True if delete succeeds, False otherwise 238 :rtype: bool 239 """ 240 return self._version.delete(method='DELETE', uri=self._uri, ) 241 242 def __repr__(self): 243 """ 244 Provide a friendly representation 245 246 :returns: Machine friendly representation 247 :rtype: str 248 """ 249 context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) 250 return '<Twilio.Trunking.V1.CredentialListContext {}>'.format(context) 251 252 253class CredentialListInstance(InstanceResource): 254 255 def __init__(self, version, payload, trunk_sid, sid=None): 256 """ 257 Initialize the CredentialListInstance 258 259 :returns: twilio.rest.trunking.v1.trunk.credential_list.CredentialListInstance 260 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListInstance 261 """ 262 super(CredentialListInstance, self).__init__(version) 263 264 # Marshaled Properties 265 self._properties = { 266 'account_sid': payload.get('account_sid'), 267 'sid': payload.get('sid'), 268 'trunk_sid': payload.get('trunk_sid'), 269 'friendly_name': payload.get('friendly_name'), 270 'date_created': deserialize.iso8601_datetime(payload.get('date_created')), 271 'date_updated': deserialize.iso8601_datetime(payload.get('date_updated')), 272 'url': payload.get('url'), 273 } 274 275 # Context 276 self._context = None 277 self._solution = {'trunk_sid': trunk_sid, 'sid': sid or self._properties['sid'], } 278 279 @property 280 def _proxy(self): 281 """ 282 Generate an instance context for the instance, the context is capable of 283 performing various actions. All instance actions are proxied to the context 284 285 :returns: CredentialListContext for this CredentialListInstance 286 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListContext 287 """ 288 if self._context is None: 289 self._context = CredentialListContext( 290 self._version, 291 trunk_sid=self._solution['trunk_sid'], 292 sid=self._solution['sid'], 293 ) 294 return self._context 295 296 @property 297 def account_sid(self): 298 """ 299 :returns: The SID of the Account that created the resource 300 :rtype: unicode 301 """ 302 return self._properties['account_sid'] 303 304 @property 305 def sid(self): 306 """ 307 :returns: The unique string that identifies the resource 308 :rtype: unicode 309 """ 310 return self._properties['sid'] 311 312 @property 313 def trunk_sid(self): 314 """ 315 :returns: The SID of the Trunk the credential list in associated with 316 :rtype: unicode 317 """ 318 return self._properties['trunk_sid'] 319 320 @property 321 def friendly_name(self): 322 """ 323 :returns: The string that you assigned to describe the resource 324 :rtype: unicode 325 """ 326 return self._properties['friendly_name'] 327 328 @property 329 def date_created(self): 330 """ 331 :returns: The RFC 2822 date and time in GMT when the resource was created 332 :rtype: datetime 333 """ 334 return self._properties['date_created'] 335 336 @property 337 def date_updated(self): 338 """ 339 :returns: The RFC 2822 date and time in GMT when the resource was last updated 340 :rtype: datetime 341 """ 342 return self._properties['date_updated'] 343 344 @property 345 def url(self): 346 """ 347 :returns: The absolute URL of the resource 348 :rtype: unicode 349 """ 350 return self._properties['url'] 351 352 def fetch(self): 353 """ 354 Fetch the CredentialListInstance 355 356 :returns: The fetched CredentialListInstance 357 :rtype: twilio.rest.trunking.v1.trunk.credential_list.CredentialListInstance 358 """ 359 return self._proxy.fetch() 360 361 def delete(self): 362 """ 363 Deletes the CredentialListInstance 364 365 :returns: True if delete succeeds, False otherwise 366 :rtype: bool 367 """ 368 return self._proxy.delete() 369 370 def __repr__(self): 371 """ 372 Provide a friendly representation 373 374 :returns: Machine friendly representation 375 :rtype: str 376 """ 377 context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items()) 378 return '<Twilio.Trunking.V1.CredentialListInstance {}>'.format(context) 379