Skip to content

Commit f62ac39

Browse files
authored
Add ability to set a timeout on api requests (#36)
1 parent 87adee7 commit f62ac39

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

knockapi/client.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55

66

77
class Connection(object):
8-
def __init__(self, api_key, host='https://api.knock.app'):
8+
def __init__(self, api_key, host='https://api.knock.app', timeout=None):
99
self.api_key = api_key
1010
self.host = host
1111
self.client_version = __version__
1212
self.headers = {
1313
'Authorization': 'Bearer {}'.format(self.api_key),
1414
'User-Agent': 'Knock Python - {}'.format(self.client_version)
1515
}
16+
self.timeout = timeout
1617

1718
def request(self, method, endpoint, payload=None, options={}):
1819
url = '{}/v1{}'.format(self.host, endpoint)
@@ -26,7 +27,8 @@ def request(self, method, endpoint, payload=None, options={}):
2627
url,
2728
params=payload if method == 'get' else None,
2829
json=payload if method != 'get' else None,
29-
headers={**self.headers, **extra_headers}
30+
headers={**self.headers, **extra_headers},
31+
timeout=self.timeout,
3032
)
3133

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

0 commit comments

Comments
 (0)