Skip to content

Commit 0d83381

Browse files
authored
Add bitcoin estimates and registry_url (#26)
* Add bitcoin and registry_url * Fix existing test * Reformat files * Inline black * Add bitcoin test * Autoformat * Pre-commit instructions * Fix flake8 * Remove ;
1 parent bf63bfb commit 0d83381

18 files changed

+315
-42
lines changed

.github/workflows/black.yml

-13
This file was deleted.

.github/workflows/test.yml

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ on:
66
pull_request:
77

88
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-python@v2
14+
- uses: psf/black@stable
15+
916
build-and-test:
1017
runs-on: ubuntu-latest
1118
name: Python Library tests

.pre-commit-config.yaml

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
repos:
2-
- repo: https://github.com/ambv/black
3-
rev: stable
4-
hooks:
5-
- id: black
6-
language_version: python3.6
72
- repo: https://github.com/pre-commit/pre-commit-hooks
8-
rev: v1.2.3
3+
rev: v2.3.0
94
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
108
- id: flake8
119
args: ['--config=.flake8']
10+
- repo: https://github.com/psf/black
11+
rev: 21.6b0
12+
hooks:
13+
- id: black

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ 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.6.0] - 2021-07-14
9+
10+
### Added
11+
12+
- Order responses return a `registry_url` field
13+
- Add support for Bitcoin estimates
14+
815
## [1.5.2] - 2021-03-30
916

1017
### Fixed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ build:
55
python setup.py install
66

77
lint:
8-
pre-commit
8+
pip install -r test-requirements.txt && \
9+
black .
910

1011
test:
1112
pip install -r test-requirements.txt && \

README.md

+32-13
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ model = "Corolla"
139139
year = 1995
140140
patch.estimates.create_mass_estimate(distance_m=distance_m, make=make, model=model, year=year)
141141

142+
# Create a bitcoin estimate
143+
transaction_value_btc_sats = 1000 # [Optional] Pass in the transaction value in satoshis
144+
patch.estimates.create_bitcoin_estimate(transaction_value_btc_sats=transaction_value_btc_sats)
145+
142146
# Retrieve an estimate
143147
estimate_id = 'est_test_1234'
144148
patch.estimates.retrieve_estimate(id=estimate_id)
@@ -218,45 +222,60 @@ patch.preferences.retrieve_preferences(page=page)
218222

219223
## Development
220224

225+
### Pre-commit
226+
227+
This project uses pre-commit to automatically lint code on commit. Set-up lint commit the first time around using
228+
```
229+
pre-commit install
230+
```
231+
232+
### Linter
233+
234+
This project uses black for code formatting. To run the automatic formatting, run:
235+
236+
```bash
237+
make lint
238+
```
239+
221240
### Running tests
222241

223242
Set up the required environment variable:
224243

225-
```
226-
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
244+
```bash
245+
export SANDBOX_API_KEY=<SANDBOX API KEY>
227246
```
228247

229248
Run tests:
230249

231-
```
232-
$ make test
250+
```bash
251+
make test
233252
```
234253

235254
To run an individual test:
236255

237-
```
238-
$ python -m unittest
256+
```bash
257+
python -m unittest test/xxx_test.py
239258
```
240259

241260
### Testing the built package locally
242261

243262
To build the library locally, run:
244263

245-
```
246-
$ make build
264+
```bash
265+
make build
247266
```
248267

249268
In another directory, create a file called `patch.py` and install the local package in this directory:
250269

251-
```
252-
$ touch patch.py
253-
$ pip install ../patch-python
270+
```bash
271+
touch patch.py
272+
pip install ../patch-python
254273
```
255274

256275
Set up the required environment variable:
257276

258-
```
259-
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
277+
```bash
278+
export SANDBOX_API_KEY=<SANDBOX API KEY>
260279
```
261280

262281
To test the package locally, create a python file in a sibling directory and add the following:

patch_api/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from __future__ import absolute_import
1717

18-
__version__ = "1.5.2"
18+
__version__ = "1.6.0"
1919

2020
# import ApiClient
2121
from patch_api.api_client import ApiClient

patch_api/api/estimates_api.py

+159
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,158 @@ class EstimatesApi(object):
4040
"model",
4141
"make",
4242
"year",
43+
"transaction_value_btc_sats",
44+
"timestamp",
4345
]
4446

