shipthisapi-python 1.2.0__tar.gz → 1.3.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {shipthisapi-python-1.2.0 → shipthisapi_python-1.3.1}/PKG-INFO +13 -6
- {shipthisapi-python-1.2.0 → shipthisapi_python-1.3.1}/README.md +4 -0
- shipthisapi_python-1.3.1/ShipthisAPI/shipthisapi.py +116 -0
- {shipthisapi-python-1.2.0 → shipthisapi_python-1.3.1}/setup.py +1 -1
- {shipthisapi-python-1.2.0 → shipthisapi_python-1.3.1}/shipthisapi_python.egg-info/PKG-INFO +13 -6
- {shipthisapi-python-1.2.0 → shipthisapi_python-1.3.1}/shipthisapi_python.egg-info/SOURCES.txt +0 -1
- shipthisapi-python-1.2.0/ShipthisAPI/shipthisapi.py +0 -62
- shipthisapi-python-1.2.0/shipthisapi_python.egg-info/entry_points.txt +0 -3
- {shipthisapi-python-1.2.0 → shipthisapi_python-1.3.1}/ShipthisAPI/__init__.py +0 -0
- {shipthisapi-python-1.2.0 → shipthisapi_python-1.3.1}/setup.cfg +0 -0
- {shipthisapi-python-1.2.0 → shipthisapi_python-1.3.1}/shipthisapi_python.egg-info/dependency_links.txt +0 -0
- {shipthisapi-python-1.2.0 → shipthisapi_python-1.3.1}/shipthisapi_python.egg-info/top_level.txt +0 -0
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: shipthisapi-python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
Summary: ShipthisAPI utility package
|
|
5
5
|
Home-page: https://github.com/shipthisco/shipthisapi-python
|
|
6
6
|
Author: Mayur Rawte
|
|
7
7
|
Author-email: mayur@shipthis.co
|
|
8
|
-
License: UNKNOWN
|
|
9
|
-
Platform: UNKNOWN
|
|
10
8
|
Classifier: Programming Language :: Python :: 3
|
|
11
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
12
10
|
Classifier: Operating System :: OS Independent
|
|
13
11
|
Description-Content-Type: text/markdown
|
|
12
|
+
Dynamic: author
|
|
13
|
+
Dynamic: author-email
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: description
|
|
16
|
+
Dynamic: description-content-type
|
|
17
|
+
Dynamic: home-page
|
|
18
|
+
Dynamic: summary
|
|
14
19
|
|
|
15
20
|
# ShipthisAPI Python
|
|
16
21
|
|
|
@@ -60,6 +65,10 @@ print(shipthisapi.info())
|
|
|
60
65
|
|
|
61
66
|
print(shipthisapi.get_list(collection_name='invoice'))
|
|
62
67
|
|
|
68
|
+
# Get all Sea list
|
|
69
|
+
|
|
70
|
+
print(shipthisapi.get_list(collection_name="sea_shipment", params={"count": 2}))
|
|
71
|
+
|
|
63
72
|
|
|
64
73
|
```
|
|
65
74
|
|
|
@@ -88,5 +97,3 @@ If you have any queries related to usage of the api please raise a issue [here](
|
|
|
88
97
|
|
|
89
98
|
|
|
90
99
|
|
|
91
|
-
|
|
92
|
-
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
from typing import Dict, List
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ShipthisAPI:
|
|
6
|
+
base_api_endpoint = "https://api.shipthis.co/api/v3/"
|
|
7
|
+
|
|
8
|
+
def __init__(
|
|
9
|
+
self,
|
|
10
|
+
organisation: str,
|
|
11
|
+
x_api_key: str,
|
|
12
|
+
user_type="employee",
|
|
13
|
+
region_id: str = None,
|
|
14
|
+
location_id: str = None,
|
|
15
|
+
) -> None:
|
|
16
|
+
self.x_api_key = x_api_key
|
|
17
|
+
self.organisation_id = organisation
|
|
18
|
+
self.user_type = user_type
|
|
19
|
+
self.region_id = region_id
|
|
20
|
+
self.location_id = location_id
|
|
21
|
+
|
|
22
|
+
def set_region_location(self, region_id, location_id):
|
|
23
|
+
self.region_id = region_id
|
|
24
|
+
self.location_id = location_id
|
|
25
|
+
|
|
26
|
+
def _make_request(
|
|
27
|
+
self, method: str, path: str, query_params: str = None, request_data=None
|
|
28
|
+
) -> None:
|
|
29
|
+
headers = {
|
|
30
|
+
"x-api-key": self.x_api_key,
|
|
31
|
+
"organisation": self.organisation_id,
|
|
32
|
+
"user_type": self.user_type,
|
|
33
|
+
"location": "new_york",
|
|
34
|
+
}
|
|
35
|
+
fetched_response = requests.request(
|
|
36
|
+
method,
|
|
37
|
+
self.base_api_endpoint + path,
|
|
38
|
+
data=request_data or {},
|
|
39
|
+
headers=headers,
|
|
40
|
+
params=query_params,
|
|
41
|
+
)
|
|
42
|
+
result = fetched_response.json()
|
|
43
|
+
|
|
44
|
+
if fetched_response.status_code == 200:
|
|
45
|
+
if result.get("success"):
|
|
46
|
+
return result.get("data")
|
|
47
|
+
else:
|
|
48
|
+
error_message = (
|
|
49
|
+
result.get("errors")
|
|
50
|
+
or "API call failed. Please check your internet connection or try again later"
|
|
51
|
+
)
|
|
52
|
+
return (
|
|
53
|
+
error_message[0].get("message")
|
|
54
|
+
if error_message[0].get("message")
|
|
55
|
+
else "Please provide the necessary requirements or try again later"
|
|
56
|
+
)
|
|
57
|
+
else:
|
|
58
|
+
return f"Request failed with status {fetched_response.status_code}: {fetched_response.text}"
|
|
59
|
+
|
|
60
|
+
def info(self) -> Dict:
|
|
61
|
+
info_resp = self._make_request("GET", "auth/info")
|
|
62
|
+
return info_resp
|
|
63
|
+
|
|
64
|
+
def get_one_item(self, collection_name: str, params=None) -> Dict:
|
|
65
|
+
resp = self._make_request("GET", "incollection/" + collection_name)
|
|
66
|
+
if isinstance(resp, dict):
|
|
67
|
+
if resp.get("items"):
|
|
68
|
+
# return first elem
|
|
69
|
+
return resp.get("items")[0]
|
|
70
|
+
else:
|
|
71
|
+
return resp
|
|
72
|
+
|
|
73
|
+
def get_list(self, collection_name: str, params=None) -> List[Dict] or str:
|
|
74
|
+
get_list_response = self._make_request(
|
|
75
|
+
"GET", "incollection/" + collection_name, params
|
|
76
|
+
)
|
|
77
|
+
if isinstance(get_list_response, str):
|
|
78
|
+
return get_list_response
|
|
79
|
+
else:
|
|
80
|
+
if get_list_response.get("items", False):
|
|
81
|
+
return get_list_response.get("items", [])
|
|
82
|
+
else:
|
|
83
|
+
return get_list_response
|
|
84
|
+
|
|
85
|
+
def create_item(self, collection_name: str, data=None) -> Dict:
|
|
86
|
+
resp = self._make_request(
|
|
87
|
+
"POST", "incollection/" + collection_name, request_data={"reqbody": data}
|
|
88
|
+
)
|
|
89
|
+
if isinstance(resp, dict):
|
|
90
|
+
if resp.get("data"):
|
|
91
|
+
return resp.get("data")
|
|
92
|
+
else:
|
|
93
|
+
return resp
|
|
94
|
+
|
|
95
|
+
def update_item(
|
|
96
|
+
self, collection_name: str, object_id: str, updated_data=None
|
|
97
|
+
) -> Dict:
|
|
98
|
+
resp = self._make_request(
|
|
99
|
+
"PUT",
|
|
100
|
+
"incollection/" + collection_name + "/" + object_id,
|
|
101
|
+
request_data={"reqbody": updated_data},
|
|
102
|
+
)
|
|
103
|
+
if isinstance(resp, dict):
|
|
104
|
+
if resp.get("data"):
|
|
105
|
+
return resp.get("data")
|
|
106
|
+
else:
|
|
107
|
+
return resp
|
|
108
|
+
|
|
109
|
+
def delete_item(self, collection_name: str, object_id: str) -> Dict:
|
|
110
|
+
resp = self._make_request(
|
|
111
|
+
"DELETE", "incollection/" + collection_name + "/" + object_id
|
|
112
|
+
)
|
|
113
|
+
# if isinstance(resp, str):
|
|
114
|
+
# return resp
|
|
115
|
+
# else:
|
|
116
|
+
return resp
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: shipthisapi-python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.1
|
|
4
4
|
Summary: ShipthisAPI utility package
|
|
5
5
|
Home-page: https://github.com/shipthisco/shipthisapi-python
|
|
6
6
|
Author: Mayur Rawte
|
|
7
7
|
Author-email: mayur@shipthis.co
|
|
8
|
-
License: UNKNOWN
|
|
9
|
-
Platform: UNKNOWN
|
|
10
8
|
Classifier: Programming Language :: Python :: 3
|
|
11
9
|
Classifier: License :: OSI Approved :: MIT License
|
|
12
10
|
Classifier: Operating System :: OS Independent
|
|
13
11
|
Description-Content-Type: text/markdown
|
|
12
|
+
Dynamic: author
|
|
13
|
+
Dynamic: author-email
|
|
14
|
+
Dynamic: classifier
|
|
15
|
+
Dynamic: description
|
|
16
|
+
Dynamic: description-content-type
|
|
17
|
+
Dynamic: home-page
|
|
18
|
+
Dynamic: summary
|
|
14
19
|
|
|
15
20
|
# ShipthisAPI Python
|
|
16
21
|
|
|
@@ -60,6 +65,10 @@ print(shipthisapi.info())
|
|
|
60
65
|
|
|
61
66
|
print(shipthisapi.get_list(collection_name='invoice'))
|
|
62
67
|
|
|
68
|
+
# Get all Sea list
|
|
69
|
+
|
|
70
|
+
print(shipthisapi.get_list(collection_name="sea_shipment", params={"count": 2}))
|
|
71
|
+
|
|
63
72
|
|
|
64
73
|
```
|
|
65
74
|
|
|
@@ -88,5 +97,3 @@ If you have any queries related to usage of the api please raise a issue [here](
|
|
|
88
97
|
|
|
89
98
|
|
|
90
99
|
|
|
91
|
-
|
|
92
|
-
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
from typing import Dict, List
|
|
2
|
-
import requests
|
|
3
|
-
class ShipthisAPI:
|
|
4
|
-
base_api_endpoint = 'https://api.shipthis.co/api/v3/'
|
|
5
|
-
|
|
6
|
-
def __init__(self, organisation: str, x_api_key:str, user_type='employee', region_id: str=None, location_id: str=None) -> None:
|
|
7
|
-
self.x_api_key = x_api_key
|
|
8
|
-
self.organisation_id = organisation
|
|
9
|
-
self.user_type = user_type
|
|
10
|
-
self.region_id = region_id
|
|
11
|
-
self.location_id = location_id
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def set_region_location(self, region_id, location_id):
|
|
15
|
-
self.region_id = region_id
|
|
16
|
-
self.location_id = location_id
|
|
17
|
-
|
|
18
|
-
def _make_request(self, method: str, path: str, query_params: str=None, request_data=None) -> None:
|
|
19
|
-
headers = {
|
|
20
|
-
"x-api-key": self.x_api_key,
|
|
21
|
-
"organisation": self.organisation_id,
|
|
22
|
-
"user_type": self.user_type,
|
|
23
|
-
"location": 'new_york'
|
|
24
|
-
}
|
|
25
|
-
resp = requests.request(method, self.base_api_endpoint + path, data=request_data or {}, headers=headers)
|
|
26
|
-
if resp.status_code == 200:
|
|
27
|
-
raw_response = resp.json()
|
|
28
|
-
if raw_response.get("success"):
|
|
29
|
-
return raw_response.get("data")
|
|
30
|
-
|
|
31
|
-
def info(self) -> Dict:
|
|
32
|
-
info_resp = self._make_request('GET', 'auth/info')
|
|
33
|
-
return info_resp
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def get_one_item(self, collection_name: str, params=None) -> Dict:
|
|
38
|
-
resp = self._make_request('GET', 'incollection/' + collection_name)
|
|
39
|
-
if resp.get("items"):
|
|
40
|
-
# return first elem
|
|
41
|
-
return resp.get("items")[0]
|
|
42
|
-
|
|
43
|
-
def get_list(self, collection_name: str, params=None) -> List[Dict]:
|
|
44
|
-
resp = self._make_request('GET', 'incollection/' + collection_name)
|
|
45
|
-
if resp.get("items"):
|
|
46
|
-
return resp.get("items", [])
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def create_item(self, collection_name: str, data=None) -> Dict:
|
|
51
|
-
resp = self._make_request('POST', 'incollection/' + collection_name, request_data={"reqbody": data})
|
|
52
|
-
if resp.get("data"):
|
|
53
|
-
return resp.get("data")
|
|
54
|
-
|
|
55
|
-
def update_item(self, collection_name: str, object_id: str, updated_data=None) -> Dict:
|
|
56
|
-
resp = self._make_request('PUT', 'incollection/' + collection_name + '/' + object_id, request_data={"reqbody": updated_data})
|
|
57
|
-
if resp.get("data"):
|
|
58
|
-
return resp.get("data")
|
|
59
|
-
|
|
60
|
-
def delete_item(self, collection_name: str, object_id: str) -> Dict:
|
|
61
|
-
resp = self._make_request('DELETE', 'incollection/' + collection_name + '/' + object_id)
|
|
62
|
-
return resp
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{shipthisapi-python-1.2.0 → shipthisapi_python-1.3.1}/shipthisapi_python.egg-info/top_level.txt
RENAMED
|
File without changes
|