Skip to content

Commit

Permalink
Add ability to set a timeout on api requests (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
zemek authored Jan 6, 2025
1 parent 87adee7 commit f62ac39
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions knockapi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@


class Connection(object):
def __init__(self, api_key, host='https://api.knock.app'):
def __init__(self, api_key, host='https://api.knock.app', timeout=None):
self.api_key = api_key
self.host = host
self.client_version = __version__
self.headers = {
'Authorization': 'Bearer {}'.format(self.api_key),
'User-Agent': 'Knock Python - {}'.format(self.client_version)
}
self.timeout = timeout

def request(self, method, endpoint, payload=None, options={}):
url = '{}/v1{}'.format(self.host, endpoint)
Expand All @@ -26,7 +27,8 @@ def request(self, method, endpoint, payload=None, options={}):
url,
params=payload if method == 'get' else None,
json=payload if method != 'get' else None,
headers={**self.headers, **extra_headers}
headers={**self.headers, **extra_headers},
timeout=self.timeout,
)

# If we got a successful response, then attempt to deserialize as JSON
Expand Down

0 comments on commit f62ac39

Please sign in to comment.