-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsdk_create_delivery.py
89 lines (69 loc) · 2.23 KB
/
sdk_create_delivery.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
79
80
81
82
83
84
85
86
87
88
89
"""
Deliveree SDK
With Deliveree SDK, developers can integrate our on-demand local delivery
platform into their applications. The SDK is designed for developers to
create bookings.
Contact: [email protected]
"""
import requests
import json
from utils import load_conf
class SdkCreateDlvr():
def __init__(self):
self.conf = load_conf()
def sdk_create_dlvr_conn(
self,
api_key,
vehicle_type_id,
note,
time_type,
pickup_time,
job_order_number,
locations
):
conf = self.conf["sdk-create-dlvr"]
data = conf["payload"]
data["time_type"] = self._time_type(time_type)
data["vehicle_type_id"] = self._vehicle_type_id(vehicle_type_id)
data["note"] = self._note(note)
data["locations"] = self._locations(locations)
data["job_order_number"] = self._job_order_number(job_order_number)
data["pickup_time"] = self._pickup_time(pickup_time)
payload = json.dumps(data)
headers = conf["headers"]
headers["Authorization"] = api_key
conn = requests.post(
conf["url"],
headers=headers,
data=payload,
timeout=3)
print(conn, conn.text)
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 _note(self, value):
if type(value) != str:
raise Exception("note expect a str")
return value
def _job_order_number(self, value):
if type(value) != str:
raise Exception("note expect a str")
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
def _pickup_time(self, value):
if type(value) != str:
raise Exception("note expect a str")
return value