-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Minor bugfixes * Improve error handling
1 parent
0325252
commit 303d9f8
Showing
7 changed files
with
148 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import requests | ||
import json | ||
|
||
from urllib.parse import urljoin, urlencode | ||
from requests.exceptions import RequestException | ||
|
||
|
||
class BlockBeeAPIException(Exception): | ||
pass | ||
|
||
|
||
class BlockBeeRequests: | ||
BLOCKBEE_URL = 'https://api.blockbee.io/' | ||
BLOCKBEE_HOST = 'api.blockbee.io' | ||
|
||
@staticmethod | ||
def process_request_get(coin=None, endpoint='', params=None): | ||
if coin: | ||
coin += '/' | ||
else: | ||
coin = '' | ||
|
||
response = requests.get( | ||
url="{base_url}{coin}{endpoint}/".format( | ||
base_url=BlockBeeRequests.BLOCKBEE_URL, | ||
coin=coin.replace('_', '/'), | ||
endpoint=endpoint, | ||
), | ||
params=params, | ||
headers={'Host': BlockBeeRequests.BLOCKBEE_HOST}, | ||
) | ||
|
||
response_obj = response.json() | ||
|
||
if response_obj.get('status') == 'error': | ||
raise BlockBeeAPIException(response_obj['error']) | ||
|
||
return response_obj | ||
|
||
@staticmethod | ||
def process_request_post(coin=None, endpoint='', apiKey='', body=None, isJson=False): | ||
if coin: | ||
coin_path = coin.replace('_', '/') + '/' | ||
else: | ||
coin_path = '' | ||
|
||
url = urljoin(BlockBeeRequests.BLOCKBEE_URL, f"{coin_path}{endpoint}/") | ||
url += '?' + urlencode({'apikey': apiKey}) | ||
|
||
headers = { | ||
'Host': BlockBeeRequests.BLOCKBEE_HOST, | ||
} | ||
|
||
if isJson: | ||
headers['Content-Type'] = 'application/json' | ||
data = json.dumps(body) | ||
else: | ||
headers['Content-Type'] = 'application/x-www-form-urlencoded' | ||
data = urlencode(body) | ||
|
||
response = requests.post(url, headers=headers, data=data) | ||
|
||
response_obj = response.json() | ||
|
||
if response_obj.get('status') == 'error': | ||
raise BlockBeeAPIException(response_obj['error']) | ||
|
||
return response_obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .BlockBee import BlockBeeHelper | ||
from .BlockBeeCheckout import BlockBeeCheckoutHelper | ||
from .BlockBeeCheckout import BlockBeeCheckoutHelper | ||
from .BlockBeeRequests import BlockBeeRequests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
name='python-blockbee', | ||
|
||
version='2.0.1', | ||
version='2.1.0', | ||
|
||
packages=find_packages(), | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters