Skip to content

Commit

Permalink
Add bitcoin estimates and registry_url (#26)
Browse files Browse the repository at this point in the history
* Add bitcoin and registry_url

* Fix existing test

* Reformat files

* Inline black

* Add bitcoin test

* Autoformat

* Pre-commit instructions

* Fix flake8

* Remove ;
  • Loading branch information
pcothenet authored Jul 14, 2021
1 parent bf63bfb commit 0d83381
Show file tree
Hide file tree
Showing 18 changed files with 315 additions and 42 deletions.
13 changes: 0 additions & 13 deletions .github/workflows/black.yml

This file was deleted.

7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ on:
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: psf/black@stable

build-and-test:
runs-on: ubuntu-latest
name: Python Library tests
Expand Down
14 changes: 8 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
repos:
- repo: https://github.com/ambv/black
rev: stable
hooks:
- id: black
language_version: python3.6
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: flake8
args: ['--config=.flake8']
- repo: https://github.com/psf/black
rev: 21.6b0
hooks:
- id: black
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.6.0] - 2021-07-14

### Added

- Order responses return a `registry_url` field
- Add support for Bitcoin estimates

## [1.5.2] - 2021-03-30

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ build:
python setup.py install

lint:
pre-commit
pip install -r test-requirements.txt && \
black .

test:
pip install -r test-requirements.txt && \
Expand Down
45 changes: 32 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ model = "Corolla"
year = 1995
patch.estimates.create_mass_estimate(distance_m=distance_m, make=make, model=model, year=year)

# Create a bitcoin estimate
transaction_value_btc_sats = 1000 # [Optional] Pass in the transaction value in satoshis
patch.estimates.create_bitcoin_estimate(transaction_value_btc_sats=transaction_value_btc_sats)

# Retrieve an estimate
estimate_id = 'est_test_1234'
patch.estimates.retrieve_estimate(id=estimate_id)
Expand Down Expand Up @@ -218,45 +222,60 @@ patch.preferences.retrieve_preferences(page=page)

## Development

### Pre-commit

This project uses pre-commit to automatically lint code on commit. Set-up lint commit the first time around using
```
pre-commit install
```

### Linter

This project uses black for code formatting. To run the automatic formatting, run:

```bash
make lint
```

### Running tests

Set up the required environment variable:

```
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
```bash
export SANDBOX_API_KEY=<SANDBOX API KEY>
```

Run tests:

```
$ make test
```bash
make test
```

To run an individual test:

```
$ python -m unittest
```bash
python -m unittest test/xxx_test.py
```

### Testing the built package locally

To build the library locally, run:

```
$ make build
```bash
make build
```

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

```
$ touch patch.py
$ pip install ../patch-python
```bash
touch patch.py
pip install ../patch-python
```

Set up the required environment variable:

```
$ export SANDBOX_API_KEY=<SANDBOX API KEY>
```bash
export SANDBOX_API_KEY=<SANDBOX API KEY>
```

To test the package locally, create a python file in a sibling directory and add the following:
Expand Down
2 changes: 1 addition & 1 deletion patch_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from __future__ import absolute_import

__version__ = "1.5.2"
__version__ = "1.6.0"

# import ApiClient
from patch_api.api_client import ApiClient
Expand Down
159 changes: 159 additions & 0 deletions patch_api/api/estimates_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,158 @@ class EstimatesApi(object):
"model",
"make",
"year",
"transaction_value_btc_sats",
"timestamp",
]

def __init__(self, api_client=None):
self.api_client = api_client

def create_bitcoin_estimate(
self, create_bitcoin_estimate_request={}, **kwargs
): # noqa: E501
"""Create a bitcoin estimate given a timestamp and transaction value # noqa: E501
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
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.create_bitcoin_estimate(create_bitcoin_estimate_request, async_req=True)
>>> result = thread.get()
:param async_req bool: execute request asynchronously
:param CreateBitcoinEstimateRequest create_bitcoin_estimate_request: (required)
:param _preload_content: if False, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Default is True.
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:return: EstimateResponse
If the method is called asynchronously,
returns the request thread.
"""
kwargs["_return_http_data_only"] = True
return self.create_bitcoin_estimate_with_http_info(
create_bitcoin_estimate_request, **kwargs
) # noqa: E501

def create_bitcoin_estimate_with_http_info(
self, create_bitcoin_estimate_request, **kwargs
): # noqa: E501
"""Create a bitcoin estimate given a timestamp and transaction value # noqa: E501
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
This method makes a synchronous HTTP request by default. To make an
asynchronous HTTP request, please pass async_req=True
>>> thread = api.create_bitcoin_estimate_with_http_info(create_bitcoin_estimate_request, async_req=True)
>>> result = thread.get()
:param async_req bool: execute request asynchronously
:param CreateBitcoinEstimateRequest create_bitcoin_estimate_request: (required)
:param _return_http_data_only: response data without head status code
and headers
:param _preload_content: if False, the urllib3.HTTPResponse object will
be returned without reading/decoding response
data. Default is True.
:param _request_timeout: timeout setting for this request. If one
number provided, it will be total request
timeout. It can also be a pair (tuple) of
(connection, read) timeouts.
:return: tuple(EstimateResponse, status_code(int), headers(HTTPHeaderDict))
If the method is called asynchronously,
returns the request thread.
"""

