Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Support for connecting to Square API endpoints via a proxy #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions squareconnect/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
11 changes: 10 additions & 1 deletion squareconnect/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,23 @@ 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,
cert_file=cert_file,
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):
"""
Expand Down