4547
def __init__(self, api_client=None):
4648
self.api_client = api_client
4749

50+
def create_bitcoin_estimate(
51+
self, create_bitcoin_estimate_request={}, **kwargs
52+
): # noqa: E501
53+
"""Create a bitcoin estimate given a timestamp and transaction value # noqa: E501
54+
55+
Creates a bitcoin estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. # noqa: E501
56+
This method makes a synchronous HTTP request by default. To make an
57+
asynchronous HTTP request, please pass async_req=True
58+
>>> thread = api.create_bitcoin_estimate(create_bitcoin_estimate_request, async_req=True)
59+
>>> result = thread.get()
60+
61+
:param async_req bool: execute request asynchronously
62+
:param CreateBitcoinEstimateRequest create_bitcoin_estimate_request: (required)
63+
:param _preload_content: if False, the urllib3.HTTPResponse object will
64+
be returned without reading/decoding response
65+
data. Default is True.
66+
:param _request_timeout: timeout setting for this request. If one
67+
number provided, it will be total request
68+
timeout. It can also be a pair (tuple) of
69+
(connection, read) timeouts.
70+
:return: EstimateResponse
71+
If the method is called asynchronously,
72+
returns the request thread.
73+
"""
74+
kwargs["_return_http_data_only"] = True
75+
return self.create_bitcoin_estimate_with_http_info(
76+
create_bitcoin_estimate_request, **kwargs
77+
) # noqa: E501
78+
79+
def create_bitcoin_estimate_with_http_info(
80+
self, create_bitcoin_estimate_request, **kwargs
81+
): # noqa: E501
82+
"""Create a bitcoin estimate given a timestamp and transaction value # noqa: E501
83+
84+
Creates a bitcoin estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters, linked to the estimate. # noqa: E501
85+
This method makes a synchronous HTTP request by default. To make an
86+
asynchronous HTTP request, please pass async_req=True
87+
>>> thread = api.create_bitcoin_estimate_with_http_info(create_bitcoin_estimate_request, async_req=True)
88+
>>> result = thread.get()
89+
90+
:param async_req bool: execute request asynchronously
91+
:param CreateBitcoinEstimateRequest create_bitcoin_estimate_request: (required)
92+
:param _return_http_data_only: response data without head status code
93+
and headers
94+
:param _preload_content: if False, the urllib3.HTTPResponse object will
95+
be returned without reading/decoding response
96+
data. Default is True.
97+
:param _request_timeout: timeout setting for this request. If one
98+
number provided, it will be total request
99+
timeout. It can also be a pair (tuple) of
100+
(connection, read) timeouts.
101+
:return: tuple(EstimateResponse, status_code(int), headers(HTTPHeaderDict))
102+
If the method is called asynchronously,
103+
returns the request thread.
104+
"""
105+
106+
local_var_params = locals()
107+
108+
all_params = ["create_bitcoin_estimate_request"] # noqa: E501
109+
all_params.append("async_req")
110+
all_params.append("_return_http_data_only")
111+
all_params.append("_preload_content")
112+
all_params.append("_request_timeout")
113+
all_params.append("mass_g")
114+
all_params.append("total_price_cents_usd")
115+
all_params.append("project_id")
116+
all_params.append("metadata")
117+
all_params.append("distance_m")
118+
all_params.append("transportation_method")
119+
all_params.append("package_mass_g")
120+
all_params.append("create_order")
121+
all_params.append("make")
122+
all_params.append("model")
123+
all_params.append("year")
124+
all_params.append("transaction_value_btc_sats")
125+
all_params.append("timestamp")
126+
127+
for key, val in six.iteritems(local_var_params["kwargs"]):
128+
if key not in all_params:
129+
raise ApiTypeError(
130+
"Got an unexpected keyword argument '%s'"
131+
" to method create_bitcoin_estimate" % key
132+
)
133+
local_var_params[key] = val
134+
del local_var_params["kwargs"]
135+
# verify the required parameter 'create_bitcoin_estimate_request' is set
136+
if (
137+
"create_bitcoin_estimate_request" not in local_var_params
138+
or local_var_params["create_bitcoin_estimate_request"] is None
139+
):
140+
raise ApiValueError(
141+
"Missing the required parameter `create_bitcoin_estimate_request` when calling `create_bitcoin_estimate`"
142+
) # noqa: E501
143+
144+
collection_formats = {}
145+
146+
path_params = {}
147+
148+
query_params = []
149+
for key in kwargs:
150+
query_params.append([key, kwargs.get(key)])
151+
152+
header_params = {}
153+
154+
form_params = []
155+
local_var_files = {}
156+
157+
body_params = None
158+
if "create_bitcoin_estimate_request" in local_var_params:
159+
body_params = local_var_params["create_bitcoin_estimate_request"]
160+
# HTTP header `Accept`
161+
header_params["Accept"] = self.api_client.select_header_accept(
162+
["application/json"]
163+
) # noqa: E501
164+
165+
# HTTP header `Content-Type`
166+
header_params[
167+
"Content-Type"
168+
] = self.api_client.select_header_content_type( # noqa: E501
169+
["application/json"]
170+
) # noqa: E501
171+
172+
# Authentication setting
173+
auth_settings = ["bearer_auth"] # noqa: E501
174+
175+
return self.api_client.call_api(
176+
"/v1/estimates/crypto/btc",
177+
"POST",
178+
path_params,
179+
query_params,
180+
header_params,
181+
body=body_params,
182+
post_params=form_params,
183+
files=local_var_files,
184+
response_type="EstimateResponse", # noqa: E501
185+
auth_settings=auth_settings,
186+
async_req=local_var_params.get("async_req"),
187+
_return_http_data_only=local_var_params.get(
188+
"_return_http_data_only"
189+
), # noqa: E501
190+
_preload_content=local_var_params.get("_preload_content", True),
191+
_request_timeout=local_var_params.get("_request_timeout"),
192+
collection_formats=collection_formats,
193+
)
194+
48195
def create_flight_estimate(
49196
self, create_flight_estimate_request={}, **kwargs
50197
): # noqa: E501
@@ -119,6 +266,8 @@ def create_flight_estimate_with_http_info(
119266
all_params.append("make")
120267
all_params.append("model")
121268
all_params.append("year")
269+
all_params.append("transaction_value_btc_sats")
270+
all_params.append("timestamp")
122271

123272
for key, val in six.iteritems(local_var_params["kwargs"]):
124273
if key not in all_params:
@@ -262,6 +411,8 @@ def create_mass_estimate_with_http_info(
262411
all_params.append("make")
263412
all_params.append("model")
264413
all_params.append("year")
414+
all_params.append("transaction_value_btc_sats")
415+
all_params.append("timestamp")
265416

266417
for key, val in six.iteritems(local_var_params["kwargs"]):
267418
if key not in all_params:
@@ -405,6 +556,8 @@ def create_shipping_estimate_with_http_info(
405556
all_params.append("make")
406557
all_params.append("model")
407558
all_params.append("year")
559+
all_params.append("transaction_value_btc_sats")
560+
all_params.append("timestamp")
408561

409562
for key, val in six.iteritems(local_var_params["kwargs"]):
410563
if key not in all_params:
@@ -548,6 +701,8 @@ def create_vehicle_estimate_with_http_info(
548701
all_params.append("make")
549702
all_params.append("model")
550703
all_params.append("year")
704+
all_params.append("transaction_value_btc_sats")
705+
all_params.append("timestamp")
551706

552707
for key, val in six.iteritems(local_var_params["kwargs"]):
553708
if key not in all_params:
@@ -685,6 +840,8 @@ def retrieve_estimate_with_http_info(self, id, **kwargs): # noqa: E501
685840
all_params.append("make")
686841
all_params.append("model")
687842
all_params.append("year")
843+
all_params.append("transaction_value_btc_sats")
844+
all_params.append("timestamp")
688845

689846
for key, val in six.iteritems(local_var_params["kwargs"]):
690847
if key not in all_params:
@@ -812,6 +969,8 @@ def retrieve_estimates_with_http_info(self, **kwargs): # noqa: E501
812969
all_params.append("make")
813970
all_params.append("model")
814971
all_params.append("year")
972+
all_params.append("transaction_value_btc_sats")
973+
all_params.append("timestamp")
815974

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

0 commit comments

Comments
 (0)