12
12
from twilio .rest .base import InstanceContext
13
13
from twilio .rest .base import InstanceResource
14
14
from twilio .rest .base import ListResource
15
+ from twilio .rest .page import Page
15
16
16
17
17
18
class AddressList (ListResource ):
@@ -29,10 +30,10 @@ def __init__(self, version, account_sid):
29
30
super (AddressList , self ).__init__ (version )
30
31
31
32
# Path Solution
32
- self ._kwargs = {
33
+ self ._solution = {
33
34
'account_sid' : account_sid ,
34
35
}
35
- self ._uri = '/Accounts/{account_sid}/Addresses.json' .format (** self ._kwargs )
36
+ self ._uri = '/Accounts/{account_sid}/Addresses.json' .format (** self ._solution )
36
37
37
38
def create (self , customer_name , street , city , region , postal_code , iso_country ,
38
39
friendly_name = values .unset ):
@@ -60,16 +61,20 @@ def create(self, customer_name, street, city, region, postal_code, iso_country,
60
61
'FriendlyName' : friendly_name ,
61
62
})
62
63
63
- return self ._version .create (
64
- AddressInstance ,
65
- self ._kwargs ,
64
+ payload = self ._version .create (
66
65
'POST' ,
67
66
self ._uri ,
68
67
data = data ,
69
68
)
69
+
70
+ return AddressInstance (
71
+ self ._version ,
72
+ payload ,
73
+ account_sid = self ._solution ['account_sid' ],
74
+ )
70
75
71
76
def stream (self , customer_name = values .unset , friendly_name = values .unset ,
72
- iso_country = values .unset , limit = None , page_size = None , ** kwargs ):
77
+ iso_country = values .unset , limit = None , page_size = None ):
73
78
"""
74
79
Streams AddressInstance records from the API as a generator stream.
75
80
This operation lazily loads records as efficiently as possible until the limit
@@ -91,27 +96,17 @@ def stream(self, customer_name=values.unset, friendly_name=values.unset,
91
96
"""
92
97
limits = self ._version .read_limits (limit , page_size )
93
98
94
- params = values .of ({
95
- 'CustomerName' : customer_name ,
96
- 'FriendlyName' : friendly_name ,
97
- 'IsoCountry' : iso_country ,
98
- 'PageSize' : limits ['page_size' ],
99
- })
100
- params .update (kwargs )
101
-
102
- return self ._version .stream (
103
- self ,
104
- AddressInstance ,
105
- self ._kwargs ,
106
- 'GET' ,
107
- self ._uri ,
108
- limits ['limit' ],
109
- limits ['page_limit' ],
110
- params = params ,
99
+ page = self .page (
100
+ customer_name = customer_name ,
101
+ friendly_name = friendly_name ,
102
+ iso_country = iso_country ,
103
+ page_size = limits ['page_size' ],
111
104
)
105
+
106
+ return self ._version .stream (page , limits ['limit' ], limits ['page_limit' ])
112
107
113
108
def read (self , customer_name = values .unset , friendly_name = values .unset ,
114
- iso_country = values .unset , limit = None , page_size = None , ** kwargs ):
109
+ iso_country = values .unset , limit = None , page_size = values . unset ):
115
110
"""
116
111
Reads AddressInstance records from the API as a list.
117
112
Unlike stream(), this operation is eager and will load `limit` records into
@@ -136,12 +131,11 @@ def read(self, customer_name=values.unset, friendly_name=values.unset,
136
131
iso_country = iso_country ,
137
132
limit = limit ,
138
133
page_size = page_size ,
139
- ** kwargs
140
134
))
141
135
142
136
def page (self , customer_name = values .unset , friendly_name = values .unset ,
143
- iso_country = values .unset , page_token = None , page_number = None ,
144
- page_size = None , ** kwargs ):
137
+ iso_country = values .unset , page_token = values . unset ,
138
+ page_number = values . unset , page_size = values . unset ):
145
139
"""
146
140
Retrieve a single page of AddressInstance records from the API.
147
141
Request is executed immediately
@@ -164,16 +158,18 @@ def page(self, customer_name=values.unset, friendly_name=values.unset,
164
158
'Page' : page_number ,
165
159
'PageSize' : page_size ,
166
160
})
167
- params .update (kwargs )
168
161
169
- return self ._version .page (
170
- self ,
171
- AddressInstance ,
172
- self ._kwargs ,
162
+ response = self ._version .page (
173
163
'GET' ,
174
164
self ._uri ,
175
165
params = params ,
176
166
)
167
+
168
+ return AddressPage (
169
+ self ._version ,
170
+ response ,
171
+ account_sid = self ._solution ['account_sid' ],
172
+ )
177
173
178
174
def get (self , sid ):
179
175
"""
@@ -184,7 +180,11 @@ def get(self, sid):
184
180
:returns: AddressContext
185
181
:rtype: AddressContext
186
182
"""
187
- return AddressContext (self ._version , sid = sid , ** self ._kwargs )
183
+ return AddressContext (
184
+ self ._version ,
185
+ account_sid = self ._solution ['account_sid' ],
186
+ sid = sid ,
187
+ )
188
188
189
189
def __call__ (self , sid ):
190
190
"""
@@ -195,7 +195,11 @@ def __call__(self, sid):
195
195
:returns: AddressContext
196
196
:rtype: AddressContext
197
197
"""
198
- return AddressContext (self ._version , sid = sid , ** self ._kwargs )
198
+ return AddressContext (
199
+ self ._version ,
200
+ account_sid = self ._solution ['account_sid' ],
201
+ sid = sid ,
202
+ )
199
203
200
204
def __repr__ (self ):
201
205
"""
@@ -207,13 +211,58 @@ def __repr__(self):
207
211
return '<Twilio.Api.V2010.AddressList>'
208
212
209
213
214
+ class AddressPage (Page ):
215
+
216
+ def __init__ (self , version , response , account_sid ):
217
+ """
218
+ Initialize the AddressPage
219
+
220
+ :param Version version: Version that contains the resource
221
+ :param Response response: Response from the API
222
+ :param account_sid: The account_sid
223
+
224
+ :returns: AddressPage
225
+ :rtype: AddressPage
226
+ """
227
+ super (AddressPage , self ).__init__ (version , response )
228
+
229
+ # Path Solution
230
+ self ._solution = {
231
+ 'account_sid' : account_sid ,
232
+ }
233
+
234
+ def get_instance (self , payload ):
235
+ """
236
+ Build an instance of AddressInstance
237
+
238
+ :param dict payload: Payload response from the API
239
+
240
+ :returns: AddressInstance
241
+ :rtype: AddressInstance
242
+ """
243
+ return AddressInstance (
244
+ self ._version ,
245
+ payload ,
246
+ account_sid = self ._solution ['account_sid' ],
247
+ )
248
+
249
+ def __repr__ (self ):
250
+ """
251
+ Provide a friendly representation
252
+
253
+ :returns: Machine friendly representation
254
+ :rtype: str
255
+ """
256
+ return '<Twilio.Api.V2010.AddressPage>'
257
+
258
+
210
259
class AddressContext (InstanceContext ):
211
260
212
261
def __init__ (self , version , account_sid , sid ):
213
262
"""
214
263
Initialize the AddressContext
215
264
216
- :param Version version
265
+ :param Version version: Version that contains the resource
217
266
:param account_sid: The account_sid
218
267
:param sid: The sid
219
268
@@ -223,11 +272,11 @@ def __init__(self, version, account_sid, sid):
223
272
super (AddressContext , self ).__init__ (version )
224
273
225
274
# Path Solution
226
- self ._kwargs = {
275
+ self ._solution = {
227
276
'account_sid' : account_sid ,
228
277
'sid' : sid ,
229
278
}
230
- self ._uri = '/Accounts/{account_sid}/Addresses/{sid}.json' .format (** self ._kwargs )
279
+ self ._uri = '/Accounts/{account_sid}/Addresses/{sid}.json' .format (** self ._solution )
231
280
232
281
# Dependents
233
282
self ._dependent_phone_numbers = None
@@ -250,13 +299,18 @@ def fetch(self):
250
299
"""
251
300
params = values .of ({})
252
301
253
- return self ._version .fetch (
254
- AddressInstance ,
255
- self ._kwargs ,
302
+ payload = self ._version .fetch (
256
303
'GET' ,
257
304
self ._uri ,
258
305
params = params ,
259
306
)
307
+
308
+ return AddressInstance (
309
+ self ._version ,
310
+ payload ,
311
+ account_sid = self ._solution ['account_sid' ],
312
+ sid = self ._solution ['sid' ],
313
+ )
260
314
261
315
def update (self , friendly_name = values .unset , customer_name = values .unset ,
262
316
street = values .unset , city = values .unset , region = values .unset ,
@@ -283,13 +337,18 @@ def update(self, friendly_name=values.unset, customer_name=values.unset,
283
337
'PostalCode' : postal_code ,
284
338
})
285
339
286
- return self ._version .update (
287
- AddressInstance ,
288
- self ._kwargs ,
340
+ payload = self ._version .update (
289
341
'POST' ,
290
342
self ._uri ,
291
343
data = data ,
292
344
)
345
+
346
+ return AddressInstance (
347
+ self ._version ,
348
+ payload ,
349
+ account_sid = self ._solution ['account_sid' ],
350
+ sid = self ._solution ['sid' ],
351
+ )
293
352
294
353
@property
295
354
def dependent_phone_numbers (self ):
@@ -302,8 +361,8 @@ def dependent_phone_numbers(self):
302
361
if self ._dependent_phone_numbers is None :
303
362
self ._dependent_phone_numbers = DependentPhoneNumberList (
304
363
self ._version ,
305
- account_sid = self ._kwargs ['account_sid' ],
306
- address_sid = self ._kwargs ['sid' ],
364
+ account_sid = self ._solution ['account_sid' ],
365
+ address_sid = self ._solution ['sid' ],
307
366
)
308
367
return self ._dependent_phone_numbers
309
368
@@ -314,7 +373,7 @@ def __repr__(self):
314
373
:returns: Machine friendly representation
315
374
:rtype: str
316
375
"""
317
- context = ' ' .join ('{}={}' .format (k , v ) for k , v in self ._kwargs .items ())
376
+ context = ' ' .join ('{}={}' .format (k , v ) for k , v in self ._solution .items ())
318
377
return '<Twilio.Api.V2010.AddressContext {}>' .format (context )
319
378
320
379
@@ -346,28 +405,28 @@ def __init__(self, version, payload, account_sid, sid=None):
346
405
}
347
406
348
407
# Context
349
- self ._instance_context = None
350
- self ._kwargs = {
408
+ self ._context = None
409
+ self ._solution = {
351
410
'account_sid' : account_sid ,
352
411
'sid' : sid or self ._properties ['sid' ],
353
412
}
354
413
355
414
@property
356
- def _context (self ):
415
+ def _proxy (self ):
357
416
"""
358
417
Generate an instance context for the instance, the context is capable of
359
418
performing various actions. All instance actions are proxied to the context
360
419
361
420
:returns: AddressContext for this AddressInstance
362
421
:rtype: AddressContext
363
422
"""
364
- if self ._instance_context is None :
365
- self ._instance_context = AddressContext (
423
+ if self ._context is None :
424
+ self ._context = AddressContext (
366
425
self ._version ,
367
- self ._kwargs ['account_sid' ],
368
- self ._kwargs ['sid' ],
426
+ account_sid = self ._solution ['account_sid' ],
427
+ sid = self ._solution ['sid' ],
369
428
)
370
- return self ._instance_context
429
+ return self ._context
371
430
372
431
@property
373
432
def account_sid (self ):
@@ -472,7 +531,7 @@ def delete(self):
472
531
:returns: True if delete succeeds, False otherwise
473
532
:rtype: bool
474
533
"""
475
- return self ._context .delete ()
534
+ return self ._proxy .delete ()
476
535
477
536
def fetch (self ):
478
537
"""
@@ -481,7 +540,7 @@ def fetch(self):
481
540
:returns: Fetched AddressInstance
482
541
:rtype: AddressInstance
483
542
"""
484
- return self ._context .fetch ()
543
+ return self ._proxy .fetch ()
485
544
486
545
def update (self , friendly_name = values .unset , customer_name = values .unset ,
487
546
street = values .unset , city = values .unset , region = values .unset ,
@@ -499,7 +558,7 @@ def update(self, friendly_name=values.unset, customer_name=values.unset,
499
558
:returns: Updated AddressInstance
500
559
:rtype: AddressInstance
501
560
"""
502
- return self ._context .update (
561
+ return self ._proxy .update (
503
562
friendly_name = friendly_name ,
504
563
customer_name = customer_name ,
505
564
street = street ,
@@ -516,7 +575,7 @@ def dependent_phone_numbers(self):
516
575
:returns: dependent_phone_numbers
517
576
:rtype: dependent_phone_numbers
518
577
"""
519
- return self ._context .dependent_phone_numbers
578
+ return self ._proxy .dependent_phone_numbers
520
579
521
580
def __repr__ (self ):
522
581
"""
@@ -525,5 +584,5 @@ def __repr__(self):
525
584
:returns: Machine friendly representation
526
585
:rtype: str
527
586
"""
528
- context = ' ' .join ('{}={}' .format (k , v ) for k , v in self ._kwargs .items ())
587
+ context =
38E0
span> ' ' .join ('{}={}' .format (k , v ) for k , v in self ._solution .items ())
529
588
return '<Twilio.Api.V2010.AddressInstance {}>' .format (context )
0 commit comments