8000 Minor rekwarg, the framework no longer need kwarg expansion · rbachman/twilio-python@0a6418c · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a6418c

Browse files
author
matt
committed
Minor rekwarg, the framework no longer need kwarg expansion
1 parent e9b17f7 commit 0a6418c

File tree

88 files changed

+8385
-3705
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+8385
-3705
lines changed

twilio/rest/api/v2010/account/__init__.py

Lines changed: 143 additions & 93 deletions
Large diffs are not rendered by default.
Lines changed: 118 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from twilio.rest.base import InstanceContext
1313
from twilio.rest.base import InstanceResource
1414
from twilio.rest.base import ListResource
15+
from twilio.rest.page import Page
1516

1617

1718
class AddressList(ListResource):
@@ -29,10 +30,10 @@ def __init__(self, version, account_sid):
2930
super(AddressList, self).__init__(version)
3031

3132
# Path Solution
32-
self._kwargs = {
33+
self._solution = {
3334
'account_sid': account_sid,
3435
}
35-
self._uri = '/Accounts/{account_sid}/Addresses.json'.format(**self._kwargs)
36+
self._uri = '/Accounts/{account_sid}/Addresses.json'.format(**self._solution)
3637

3738
def create(self, customer_name, street, city, region, postal_code, iso_country,
3839
friendly_name=values.unset):
@@ -60,16 +61,20 @@ def create(self, customer_name, street, city, region, postal_code, iso_country,
6061
'FriendlyName': friendly_name,
6162
})
6263

63-
return self._version.create(
64-
AddressInstance,
65-
self._kwargs,
64+
payload = self._version.create(
6665
'POST',
6766
self._uri,
6867
data=data,
6968
)
69+
70+
return AddressInstance(
71+
self._version,
72+
payload,
73+
account_sid=self._solution['account_sid'],
74+
)
7075

7176
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):
7378
"""
7479
Streams AddressInstance records from the API as a generator stream.
7580
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,
9196
"""
9297
limits = self._version.read_limits(limit, page_size)
9398

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'],
111104
)
105+
106+
return self._version.stream(page, limits['limit'], limits['page_limit'])
112107

113108
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):
115110
"""
116111
Reads AddressInstance records from the API as a list.
117112
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,
136131
iso_country=iso_country,
137132
limit=limit,
138133
page_size=page_size,
139-
**kwargs
140134
))
141135

142136
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):
145139
"""
146140
Retrieve a single page of AddressInstance records from the API.
147141
Request is executed immediately
@@ -164,16 +158,18 @@ def page(self, customer_name=values.unset, friendly_name=values.unset,
164158
'Page': page_number,
165159
'PageSize': page_size,
166160
})
167-
params.update(kwargs)
168161

169-
return self._version.page(
170-
self,
171-
AddressInstance,
172-
self._kwargs,
162+
response = self._version.page(
173163
'GET',
174164
self._uri,
175165
params=params,
176166
)
167+
168+
return AddressPage(
169+
self._version,
170+
response,
171+
account_sid=self._solution['account_sid'],
172+
)
177173

178174
def get(self, sid):
179175
"""
@@ -184,7 +180,11 @@ def get(self, sid):
184180
:returns: AddressContext
185181
:rtype: AddressContext
186182
"""
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+
)
188188

189189
def __call__(self, sid):
190190
"""
@@ -195,7 +195,11 @@ def __call__(self, sid):
195195
:returns: AddressContext
196196
:rtype: AddressContext
197197
"""
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+
)
199203

200204
def __repr__(self):
201205
"""
@@ -207,13 +211,58 @@ def __repr__(self):
207211
return '<Twilio.Api.V2010.AddressList>'
208212

209213

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+
210259
class AddressContext(InstanceContext):
211260

212261
def __init__(self, version, account_sid, sid):
213262
"""
214263
Initialize the AddressContext
215264
216-
:param Version version
265+
:param Version version: Version that contains the resource
217266
:param account_sid: The account_sid
218267
:param sid: The sid
219268
@@ -223,11 +272,11 @@ def __init__(self, version, account_sid, sid):
223272
super(AddressContext, self).__init__(version)
224273

