Uh oh!
There was an error while loading. Please reload this page.
forked from mmkhitaryan/tegro_api_python_client
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi_client.py
More file actions
Latest commit
40 lines (33 loc) · 1.1 KB
/
Copy pathapi_client.py
File metadata and controls
40 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
importtime
importhmac
importhashlib
importrequests
importjson
classAPIClient():
def__init__(self, api_key, shop_id):
self.api_key=api_key
self.shop_id=shop_id
def_send_http_request(self, api_method, data):
data= {
"shop_id": self.shop_id,
**data
}
# По умолчанию питон json.dumps добавляет пробелы в JSON
# Но php метод json_encode их не добавляет.
jsoned_data=json.dumps(data, separators=(',', ':'))
sign=hmac.digest(
self.api_key.encode(),
jsoned_data.encode(),
'sha256'
).hex()
resp=requests.post(f"https://tegro.money/api/{api_method}/",
data=jsoned_data,
headers={
"Authorization": f'Bearer {sign}',
}
)
returnresp.json()
defapi_call(self, api_method, params={}, nonce=None):
ifnonce==None:
nonce=int(time.time())
returnself._send_http_request(api_method, {"nonce": nonce, **params})