Skip to content

Commit 4b06c67

Browse files
authoredFeb 9, 2021
[1.3.0] Add support for Flight/Vehicle/Shipping estimates (#11)
1 parent 3fbd09a commit 4b06c67

15 files changed

+709
-21
lines changed
 

‎CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.3.0] - 2021-02-08
9+
10+
### Added
11+
12+
- Adds support for creating Shipping/Flight/Vehicle estimates.
13+
- Sets the library version to 1.3.0 to track the [Patch Ruby SDK](https://github.com/patch-technology/patch-ruby) and [Patch Node SDK](https://github.com/patch-technology/patch-node).
14+
815
## [1.0.1] - 2021-01-22
916

1017
### Added
1118

1219
- Pre-release of v1 Library
1320
- Adds support for Orders, Estimates, Projects and Preferences
14-

‎Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
SHELL = /bin/bash
22

33
build:
4-
pip install -r requirements.txt \
4+
pip install -r requirements.txt && \
55
python setup.py install
66

77
lint:
@@ -12,4 +12,4 @@ test:
1212
pip install -r requirements.txt && \
1313
python -m unittest discover test/
1414

15-
.PHONY: build test lint publish
15+
.PHONY: build lint test

‎README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For a complete API reference, check out [Patch's API Reference.](https://docs.us
1212

1313
Add the library to your `requirements.txt` file:
1414
```txt
15-
patch_api >= 1.0.1
15+
patch_api >= 1.3.0
1616
```
1717

1818
Then run:
@@ -105,14 +105,30 @@ import patch_api
105105
patch = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY'))
106106

107107
# Create an estimate
108-
109108
mass_g = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne)
110109
patch.estimates.create_estimate(mass_g=mass_g)
111110

112111
## You can also specify a project-id field (optional) to be used instead of the preferred one
113112
project_id = 'pro_test_1234' # Pass in the project's ID
114113
patch.estimates.create_estimate(mass_g=mass_g, project_id=project_id)
115114

115+
# Create a flight estimate
116+
distance_m = 1_000_000 # Pass in the distance traveled in meters
117+
patch.estimates.create_estimate(distance_m=distance_m)
118+
119+
# Create a shipping estimate
120+
distance_m = 1_000_000 # Pass in the distance traveled in meters
121+
transportation_method = "rail"
122+
package_mass_g = 5000
123+
patch.estimates.create_estimate(distance_m=distance_m, transportation_method=transportation_method, package_mass_g=package_mass_g)
124+
125+
# Create a vehicle estimate
126+
distance_m = 1_000_000 # Pass in the distance traveled in meters
127+
make = "Toyota"
128+
model = "Corolla"
129+
year = 1995
130+
patch.estimates.create_estimate(distance_m=distance_m, make=make, model=model, year=year)
131+
116132
# Retrieve an estimate
117133
estimate_id = 'est_test_1234'
118134
patch.estimates.retrieve_estimate(id=estimate_id)

‎patch_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from __future__ import absolute_import
1717

18-
__version__ = "1.0.0"
18+
__version__ = "1.3.0"
1919

2020
# import ApiClient
2121
from patch_api.api_client import ApiClient

‎patch_api/api/estimates_api.py

Lines changed: 463 additions & 1 deletion
Large diffs are not rendered by default.

‎patch_api/api/orders_api.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ class OrdersApi(object):
2828
Do not edit the class manually.
2929
"""
3030

31-
ALLOWED_QUERY_PARAMS = ["mass_g", "price_cents_usd", "project_id", "page"]
31+
ALLOWED_QUERY_PARAMS = [
32+
"mass_g",
33+
"price_cents_usd",
34+
"project_id",
35+
"page",
36+
"distance_m",
37+
"transportation_method",
38+
"package_mass_g",
39+
"create_order",
40+
"model",
41+
"make",
42+
"year",
43+
]
3244

3345
def __init__(self, api_client=None):
3446
self.api_client = api_client
@@ -94,6 +106,13 @@ def cancel_order_with_http_info(self, id, **kwargs): # noqa: E501
94106
all_params.append("price_cents_usd")
95107
all_params.append("project_id")
96108
all_params.append("metadata")
109+
all_params.append("distance_m")
110+
all_params.append("transportation_method")
111+
all_params.append("package_mass_g")
112+
all_params.append("create_order")
113+
all_params.append("make")
114+
all_params.append("model")
115+
all_params.append("year")
97116

98117
for key, val in six.iteritems(local_var_params["kwargs"]):
99118
if key not in all_params:
@@ -216,6 +235,13 @@ def create_order_with_http_info(self, create_order_request, **kwargs): # noqa:
216235
all_params.append("price_cents_usd")
217236
all_params.append("project_id")
218237
all_params.append("metadata")
238+
all_params.append("distance_m")
239+
all_params.append("transportation_method")
240+
all_params.append("package_mass_g")
241+
all_params.append("create_order")
242+
all_params.append("make")
243+
all_params.append("model")
244+
all_params.append("year")
219245

220246
for key, val in six.iteritems(local_var_params["kwargs"]):
221247
if key not in all_params:
@@ -346,6 +372,13 @@ def place_order_with_http_info(self, id, **kwargs): # noqa: E501
346372
all_params.append("price_cents_usd")
347373
all_params.append("project_id")
348374
all_params.append("metadata")
375+
all_params.append("distance_m")
376+
all_params.append("transportation_method")
377+
all_params.append("package_mass_g")
378+
all_params.append("create_order")
379+
all_params.append("make")
380+
all_params.append("model")
381+
all_params.append("year")
349382

350383
for key, val in six.iteritems(local_var_params["kwargs"]):
351384
if key not in all_params:
@@ -466,6 +499,13 @@ def retrieve_order_with_http_info(self, id, **kwargs): # noqa: E501
466499
all_params.append("price_cents_usd")
467500
all_params.append("project_id")
468501
all_params.append("metadata")
502+
all_params.append("distance_m")
503+
all_params.append("transportation_method")
504+
all_params.append("package_mass_g")
505+
all_params.append("create_order")
506+
all_params.append("make")
507+
all_params.append("model")
508+
all_params.append("year")
469509

470510
for key, val in six.iteritems(local_var_params["kwargs"]):
471511
if key not in all_params:
@@ -586,6 +626,13 @@ def retrieve_orders_with_http_info(self, **kwargs): # noqa: E501
586626
all_params.append("price_cents_usd")
587627
all_params.append("project_id")
588628
all_params.append("metadata")
629+
all_params.append("distance_m")
630+
all_params.append("transportation_method")
631+
all_params.append("package_mass_g")
632+
all_params.append("create_order")
633+
all_params.append("make")
634+
all_params.append("model")
635+
all_params.append("year")
589636

590637
for key, val in six.iteritems(local_var_params["kwargs"]):
591638
if key not in all_params:

‎patch_api/api/preferences_api.py

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ class PreferencesApi(object):
2828
Do not edit the class manually.
2929
"""
3030

31-
ALLOWED_QUERY_PARAMS = ["mass_g", "price_cents_usd", "project_id", "page"]
31+
ALLOWED_QUERY_PARAMS = [
32+
"mass_g",
33+
"price_cents_usd",
34+
"project_id",
35+
"page",
36+
"distance_m",
37+
"transportation_method",
38+
"package_mass_g",
39+
"create_order",
40+
"model",
41+
"make",
42+
"year",
43+
]
3244

3345
def __init__(self, api_client=None):
3446
self.api_client = api_client
@@ -98,6 +110,13 @@ def create_preference_with_http_info(
98110
all_params.append("price_cents_usd")
99111
all_params.append("project_id")
100112
all_params.append("metadata")
113+
all_params.append("distance_m")
114+
all_params.append("transportation_method")
115+
all_params.append("package_mass_g")
116+
all_params.append("create_order")
117+
all_params.append("make")
118+
all_params.append("model")
119+
all_params.append("year")
101120

102121
for key, val in six.iteritems(local_var_params["kwargs"]):
103122
if key not in all_params:
@@ -228,6 +247,13 @@ def delete_preference_with_http_info(self, id, **kwargs): # noqa: E501
228247
all_params.append("price_cents_usd")
229248
all_params.append("project_id")
230249
all_params.append("metadata")
250+
all_params.append("distance_m")
251+
all_params.append("transportation_method")
252+
all_params.append("package_mass_g")
253+
all_params.append("create_order")
254+
all_params.append("make")
255+
all_params.append("model")
256+
all_params.append("year")
231257

232258
for key, val in six.iteritems(local_var_params["kwargs"]):
233259
if key not in all_params:
@@ -348,6 +374,13 @@ def retrieve_preference_with_http_info(self, id, **kwargs): # noqa: E501
348374
all_params.append("price_cents_usd")
349375
all_params.append("project_id")
350376
all_params.append("metadata")
377+
all_params.append("distance_m")
378+
all_params.append("transportation_method")
379+
all_params.append("package_mass_g")
380+
all_params.append("create_order")
381+
all_params.append("make")
382+
all_params.append("model")
383+
all_params.append("year")
351384

352385
for key, val in six.iteritems(local_var_params["kwargs"]):
353386
if key not in all_params:
@@ -468,6 +501,13 @@ def retrieve_preferences_with_http_info(self, **kwargs): # noqa: E501
468501
all_params.append("price_cents_usd")
469502
all_params.append("project_id")
470503
all_params.append("metadata")
504+
all_params.append("distance_m")
505+
all_params.append("transportation_method")
506+
all_params.append("package_mass_g")
507+
all_params.append("create_order")
508+
all_params.append("make")
509+
all_params.append("model")
510+
all_params.append("year")
471511

472512
for key, val in six.iteritems(local_var_params["kwargs"]):
473513
if key not in all_params:

‎patch_api/api/projects_api.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ class ProjectsApi(object):
2828
Do not edit the class manually.
2929
"""
3030

31-
ALLOWED_QUERY_PARAMS = ["mass_g", "price_cents_usd", "project_id", "page"]
31+
ALLOWED_QUERY_PARAMS = [
32+
"mass_g",
33+
"price_cents_usd",
34+
"project_id",
35+
"page",
36+
"distance_m",
37+
"transportation_method",
38+
"package_mass_g",
39+
"create_order",
40+
"model",
41+
"make",
42+
"year",
43+
]
3244

3345
def __init__(self, api_client=None):
3446
self.api_client = api_client
@@ -94,6 +106,13 @@ def retrieve_project_with_http_info(self, id, **kwargs): # noqa: E501
94106
all_params.append("price_cents_usd")
95107
all_params.append("project_id")
96108
all_params.append("metadata")
109+
all_params.append("distance_m")
110+
all_params.append("transportation_method")
111+
all_params.append("package_mass_g")
112+
all_params.append("create_order")
113+
all_params.append("make")
114+
all_params.append("model")
115+
all_params.append("year")
97116

98117
for key, val in six.iteritems(local_var_params["kwargs"]):
99118
if key not in all_params:
@@ -214,6 +233,13 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501
214233
all_params.append("price_cents_usd")
215234
all_params.append("project_id")
216235
all_params.append("metadata")
236+
all_params.append("distance_m")
237+
all_params.append("transportation_method")
238+
all_params.append("package_mass_g")
239+
all_params.append("create_order")
240+
all_params.append("make")
241+
all_params.append("model")
242+
all_params.append("year")
217243

218244
for key, val in six.iteritems(local_var_params["kwargs"]):
219245
if key not in all_params:

‎patch_api/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init__(
9191
self.default_headers[header_name] = header_value
9292
self.cookie = cookie
9393
# Set default User-Agent.
94-
self.user_agent = "OpenAPI-Generator/1.0.0/python"
94+
self.user_agent = "OpenAPI-Generator/1.3.0/python"
9595

9696
def __del__(self):
9797
if self._pool:

‎patch_api/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def to_debug_report(self):
341341
"OS: {env}\n"
342342
"Python Version: {pyversion}\n"
343343
"Version of the API: v1\n"
344-
"SDK Package Version: 1.0.0".format(env=sys.platform, pyversion=sys.version)
344+
"SDK Package Version: 1.3.0".format(env=sys.platform, pyversion=sys.version)
345345
)
346346

347347
def get_host_settings(self):

‎patch_api/models/estimate.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,19 @@ class Estimate(object):
3333
attribute_map (dict): The key is attribute name
3434
and the value is json key in definition.
3535
"""
36-
openapi_types = {"id": "str", "production": "bool", "type": "str", "order": "Order"}
36+
openapi_types = {
37+
"id": "str",
38+
"production": "bool",
39+
"type": "str",
40+
"mass_g": "int",
41+
"order": "Order",
42+
}
3743

3844
attribute_map = {
3945
"id": "id",
4046
"production": "production",
4147
"type": "type",
48+
"mass_g": "mass_g",
4249
"order": "order",
4350
}
4451

@@ -47,6 +54,7 @@ def __init__(
4754
id=None,
4855
production=None,
4956
type=None,
57+
mass_g=None,
5058
order=None,
5159
local_vars_configuration=None,
5260
): # noqa: E501
@@ -58,12 +66,15 @@ def __init__(
5866
self._id = None
5967
self._production = None
6068
self._type = None
69+
self._mass_g = None
6170
self._order = None
6271
self.discriminator = None
6372

6473
self.id = id
6574
self.production = production
6675
self.type = type
76+
if mass_g is not None:
77+
self.mass_g = mass_g
6778
self.order = order
6879

6980
@property
@@ -126,7 +137,7 @@ def production(self, production):
126137
def type(self):
127138
"""Gets the type of this Estimate. # noqa: E501
128139
129-
The type of estimate. Currently mass is the only supported value. # noqa: E501
140+
The type of estimate. Available types are mass, flight, shipping, and vehicle. # noqa: E501
130141
131142
:return: The type of this Estimate. # noqa: E501
132143
:rtype: str
@@ -137,7 +148,7 @@ def type(self):
137148
def type(self, type):
138149
"""Sets the type of this Estimate.
139150
140-
The type of estimate. Currently mass is the only supported value. # noqa: E501
151+
The type of estimate. Available types are mass, flight, shipping, and vehicle. # noqa: E501
141152
142153
:param type: The type of this Estimate. # noqa: E501
143154
:type: str
@@ -151,6 +162,29 @@ def type(self, type):
151162

152163
self._type = type
153164

165+
@property
166+
def mass_g(self):
167+
"""Gets the mass_g of this Estimate. # noqa: E501
168+
169+
The estimated mass in grams for this estimate. # noqa: E501
170+
171+
:return: The mass_g of this Estimate. # noqa: E501
172+
:rtype: int
173+
"""
174+
return self._mass_g
175+
176+
@mass_g.setter
177+
def mass_g(self, mass_g):
178+
"""Sets the mass_g of this Estimate.
179+
180+
The estimated mass in grams for this estimate. # noqa: E501
181+
182+
:param mass_g: The mass_g of this Estimate. # noqa: E501
183+
:type: int
184+
"""
185+
186+
self._mass_g = mass_g
187+
154188
@property
155189
def order(self):
156190
"""Gets the order of this Estimate. # noqa: E501

‎requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ six >= 1.10
33
python_dateutil >= 2.5.3
44
setuptools >= 21.0.0
55
urllib3 >= 1.15.1
6-
pre-commit >= 2.9.3
6+
pre-commit >= 2.10.0

‎setup.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
from setuptools import setup, find_packages # noqa: H301
1313

1414
NAME = "patch-api"
15-
VERSION = "1.0.1"
15+
VERSION = "1.3.0"
1616
# To install the library, run the following
1717
#
1818
# python setup.py install
1919
#
2020
# prerequisite: setuptools
2121
# http://pypi.python.org/pypi/setuptools
2222

23-
REQUIRES = ["urllib3 >= 1.25.3", "python-dateutil", "certifi"]
23+
REQUIRES = [
24+
"urllib3 >= 1.25.3",
25+
"python-dateutil",
26+
]
2427

2528
setup(
2629
name=NAME,
@@ -35,7 +38,6 @@
3538
packages=find_packages(exclude=["test", "tests"]),
3639
include_package_data=True,
3740
long_description="""\
38-
The core API used to integrate with Patch's service.
41+
The core API used to integrate with Patch's service # noqa: E501
3942
""",
40-
long_description_content_type="text/x-rst",
4143
)

‎test/test_estimates_api.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,61 @@ def test_create_and_retrieve_mass_estimate(self):
4343
retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id)
4444
self.assertTrue(retrieved_estimate)
4545

46+
def test_create_and_retrieve_flight_estimate(self):
47+
"""Test case for create_flight_estimate
48+
49+
Create an estimate based on the distance in meters flown by an airplane # noqa: E501
50+
"""
51+
distance_m = 10000000
52+
estimate = self.api.create_flight_estimate(
53+
distance_m=distance_m, create_order=True
54+
)
55+
self.assertEqual(estimate.data.type, "flight")
56+
self.assertEqual(estimate.data.order.mass_g, 1032000)
57+
self.assertEqual(estimate.data.mass_g, 1032000)
58+
59+
retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id)
60+
self.assertTrue(retrieved_estimate)
61+
62+
def test_create_and_retrieve_shipping_estimate(self):
63+
"""Test case for create_shipping_estimate
64+
65+
Create an estimate based on the shipping distance, transportation method, and package mass # noqa: E501
66+
"""
67+
distance_m = 10000000
68+
package_mass_g = 1000
69+
transportation_method = "sea"
70+
estimate = self.api.create_shipping_estimate(
71+
distance_m=distance_m,
72+
package_mass_g=package_mass_g,
73+
transportation_method=transportation_method,
74+
create_order=False,
75+
)
76+
self.assertEqual(estimate.data.order, None)
77+
self.assertEqual(estimate.data.type, "shipping")
78+
self.assertEqual(estimate.data.mass_g, 373)
79+
80+
retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id)
81+
self.assertTrue(retrieved_estimate)
82+
83+
def test_create_and_retrieve_vehicle_estimate(self):
84+
"""Test case for create_vehicle_estimate
85+
86+
Create an estimate based on the vehicle distance, transportation method, and package mass # noqa: E501
87+
"""
88+
distance_m = 10000000
89+
make = "Toyota"
90+
model = "Corolla"
91+
year = 1995
92+
estimate = self.api.create_vehicle_estimate(
93+
distance_m=distance_m, model=model, make=make, year=year
94+
)
95+
self.assertEqual(estimate.data.type, "vehicle")
96+
self.assertEqual(estimate.data.mass_g, 5719674)
97+
98+
retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id)
99+
self.assertTrue(retrieved_estimate)
100+
46101

47102
if __name__ == "__main__":
48103
unittest.main()

‎test/test_projects_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_retrieve_projects(self):
5959
self.assertTrue(project.description)
6060
self.assertEqual(project.country, "US")
6161
self.assertEqual(project.type, "biomass")
62-
self.assertEqual(project.developer, "Carbo Culture Biochar")
62+
self.assertEqual(project.developer, "Carbo Culture")
6363
self.assertTrue(isinstance(project.photos, list))
6464

6565

0 commit comments

Comments
 (0)
Please sign in to comment.