225274
# Path Solution
226-
self._kwargs = {
275+
self._solution = {
227276
'account_sid': account_sid,
228277
'sid': sid,
229278
}
230-
self._uri = '/Accounts/{account_sid}/Addresses/{sid}.json'.format(**self._kwargs)
279+
self._uri = '/Accounts/{account_sid}/Addresses/{sid}.json'.format(**self._solution)
231280

232281
# Dependents
233282
self._dependent_phone_numbers = None
@@ -250,13 +299,18 @@ def fetch(self):
250299
"""
251300
params = values.of({})
252301

253-
return self._version.fetch(
254-
AddressInstance,
255-
self._kwargs,
302+
payload = self._version.fetch(
256303
'GET',
257304
self._uri,
258305
params=params,
259306
)
307+
308+
return AddressInstance(
309+
self._version,
310+
payload,
311+
account_sid=self._solution['account_sid'],
312+
sid=self._solution['sid'],
313+
)
260314

261315
def update(self, friendly_name=values.unset, customer_name=values.unset,
262316
street=values.unset, city=values.unset, region=values.unset,
@@ -283,13 +337,18 @@ def update(self, friendly_name=values.unset, customer_name=values.unset,
283337
'PostalCode': postal_code,
284338
})
285339

286-
return self._version.update(
287-
AddressInstance,
288-
self._kwargs,
340+
payload = self._version.update(
289341
'POST',
290342
self._uri,
291343
data=data,
292344
)
345+
346+
return AddressInstance(
347+
self._version,
348+
payload,
349+
account_sid=self._solution['account_sid'],
350+
sid=self._solution['sid'],
351+
)
293352

294353
@property
295354
def dependent_phone_numbers(self):
@@ -302,8 +361,8 @@ def dependent_phone_numbers(self):
302361
if self._dependent_phone_numbers is None:
303362
self._dependent_phone_numbers = DependentPhoneNumberList(
304363
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'],
307366
)
308367
return self._dependent_phone_numbers
309368

@@ -314,7 +373,7 @@ def __repr__(self):
314373
:returns: Machine friendly representation
315374
:rtype: str
316375
"""
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())
318377
return '<Twilio.Api.V2010.AddressContext {}>'.format(context)
319378

320379

@@ -346,28 +405,28 @@ def __init__(self, version, payload, account_sid, sid=None):
346405
}
347406

348407
# Context
349-
self._instance_context = None
350-
self._kwargs = {
408+
self._context = None
409+
self._solution = {
351410
'account_sid': account_sid,
352411
'sid': sid or self._properties['sid'],
353412
}
354413

355414
@property
356-
def _context(self):
415+
def _proxy(self):
357416
"""
358417
Generate an instance context for the instance, the context is capable of
359418
performing various actions. All instance actions are proxied to the context
360419
361420
:returns: AddressContext for this AddressInstance
362421
:rtype: AddressContext
363422
"""
364-
if self._instance_context is None:
365-
self._instance_context = AddressContext(
423+
if self._context is None:
424+
self._context = AddressContext(
366425
self._version,
367-
self._kwargs['account_sid'],
368-
self._kwargs['sid'],
426+
account_sid=self._solution['account_sid'],
427+
sid=self._solution['sid'],
369428
)
370-
return self._instance_context
429+
return self._context
371430

372431
@property
373432
def account_sid(self):
@@ -472,7 +531,7 @@ def delete(self):
472531
:returns: True if delete succeeds, False otherwise
473532
:rtype: bool
474533
"""
475-
return self._context.delete()
534+
return self._proxy.delete()
476535

477536
def fetch(self):
478537
"""
@@ -481,7 +540,7 @@ def fetch(self):
481540
:returns: Fetched AddressInstance
482541
:rtype: AddressInstance
483542
"""
484-
return self._context.fetch()
543+
return self._proxy.fetch()
485544

486545
def update(self, friendly_name=values.unset, customer_name=values.unset,
487546
street=values.unset, city=values.unset, region=values.unset,
@@ -499,7 +558,7 @@ def update(self, friendly_name=values.unset, customer_name=values.unset,
499558
:returns: Updated AddressInstance
500559
:rtype: AddressInstance
501560
"""
502-
return self._context.update(
561+
return self._proxy.update(
503562
friendly_name=friendly_name,
504563
customer_name=customer_name,
505564
street=street,
@@ -516,7 +575,7 @@ def dependent_phone_numbers(self):
516575
:returns: dependent_phone_numbers
517576
:rtype: dependent_phone_numbers
518577
"""
519-
return self._context.dependent_phone_numbers
578+
return self._proxy.dependent_phone_numbers
520579

521580
def __repr__(self):
522581
"""
@@ -525,5 +584,5 @@ def __repr__(self):
525584
:returns: Machine friendly representation
526585
:rtype: str
527586
"""
528-
context = ' '.join('{}={}'.format(k, v) for k, v in self._kwargs.items())
587+
context = ' '.join('{}={}'.format(k, v) for k, v in self._solution.items())
529588
return '<Twilio.Api.V2010.AddressInstance {}>'.format(context)

0 commit comments

Comments
 (0)
0