From e5d20d31a8a8f5fa08da96e779d38b019657c667 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Wed, 21 Jun 2017 15:20:28 +0000 Subject: [PATCH 1/3] From connect-api-specification: Fix python location example in readme Implements https://github.com/square/connect-python-sdk/pull/31 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4a96881..4b43957 100644 --- a/README.md +++ b/README.md @@ -46,12 +46,12 @@ from __future__ import print_function import squareconnect from squareconnect.rest import ApiException -from squareconnect.apis.location_api import LocationApi +from squareconnect.apis.locations_api import LocationsApi # setup authorization squareconnect.configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the Location API class -api_instance = LocationApi() +api_instance = LocationsApi() try: # ListLocations From c1f8421b620f0473854902c254bef6579a02b77a Mon Sep 17 00:00:00 2001 From: Travis CI Date: Wed, 19 Jul 2017 01:07:34 +0000 Subject: [PATCH 2/3] From connect-api-specification: Merge branch 'master' into tristans/fix-python-example --- README.md | 46 ++++++++++++++++--- docs/V1EmployeesApi.md | 11 +++-- docs/V1ItemsApi.md | 6 ++- docs/V1TransactionsApi.md | 12 +++-- squareconnect/apis/v1_employees_api.py | 21 +++++---- squareconnect/apis/v1_items_api.py | 10 +++- squareconnect/apis/v1_transactions_api.py | 20 ++++++-- .../models/search_catalog_objects_request.py | 4 +- squareconnect/rest.py | 22 +++++++-- tox.ini | 2 +- 10 files changed, 115 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 4513679..dbea0dd 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ import squareconnect ### Retrieve your location IDs ```python -from __future__ import print_function +from __future__ import print_function import squareconnect from squareconnect.rest import ApiException @@ -63,7 +63,7 @@ except ApiException as e: ``` ### Charge the card nonce ```python -from __future__ import print_function +from __future__ import print_function import uuid import squareconnect @@ -74,8 +74,8 @@ from squareconnect.apis.transaction_api import TransactionApi squareconnect.configuration.access_token = 'YOUR_ACCESS_TOKEN' # create an instance of the Transaction API class api_instance = TransactionApi() -location_id = 'YOUR_LOCATION_ID' -nonce = 'YOUR_NONCE' +location_id = 'YOUR_LOCATION_ID' +nonce = 'YOUR_NONCE' try: # Charge @@ -94,8 +94,8 @@ except ApiException as e: All URIs are relative to [Square Connect Documentation](https://docs.connect.squareup.com/) -Class | Method | HTTP request ------------- | ------------- | ------------- +Class | Method | HTTP request +------------ | ------------- | ------------- *CatalogApi* | [**batch_delete_catalog_objects**](docs/CatalogApi.md#batch_delete_catalog_objects) | **POST** /v2/catalog/batch-delete *CatalogApi* | [**batch_retrieve_catalog_objects**](docs/CatalogApi.md#batch_retrieve_catalog_objects) | **POST** /v2/catalog/batch-retrieve *CatalogApi* | [**batch_upsert_catalog_objects**](docs/CatalogApi.md#batch_upsert_catalog_objects) | **POST** /v2/catalog/batch-upsert @@ -389,6 +389,40 @@ Class | Method | HTTP request - **TIMECARDS_WRITE**: POST, PUT, and DELETE endpoints related to employee timecards +## Pagination of V1 Endpoints + +V1 Endpoints return pagination information via HTTP headers. In order to obtain +response headers and extract the `batch_token` parameter you will need to get it +from the response object after each call as follows: + +### Example + +```python +from __future__ import print_function + +import squareconnect +from squareconnect.rest import ApiException +from squareconnect.apis.v1_employees_api import V1EmployeesApi + +# setup authorization +squareconnect.configuration.access_token = 'YOUR_ACCESS_TOKEN' +# create an instance of the V1 Employee API class +api_instance = V1EmployeesApi() +has_next_page = True +token = None + +try: + while has_next_page: + # ListEmployeeRoles + api_response = api_instance.list_employee_roles(batch_token=token) + print (api_response.locations) + + token = api_instance.api_client.last_response.getbatch_token() + has_next_page = token != None +except ApiException as e: + print ('Exception when calling V1EmployeesApi->list_employee_roles: %s\n' % e) +``` + ## Contributing Send bug reports, feature requests, and code contributions to the [API diff --git a/docs/V1EmployeesApi.md b/docs/V1EmployeesApi.md index 87f6b7f..45459af 100644 --- a/docs/V1EmployeesApi.md +++ b/docs/V1EmployeesApi.md @@ -143,7 +143,7 @@ Assign your **Access Token** from developer portal to the authorization paramete [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **list_employee_roles** -> list[V1EmployeeRole] list_employee_roles(order=order, limit=limit, cursor=cursor) +> list[V1EmployeeRole] list_employee_roles(order=order, limit=limit, batch_token=batch_token) ### Description @@ -155,7 +155,7 @@ Name | Type | Notes | Default Value ------------- | ------------- | ------------- | ------------- **order** | **str**| [optional] **limit** | **int**| [optional] - **cursor** | **str**| [optional] + **batch_token** | **str**| [optional] ### Return type @@ -168,7 +168,7 @@ Assign your **Access Token** from developer portal to the authorization paramete [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **list_employees** -> list[V1Employee] list_employees(order=order, begin_updated_at=begin_updated_at, end_updated_at=end_updated_at, begin_created_at=begin_created_at, end_created_at=end_created_at, status=status, external_id=external_id, limit=limit) +> list[V1Employee] list_employees(order=order, begin_updated_at=begin_updated_at, end_updated_at=end_updated_at, begin_created_at=begin_created_at, end_created_at=end_created_at, status=status, external_id=external_id, limit=limit, batch_token=batch_token) ### Description @@ -186,6 +186,7 @@ Name | Type | Notes | Default Value **status** | **str**| [optional] **external_id** | **str**| [optional] **limit** | **int**| [optional] + **batch_token** | **str**| [optional] ### Return type @@ -221,7 +222,7 @@ Assign your **Access Token** from developer portal to the authorization paramete [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **list_timecards** -> list[V1Timecard] list_timecards(order=order, employee_id=employee_id, begin_clockin_time=begin_clockin_time, end_clockin_time=end_clockin_time, begin_clockout_time=begin_clockout_time, end_clockout_time=end_clockout_time, begin_updated_at=begin_updated_at, end_updated_at=end_updated_at, deleted=deleted, limit=limit, cursor=cursor) +> list[V1Timecard] list_timecards(order=order, employee_id=employee_id, begin_clockin_time=begin_clockin_time, end_clockin_time=end_clockin_time, begin_clockout_time=begin_clockout_time, end_clockout_time=end_clockout_time, begin_updated_at=begin_updated_at, end_updated_at=end_updated_at, deleted=deleted, limit=limit, batch_token=batch_token) ### Description @@ -241,7 +242,7 @@ Name | Type | Notes | Default Value **end_updated_at** | **str**| [optional] **deleted** | **bool**| [optional] **limit** | **int**| [optional] - **cursor** | **str**| [optional] + **batch_token** | **str**| [optional] ### Return type diff --git a/docs/V1ItemsApi.md b/docs/V1ItemsApi.md index 19597be..52556b5 100644 --- a/docs/V1ItemsApi.md +++ b/docs/V1ItemsApi.md @@ -607,7 +607,7 @@ Assign your **Access Token** from developer portal to the authorization paramete [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **list_inventory** -> list[V1InventoryEntry] list_inventory(location_id, limit=limit) +> list[V1InventoryEntry] list_inventory(location_id, limit=limit, batch_token=batch_token) ### Description @@ -619,6 +619,7 @@ Name | Type | Notes | Default Value ------------- | ------------- | ------------- | ------------- **location_id** | **str**| **limit** | **int**| [optional] + **batch_token** | **str**| [optional] ### Return type @@ -631,7 +632,7 @@ Assign your **Access Token** from developer portal to the authorization paramete [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **list_items** -> list[V1Item] list_items(location_id) +> list[V1Item] list_items(location_id, batch_token=batch_token) ### Description @@ -642,6 +643,7 @@ Provides summary information for all of a location's items. Name | Type | Notes | Default Value ------------- | ------------- | ------------- | ------------- **location_id** | **str**| + **batch_token** | **str**| [optional] ### Return type diff --git a/docs/V1TransactionsApi.md b/docs/V1TransactionsApi.md index 64b3bee..a56901f 100644 --- a/docs/V1TransactionsApi.md +++ b/docs/V1TransactionsApi.md @@ -67,7 +67,7 @@ Assign your **Access Token** from developer portal to the authorization paramete [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **list_orders** -> list[V1Order] list_orders(location_id, order=order, limit=limit) +> list[V1Order] list_orders(location_id, order=order, limit=limit, batch_token=batch_token) ### Description @@ -80,6 +80,7 @@ Name | Type | Notes | Default Value **location_id** | **str**| **order** | **str**| [optional] **limit** | **int**| [optional] + **batch_token** | **str**| [optional] ### Return type @@ -92,7 +93,7 @@ Assign your **Access Token** from developer portal to the authorization paramete [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **list_payments** -> list[V1Payment] list_payments(location_id, order=order, begin_time=begin_time, end_time=end_time, limit=limit) +> list[V1Payment] list_payments(location_id, order=order, begin_time=begin_time, end_time=end_time, limit=limit, batch_token=batch_token) ### Description @@ -107,6 +108,7 @@ Name | Type | Notes | Default Value **begin_time** | **str**| [optional] **end_time** | **str**| [optional] **limit** | **int**| [optional] + **batch_token** | **str**| [optional] ### Return type @@ -119,7 +121,7 @@ Assign your **Access Token** from developer portal to the authorization paramete [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **list_refunds** -> list[V1Refund] list_refunds(location_id, order=order, begin_time=begin_time, end_time=end_time, limit=limit) +> list[V1Refund] list_refunds(location_id, order=order, begin_time=begin_time, end_time=end_time, limit=limit, batch_token=batch_token) ### Description @@ -134,6 +136,7 @@ Name | Type | Notes | Default Value **begin_time** | **str**| [optional] **end_time** | **str**| [optional] **limit** | **int**| [optional] + **batch_token** | **str**| [optional] ### Return type @@ -146,7 +149,7 @@ Assign your **Access Token** from developer portal to the authorization paramete [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) # **list_settlements** -> list[V1Settlement] list_settlements(location_id, order=order, begin_time=begin_time, end_time=end_time, limit=limit, status=status) +> list[V1Settlement] list_settlements(location_id, order=order, begin_time=begin_time, end_time=end_time, limit=limit, status=status, batch_token=batch_token) ### Description @@ -162,6 +165,7 @@ Name | Type | Notes | Default Value **end_time** | **str**| [optional] **limit** | **int**| [optional] **status** | **str**| [optional] + **batch_token** | **str**| [optional] ### Return type diff --git a/squareconnect/apis/v1_employees_api.py b/squareconnect/apis/v1_employees_api.py index 3fb15aa..adb4710 100644 --- a/squareconnect/apis/v1_employees_api.py +++ b/squareconnect/apis/v1_employees_api.py @@ -462,13 +462,13 @@ def list_employee_roles(self, **kwargs): for asynchronous request. (optional) :param str order: The order in which employees are listed in the response, based on their created_at field.Default value: ASC :param int limit: The maximum integer number of employee entities to return in a single response. Default 100, maximum 200. - :param str cursor: A pagination cursor to retrieve the next set of results for your original query to the endpoint. + :param str batch_token: A pagination cursor to retrieve the next set of results for your original query to the endpoint. :return: list[V1EmployeeRole] If the method is called asynchronously, returns the request thread. """ - all_params = ['order', 'limit', 'cursor'] + all_params = ['order', 'limit', 'batch_token'] all_params.append('callback') params = locals() @@ -493,8 +493,8 @@ def list_employee_roles(self, **kwargs): query_params['order'] = params['order'] if 'limit' in params and params['limit'] is not None: query_params['limit'] = params['limit'] - if 'cursor' in params and params['cursor'] is not None: - query_params['cursor'] = params['cursor'] + if 'batch_token' in params and params['batch_token'] is not None: + query_params['batch_token'] = params['batch_token'] header_params = {} @@ -551,12 +551,13 @@ def list_employees(self, **kwargs): :param str status: If provided, the endpoint returns only employee entities with the specified status (ACTIVE or INACTIVE). :param str external_id: If provided, the endpoint returns only employee entities with the specified external_id. :param int limit: The maximum integer number of employee entities to return in a single response. Default 100, maximum 200. + :param str batch_token: A pagination cursor to retrieve the next set of results for your original query to the endpoint. :return: list[V1Employee] If the method is called asynchronously, returns the request thread. """ - all_params = ['order', 'begin_updated_at', 'end_updated_at', 'begin_created_at', 'end_created_at', 'status', 'external_id', 'limit'] + all_params = ['order', 'begin_updated_at', 'end_updated_at', 'begin_created_at', 'end_created_at', 'status', 'external_id', 'limit', 'batch_token'] all_params.append('callback') params = locals() @@ -593,6 +594,8 @@ def list_employees(self, **kwargs): query_params['external_id'] = params['external_id'] if 'limit' in params and params['limit'] is not None: query_params['limit'] = params['limit'] + if 'batch_token' in params and params['batch_token'] is not None: + query_params['batch_token'] = params['batch_token'] header_params = {} @@ -729,13 +732,13 @@ def list_timecards(self, **kwargs): :param str end_updated_at: If filtering results by their updated_at field, the end of the requested reporting period, in ISO 8601 format. :param bool deleted: If true, only deleted timecards are returned. If false, only valid timecards are returned.If you don't provide this parameter, both valid and deleted timecards are returned. :param int limit: The maximum integer number of employee entities to return in a single response. Default 100, maximum 200. - :param str cursor: A pagination cursor to retrieve the next set of results for your original query to the endpoint. + :param str batch_token: A pagination cursor to retrieve the next set of results for your original query to the endpoint. :return: list[V1Timecard] If the method is called asynchronously, returns the request thread. """ - all_params = ['order', 'employee_id', 'begin_clockin_time', 'end_clockin_time', 'begin_clockout_time', 'end_clockout_time', 'begin_updated_at', 'end_updated_at', 'deleted', 'limit', 'cursor'] + all_params = ['order', 'employee_id', 'begin_clockin_time', 'end_clockin_time', 'begin_clockout_time', 'end_clockout_time', 'begin_updated_at', 'end_updated_at', 'deleted', 'limit', 'batch_token'] all_params.append('callback') params = locals() @@ -776,8 +779,8 @@ def list_timecards(self, **kwargs): query_params['deleted'] = params['deleted'] if 'limit' in params and params['limit'] is not None: query_params['limit'] = params['limit'] - if 'cursor' in params and params['cursor'] is not None: - query_params['cursor'] = params['cursor'] + if 'batch_token' in params and params['batch_token'] is not None: + query_params['batch_token'] = params['batch_token'] header_params = {} diff --git a/squareconnect/apis/v1_items_api.py b/squareconnect/apis/v1_items_api.py index e3222d1..a8c5b6d 100644 --- a/squareconnect/apis/v1_items_api.py +++ b/squareconnect/apis/v1_items_api.py @@ -2025,12 +2025,13 @@ def list_inventory(self, location_id, **kwargs): for asynchronous request. (optional) :param str location_id: The ID of the item's associated location. (required) :param int limit: The maximum number of inventory entries to return in a single response. This value cannot exceed 1000. + :param str batch_token: A pagination cursor to retrieve the next set of results for your original query to the endpoint. :return: list[V1InventoryEntry] If the method is called asynchronously, returns the request thread. """ - all_params = ['location_id', 'limit'] + all_params = ['location_id', 'limit', 'batch_token'] all_params.append('callback') params = locals() @@ -2058,6 +2059,8 @@ def list_inventory(self, location_id, **kwargs): query_params = {} if 'limit' in params and params['limit'] is not None: query_params['limit'] = params['limit'] + if 'batch_token' in params and params['batch_token'] is not None: + query_params['batch_token'] = params['batch_token'] header_params = {} @@ -2107,12 +2110,13 @@ def list_items(self, location_id, **kwargs): :param callback function: The callback function for asynchronous request. (optional) :param str location_id: The ID of the location to list items for. (required) + :param str batch_token: A pagination cursor to retrieve the next set of results for your original query to the endpoint. :return: list[V1Item] If the method is called asynchronously, returns the request thread. """ - all_params = ['location_id'] + all_params = ['location_id', 'batch_token'] all_params.append('callback') params = locals() @@ -2136,6 +2140,8 @@ def list_items(self, location_id, **kwargs): path_params['location_id'] = params['location_id'] query_params = {} + if 'batch_token' in params and params['batch_token'] is not None: + query_params['batch_token'] = params['batch_token'] header_params = {} diff --git a/squareconnect/apis/v1_transactions_api.py b/squareconnect/apis/v1_transactions_api.py index 95abbf2..84488e1 100644 --- a/squareconnect/apis/v1_transactions_api.py +++ b/squareconnect/apis/v1_transactions_api.py @@ -226,12 +226,13 @@ def list_orders(self, location_id, **kwargs): :param str location_id: The ID of the location to list online store orders for. (required) :param str order: TThe order in which payments are listed in the response. :param int limit: The maximum number of payments to return in a single response. This value cannot exceed 200. + :param str batch_token: A pagination cursor to retrieve the next set of results for your original query to the endpoint. :return: list[V1Order] If the method is called asynchronously, returns the request thread. """ - all_params = ['location_id', 'order', 'limit'] + all_params = ['location_id', 'order', 'limit', 'batch_token'] all_params.append('callback') params = locals() @@ -261,6 +262,8 @@ def list_orders(self, location_id, **kwargs): query_params['order'] = params['order'] if 'limit' in params and params['limit'] is not None: query_params['limit'] = params['limit'] + if 'batch_token' in params and params['batch_token'] is not None: + query_params['batch_token'] = params['batch_token'] header_params = {} @@ -314,12 +317,13 @@ def list_payments(self, location_id, **kwargs): :param str begin_time: The beginning of the requested reporting period, in ISO 8601 format. If this value is before January 1, 2013 (2013-01-01T00:00:00Z), this endpoint returns an error. Default value: The current time minus one year. :param str end_time: The end of the requested reporting period, in ISO 8601 format. If this value is more than one year greater than begin_time, this endpoint returns an error. Default value: The current time. :param int limit: The maximum number of payments to return in a single response. This value cannot exceed 200. + :param str batch_token: A pagination cursor to retrieve the next set of results for your original query to the endpoint. :return: list[V1Payment] If the method is called asynchronously, returns the request thread. """ - all_params = ['location_id', 'order', 'begin_time', 'end_time', 'limit'] + all_params = ['location_id', 'order', 'begin_time', 'end_time', 'limit', 'batch_token'] all_params.append('callback') params = locals() @@ -353,6 +357,8 @@ def list_payments(self, location_id, **kwargs): query_params['end_time'] = params['end_time'] if 'limit' in params and params['limit'] is not None: query_params['limit'] = params['limit'] + if 'batch_token' in params and params['batch_token'] is not None: + query_params['batch_token'] = params['batch_token'] header_params = {} @@ -406,12 +412,13 @@ def list_refunds(self, location_id, **kwargs): :param str begin_time: The beginning of the requested reporting period, in ISO 8601 format. If this value is before January 1, 2013 (2013-01-01T00:00:00Z), this endpoint returns an error. Default value: The current time minus one year. :param str end_time: The end of the requested reporting period, in ISO 8601 format. If this value is more than one year greater than begin_time, this endpoint returns an error. Default value: The current time. :param int limit: The maximum number of payments to return in a single response. This value cannot exceed 200. + :param str batch_token: A pagination cursor to retrieve the next set of results for your original query to the endpoint. :return: list[V1Refund] If the method is called asynchronously, returns the request thread. """ - all_params = ['location_id', 'order', 'begin_time', 'end_time', 'limit'] + all_params = ['location_id', 'order', 'begin_time', 'end_time', 'limit', 'batch_token'] all_params.append('callback') params = locals() @@ -445,6 +452,8 @@ def list_refunds(self, location_id, **kwargs): query_params['end_time'] = params['end_time'] if 'limit' in params and params['limit'] is not None: query_params['limit'] = params['limit'] + if 'batch_token' in params and params['batch_token'] is not None: + query_params['batch_token'] = params['batch_token'] header_params = {} @@ -499,12 +508,13 @@ def list_settlements(self, location_id, **kwargs): :param str end_time: The end of the requested reporting period, in ISO 8601 format. If this value is more than one year greater than begin_time, this endpoint returns an error. Default value: The current time. :param int limit: The maximum number of payments to return in a single response. This value cannot exceed 200. :param str status: Provide this parameter to retrieve only settlements with a particular status (SENT or FAILED). + :param str batch_token: A pagination cursor to retrieve the next set of results for your original query to the endpoint. :return: list[V1Settlement] If the method is called asynchronously, returns the request thread. """ - all_params = ['location_id', 'order', 'begin_time', 'end_time', 'limit', 'status'] + all_params = ['location_id', 'order', 'begin_time', 'end_time', 'limit', 'status', 'batch_token'] all_params.append('callback') params = locals() @@ -540,6 +550,8 @@ def list_settlements(self, location_id, **kwargs): query_params['limit'] = params['limit'] if 'status' in params and params['status'] is not None: query_params['status'] = params['status'] + if 'batch_token' in params and params['batch_token'] is not None: + query_params['batch_token'] = params['batch_token'] header_params = {} diff --git a/squareconnect/models/search_catalog_objects_request.py b/squareconnect/models/search_catalog_objects_request.py index 46fb77c..79a6c19 100644 --- a/squareconnect/models/search_catalog_objects_request.py +++ b/squareconnect/models/search_catalog_objects_request.py @@ -91,7 +91,7 @@ def cursor(self, cursor): def object_types(self): """ Gets the object_types of this SearchCatalogObjectsRequest. - The desired set of object types to apper in the search results. The legal values are taken from the [CatalogObjectType](#type-catalogobjecttype) enumeration, namely `\"ITEM\"`, `\"ITEM_VARIATION\"`, `\"CATEGORY\"`, `\"DISCOUNT\"`, `\"TAX\"`, `\"MODIFIER\"`, or `\"MODIFIER_LIST\"`. + The desired set of object types to appear in the search results. The legal values are taken from the [CatalogObjectType](#type-catalogobjecttype) enumeration, namely `\"ITEM\"`, `\"ITEM_VARIATION\"`, `\"CATEGORY\"`, `\"DISCOUNT\"`, `\"TAX\"`, `\"MODIFIER\"`, or `\"MODIFIER_LIST\"`. :return: The object_types of this SearchCatalogObjectsRequest. :rtype: list[str] @@ -102,7 +102,7 @@ def object_types(self): def object_types(self, object_types): """ Sets the object_types of this SearchCatalogObjectsRequest. - The desired set of object types to apper in the search results. The legal values are taken from the [CatalogObjectType](#type-catalogobjecttype) enumeration, namely `\"ITEM\"`, `\"ITEM_VARIATION\"`, `\"CATEGORY\"`, `\"DISCOUNT\"`, `\"TAX\"`, `\"MODIFIER\"`, or `\"MODIFIER_LIST\"`. + The desired set of object types to appear in the search results. The legal values are taken from the [CatalogObjectType](#type-catalogobjecttype) enumeration, namely `\"ITEM\"`, `\"ITEM_VARIATION\"`, `\"CATEGORY\"`, `\"DISCOUNT\"`, `\"TAX\"`, `\"MODIFIER\"`, or `\"MODIFIER_LIST\"`. :param object_types: The object_types of this SearchCatalogObjectsRequest. :type: list[str] diff --git a/squareconnect/rest.py b/squareconnect/rest.py index 02cbe45..7b3aff2 100644 --- a/squareconnect/rest.py +++ b/squareconnect/rest.py @@ -24,6 +24,7 @@ import ssl import certifi import logging +import re # python 2 and python 3 compatibility library from six import iteritems @@ -38,10 +39,11 @@ try: # for python3 from urllib.parse import urlencode + from urllib.parse import urlparse except ImportError: # for python2 from urllib import urlencode - + import urlparse logger = logging.getLogger(__name__) @@ -52,7 +54,7 @@ def __init__(self, resp, method): self.urllib3_response = resp self.status = resp.status self.reason = resp.reason - # In Square Connect v2 API, + # In Square Connect v2 API, # GET ListCustomers/ListLocations/ListTransaction/ListRefunds # may have large response thus calling stream() for chunked-encoding if method in ['GET', 'HEAD']: @@ -62,7 +64,7 @@ def __init__(self, resp, method): # we need to decode it to string. if sys.version_info > (3,): self.data += chunk.decode('utf8') - else: + else: self.data += str(chunk) # as using preload_content=False, we should call release_conn() # to release the http connection back to the connection pool so that @@ -86,6 +88,18 @@ def getheader(self, name, default=None): """ return self.urllib3_response.getheader(name, default) + def getbatch_token(self): + link_header = self.getheader('Link') + if link_header != None: + match = re.match("^<([^>]+)>;rel='next'$", link_header) + if match != None: + next_url = match.group(1) + parsed_url = urlparse.urlparse(next_url) + parameters = urlparse.parse_qs(parsed_url.query) + if parameters.has_key('batch_token'): + return parameters['batch_token'][0] + return None + class RESTClientObject(object): @@ -178,7 +192,7 @@ def request(self, method, url, query_params=None, headers=None, fields=query_params, headers=headers, preload_content=False) - + except urllib3.exceptions.SSLError as e: msg = "{0}\n{1}".format(type(e).__name__, str(e)) raise ApiException(status=0, reason=msg) diff --git a/tox.ini b/tox.ini index d99517b..1cf0829 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27, py34 +envlist = py27, py3 [testenv] deps=-r{toxinidir}/requirements.txt From f408015ae96d5bce96262f3a2d3ae0341fa76d56 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Fri, 28 Jul 2017 22:08:19 +0000 Subject: [PATCH 3/3] From connect-api-specification: Merge branch 'master' into tristans/fix-python-example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dbea0dd..01b8efe 100644 --- a/README.md +++ b/README.md @@ -370,7 +370,7 @@ Class | Method | HTTP request - **Type**: OAuth - **Flow**: accessCode -- **Authorization URL**: `https://connect.squareup.com/oauth2/authorize?` +- **Authorization URL**: `https://connect.squareup.com/oauth2/authorize` - **Scopes**: - **MERCHANT_PROFILE_READ**: GET endpoints related to a merchant's business and location entities. Almost all Connect API applications need this permission in order to obtain a merchant's location IDs - **PAYMENTS_READ**: GET endpoints related to transactions and refunds