local_var_params = locals()

all_params = ["create_bitcoin_estimate_request"] # noqa: E501
all_params.append("async_req")
all_params.append("_return_http_data_only")
all_params.append("_preload_content")
all_params.append("_request_timeout")
all_params.append("mass_g")
all_params.append("total_price_cents_usd")
all_params.append("project_id")
all_params.append("metadata")
all_params.append("distance_m")
all_params.append("transportation_method")
all_params.append("package_mass_g")
all_params.append("create_order")
all_params.append("make")
all_params.append("model")
all_params.append("year")
all_params.append("transaction_value_btc_sats")
all_params.append("timestamp")

for key, val in six.iteritems(local_var_params["kwargs"]):
if key not in all_params:
raise ApiTypeError(
"Got an unexpected keyword argument '%s'"
" to method create_bitcoin_estimate" % key
)
local_var_params[key] = val
del local_var_params["kwargs"]
# verify the required parameter 'create_bitcoin_estimate_request' is set
if (
"create_bitcoin_estimate_request" not in local_var_params
or local_var_params["create_bitcoin_estimate_request"] is None
):
raise ApiValueError(
"Missing the required parameter `create_bitcoin_estimate_request` when calling `create_bitcoin_estimate`"
) # noqa: E501

collection_formats = {}

path_params = {}

query_params = []
for key in kwargs:
query_params.append([key, kwargs.get(key)])

header_params = {}

form_params = []
local_var_files = {}

body_params = None
if "create_bitcoin_estimate_request" in local_var_params:
body_params = local_var_params["create_bitcoin_estimate_request"]
# HTTP header `Accept`
header_params["Accept"] = self.api_client.select_header_accept(
["application/json"]
) # noqa: E501

# HTTP header `Content-Type`
header_params[
"Content-Type"
] = self.api_client.select_header_content_type( # noqa: E501
["application/json"]
) # noqa: E501

# Authentication setting
auth_settings = ["bearer_auth"] # noqa: E501

return self.api_client.call_api(
"/v1/estimates/crypto/btc",
"POST",
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type="EstimateResponse", # noqa: E501
auth_settings=auth_settings,
async_req=local_var_params.get("async_req"),
_return_http_data_only=local_var_params.get(
"_return_http_data_only"
), # noqa: E501
_preload_content=local_var_params.get("_preload_content", True),
_request_timeout=local_var_params.get("_request_timeout"),
collection_formats=collection_formats,
)

def create_flight_estimate(
self, create_flight_estimate_request={}, **kwargs
): # noqa: E501
Expand Down Expand Up @@ -119,6 +266,8 @@ def create_flight_estimate_with_http_info(
all_params.append("make")
all_params.append("model")
all_params.append("year")
all_params.append("transaction_value_btc_sats")
all_params.append("timestamp")

for key, val in six.iteritems(local_var_params["kwargs"]):
if key not in all_params:
Expand Down Expand Up @@ -262,6 +411,8 @@ def create_mass_estimate_with_http_info(
all_params.append("make")
all_params.append("model")
all_params.append("year")
all_params.append("transaction_value_btc_sats")
all_params.append("timestamp")

for key, val in six.iteritems(local_var_params["kwargs"]):
if key not in all_params:
Expand Down Expand Up @@ -405,6 +556,8 @@ def create_shipping_estimate_with_http_info(
all_params.append("make")
all_params.append("model")
all_params.append("year")
all_params.append("transaction_value_btc_sats")
all_params.append("timestamp")

for key, val in six.iteritems(local_var_params["kwargs"]):
if key not in all_params:
Expand Down Expand Up @@ -548,6 +701,8 @@ def create_vehicle_estimate_with_http_info(
all_params.append("make")
all_params.append("model")
all_params.append("year")
all_params.append("transaction_value_btc_sats")
all_params.append("timestamp")

for key, val in six.iteritems(local_var_params["kwargs"]):
if key not in all_params:
Expand Down Expand Up @@ -685,6 +840,8 @@ def retrieve_estimate_with_http_info(self, id, **kwargs): # noqa: E501
all_params.append("make")
all_params.append("model")
all_params.append("year")
all_params.append("transaction_value_btc_sats")
all_params.append("timestamp")

for key, val in six.iteritems(local_var_params["kwargs"]):
if key not in all_params:
Expand Down Expand Up @@ -812,6 +969,8 @@ def retrieve_estimates_with_http_info(self, **kwargs): # noqa: E501
all_params.append("make")
all_params.append("model")
all_params.append("year")
all_params.append("transaction_value_btc_sats")
all_params.append("timestamp")

for key, val in six.iteritems(local_var_params["kwargs"]):
if key not in all_params:
Expand Down
Loading

0 comments on commit 0d83381

Please sign in to comment.