Skip to content
43 changes: 34 additions & 9 deletions src/main/resources/twilio-python/listOperations.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -598,8 +598,20 @@
items = [record async for record in generator]
return ApiResponse(data=items, status_code=status_code, headers=headers)

def page(self, {{#allParams}}
{{#startsWith paramName text='page_size'}}{{else}}{{#startsWith paramName text='page_token'}}{{else}}{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/startsWith}}{{/startsWith}}{{/allParams}}
def page(self, {{#isApiV1}}{{#allParams}}
{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/allParams}}
) -> {{apiName}}Page:
"""
Retrieve a single page of {{instanceName}} records from the API.
Request is executed immediately
{{#allParams}}
:param {{paramName}}: {{{description}}}{{/allParams}}
:returns: Page of {{instanceName}}
"""
data = values.of({ {{#allParams}}
'{{{baseName}}}': {{#if vendorExtensions.x-serialize}}{{vendorExtensions.x-serialize}}({{paramName}}{{#if isArray}}, lambda e: e){{else}}){{/if}}{{else}}{{paramName}}{{/if}},{{/allParams}}
}){{/isApiV1}}{{^isApiV1}}{{#allParams}}
{{#startsWith paramName text='page_size'}}{{else}}{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/startsWith}}{{/allParams}}
page_token: Union[str, object] = values.unset,
page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
Expand All @@ -620,7 +632,7 @@
'PageToken': page_token,
'Page': page_number,
'PageSize': page_size,
})
}){{/isApiV1}}

headers = values.of({
{{#headerParams}}'{{{baseName}}}': {{paramName}},
Expand All @@ -634,11 +646,23 @@
{{/vendorExtensions.successProduce}}

response = self._version.page(method='{{vendorExtensions.x-http-method}}', uri=self._uri, params=data, headers=headers){{#isApiV1}}
return {{apiName}}Page(self._version, response, uri=self._uri{{#if listPathParams}}, self._solution{{/if}}){{/isApiV1}}{{^isApiV1}}
return {{apiName}}Page(self._version, response, uri=self._uri, params=data{{#if listPathParams}}, self._solution{{/if}}){{/isApiV1}}{{^isApiV1}}
return {{apiName}}Page(self._version, response{{#if listPathParams}}, self._solution{{/if}}){{/isApiV1}}

async def page_async(self, {{#allParams}}
{{#startsWith paramName text='page_size'}}{{else}}{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/startsWith}}{{/allParams}}
async def page_async(self, {{#isApiV1}}{{#allParams}}
{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/allParams}}
) -> {{apiName}}Page:
"""
Asynchronously retrieve a single page of {{instanceName}} records from the API.
Request is executed immediately
{{#allParams}}
:param {{paramName}}: {{{description}}}{{/allParams}}
:returns: Page of {{instanceName}}
"""
data = values.of({ {{#allParams}}
'{{{baseName}}}': {{#if vendorExtensions.x-serialize}}{{vendorExtensions.x-serialize}}({{paramName}}{{#if isArray}}, lambda e: e){{else}}){{/if}}{{else}}{{paramName}}{{/if}},{{/allParams}}
}){{/isApiV1}}{{^isApiV1}}{{#allParams}}
{{#startsWith paramName text='page_size'}}{{else}}{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/startsWith}}{{/allParams}}
page_token: Union[str, object] = values.unset,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider the case when page_token, page_size params are present in the spec file too, like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

page_number: Union[int, object] = values.unset,
page_size: Union[int, object] = values.unset,
Expand All @@ -659,7 +683,7 @@
'PageToken': page_token,
'Page': page_number,
'PageSize': page_size,
})
}){{/isApiV1}}

headers = values.of({
{{#headerParams}}'{{{baseName}}}': {{paramName}},
Expand All @@ -672,8 +696,9 @@
headers["Accept"] = "{{{mediaType}}}"
{{/produces}}

response = await self._version.page_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, params=data, headers=headers)
return {{apiName}}Page(self._version, response{{#if listPathParams}}, self._solution{{/if}})
response = await self._version.page_async(method='{{vendorExtensions.x-http-method}}', uri=self._uri, params=data, headers=headers){{#isApiV1}}
return {{apiName}}Page(self._version, response, uri=self._uri, params=data{{#if listPathParams}}, self._solution{{/if}}){{/isApiV1}}{{^isApiV1}}
return {{apiName}}Page(self._version, response{{#if listPathParams}}, self._solution{{/if}}){{/isApiV1}}

def page_with_http_info(self, {{#allParams}}
{{#startsWith paramName text='page_size'}}{{else}}{{#startsWith paramName text='page_token'}}{{else}}{{paramName}}: Union[{{{dataType}}}, object] = values.unset,{{/startsWith}}{{/startsWith}}{{/allParams}}
Expand Down