diff --git a/README.md b/README.md index cd0c9fc..3608086 100644 --- a/README.md +++ b/README.md @@ -394,7 +394,7 @@ Class | Method | HTTP request - **Type**: OAuth - **Flow**: accessCode - **Authorization URL**: `https://connect.squareup.com/oauth2/authorize` -- **Scopes**: +- **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 - **PAYMENTS_WRITE**: POST, PUT, and DELETE endpoints related to transactions and refunds. E-commerce applications must request this permission @@ -453,6 +453,33 @@ except ApiException as e: print ('Exception when calling V1EmployeesApi->list_employee_roles: %s\n' % e) ``` +## Using a proxy + +You may optionally specify a proxy to be used when connecting to the +API endpoints. + +### Example + +```python +from __future__ import print_function + +import squareconnect +from squareconnect.rest import ApiException + +squareconnect.configuration.access_token = 'YOUR_ACCESS_TOKEN' +squareconnect.configuration.proxy_url = 'http://localhost:3128/' + +api = squareconnect.apis.V1LocationsApi() + +try: + locations = api.list_locations() + print('There are {} locations registered in Square.'.format(len(locations))) + for location in locations: + print('id: {}, name:{}'.format(location.id, location.name)) +except ApiException as e: + print ('Exception when calling V1LocationsApi->list_locations: %s\n' % e) +``` + ## Contributing Send bug reports, feature requests, and code contributions to the [API diff --git a/squareconnect/configuration.py b/squareconnect/configuration.py index 81fd6d5..c038ae7 100644 --- a/squareconnect/configuration.py +++ b/squareconnect/configuration.py @@ -100,6 +100,9 @@ def __init__(self): # client key file self.key_file = None + # Proxy settings + self.proxy_url = None + @property def logger_file(self): """ diff --git a/squareconnect/rest.py b/squareconnect/rest.py index 7b3aff2..c774f5b 100644 --- a/squareconnect/rest.py +++ b/squareconnect/rest.py @@ -130,7 +130,8 @@ def __init__(self, pools_size=4): key_file = Configuration().key_file # https pool manager - self.pool_manager = urllib3.PoolManager( + pool_manager_class = urllib3.PoolManager + pool_manager_args = dict( num_pools=pools_size, cert_reqs=cert_reqs, ca_certs=ca_certs, @@ -138,6 +139,14 @@ def __init__(self, pools_size=4): key_file=key_file ) + # check for proxy + proxy_url = Configuration().proxy_url + if proxy_url: + pool_manager_class = urllib3.ProxyManager + pool_manager_args['proxy_url'] = proxy_url + + self.pool_manager = pool_manager_class(**pool_manager_args) + def request(self, method, url, query_params=None, headers=None, body=None, post_params=None): """