-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsdk_quote.py
78 lines (62 loc) · 1.88 KB
/
sdk_quote.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Deliveree SDK
With Deliveree SDK, developers can integrate our on-demand local delivery
platform into their applications. The SDK is designed for developers to
check prices.
Contact: [email protected]
"""
import requests
import json
from utils import load_conf
class SDKquote():
def __init__(self):
self.conf = load_conf()
def sdk_quote_conn(
self,
api_key,
time_type,
pickup_time,
vehicle_type_id,
packs,
locations
):
conf = self.conf["sdk-quote"]
data = conf["payload"]
data["time_type"] = time_type
data["pickup_time"] = pickup_time
data["vehicle_type_id"] = vehicle_type_id
data["packs"] = packs
data["locations"] = locations
payload = json.dumps(data)
headers = conf["headers"]
headers["Authorization"] = api_key
conn = requests.post(
conf["url"],
headers=headers,
data=payload,
timeout=3)
return conn.text
def _time_type(self, value):
if type(value) != str:
raise Exception("time_type expect a string")
return value
def _vehicle_type_id(self, value):
if type(value) != int:
raise Exception("vehicle_type_id expect a int")
return value
def _packs(self, value):
if type(value) != list:
raise Exception("packs expect a list")
elif value:
for i in value:
if type(i) != dict:
raise Exception("packs value expect a dict")
return value
def _locations(self, value):
if type(value) != list:
raise Exception("locations expect a list")
elif value:
for i in value:
if type(i) != dict:
raise Exception("locations value expect a dict")
return value