Skip to content

Commit

Permalink
Merge pull request #50 from fireblocks/add-timeout
Browse files Browse the repository at this point in the history
add timeout ability in fireblocks sdk
  • Loading branch information
yarinvak authored Nov 23, 2021
2 parents 269f96a + 276ad7b commit f956e73
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions fireblocks_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@

class FireblocksSDK(object):

def __init__(self, private_key, api_key, api_base_url="https://api.fireblocks.io"):
def __init__(self, private_key, api_key, api_base_url="https://api.fireblocks.io", timeout=None):
"""Creates a new Fireblocks API Client.
Args:
private_key (str): A string representation of your private key (in PEM format)
api_key (str): Your api key. This is a uuid you received from Fireblocks
base_url (str): The fireblocks server URL. Leave empty to use the default server
timeout (number): Timeout for http requests
"""
self.private_key = private_key
self.api_key = api_key
self.base_url = api_base_url
self.token_provider = SdkTokenProvider(private_key, api_key)
self.timeout = timeout

def get_supported_assets(self):
"""Gets all assets that are currently supported by Fireblocks"""
Expand Down Expand Up @@ -1109,7 +1111,7 @@ def _get_request(self, path, page_mode=False):
"Authorization": f"Bearer {token}"
}

response = requests.get(self.base_url + path, headers=headers)
response = requests.get(self.base_url + path, headers=headers, timeout=self.timeout)
response_data = response.json()
if response.status_code >= 300:
raise FireblocksApiException("Got an error from fireblocks server: " + response.text)
Expand All @@ -1126,7 +1128,7 @@ def _delete_request(self, path):
"Authorization": f"Bearer {token}"
}

response = requests.delete(self.base_url + path, headers=headers)
response = requests.delete(self.base_url + path, headers=headers, timeout=self.timeout)
if response.status_code >= 300:
raise FireblocksApiException("Got an error from fireblocks server: " + response.text)
else:
Expand All @@ -1146,7 +1148,7 @@ def _post_request(self, path, body={}, idempotency_key=None):
"Idempotency-Key": idempotency_key
}

response = requests.post(self.base_url + path, headers=headers, json=body)
response = requests.post(self.base_url + path, headers=headers, json=body, timeout=self.timeout)
if response.status_code >= 300:
raise FireblocksApiException("Got an error from fireblocks server: " + response.text)
else:
Expand All @@ -1160,7 +1162,7 @@ def _put_request(self, path, body={}):
"Content-Type": "application/json"
}

response = requests.put(self.base_url + path, headers=headers, data=json.dumps(body))
response = requests.put(self.base_url + path, headers=headers, data=json.dumps(body), timeout=self.timeout)
if response.status_code >= 300:
raise FireblocksApiException("Got an error from fireblocks server: " + response.text)
else:
Expand Down

0 comments on commit f956e73

Please sign in to comment.