zcash-grant-system/backend/grant/utils/requests.py

30 lines
707 B
Python
Raw Normal View History

import requests
from grant.settings import BLOCKCHAIN_REST_API_URL, BLOCKCHAIN_API_SECRET
2019-01-22 21:35:22 -08:00
### REST API ###
2019-01-08 09:44:54 -08:00
def handle_res(res):
j = res.json()
if j.get('error'):
raise Exception('Blockchain API Error: {}'.format(j['error']))
return j['data']
2019-01-22 21:35:22 -08:00
def blockchain_get(path, params=None):
res = requests.get(
f'{BLOCKCHAIN_REST_API_URL}{path}',
2019-01-22 21:35:22 -08:00
headers={'authorization': BLOCKCHAIN_API_SECRET},
params=params,
)
return handle_res(res)
2019-01-22 21:35:22 -08:00
def blockchain_post(path, data=None):
res = requests.post(
f'{BLOCKCHAIN_REST_API_URL}{path}',
2019-01-22 21:35:22 -08:00
headers={'authorization': BLOCKCHAIN_API_SECRET},
json=data,
)
return handle_res(res)