Skip to content

Add /estimates/ecommerce API support #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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.24.2] - 2022-08-10

### Added

- Adds `patch.estimates.create_ecommerce_estimate` method

## [1.24.0] - 2022-07-22

### Added
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,20 +137,24 @@ patch.estimates.create_mass_estimate(mass_g=mass_g, project_id=project_id)

# Create a flight estimate
distance_m = 1_000_000 # Pass in the distance traveled in meters
patch.estimates.create_mass_estimate(distance_m=distance_m)
patch.estimates.create_flight_estimate(distance_m=distance_m)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈


# Create a shipping estimate
# Create an ecommerce estimate
distance_m = 1_000_000 # Pass in the distance traveled in meters
transportation_method = "rail"
package_mass_g = 5000
patch.estimates.create_mass_estimate(distance_m=distance_m, transportation_method=transportation_method, package_mass_g=package_mass_g)
patch.estimates.create_ecommerce_estimate(
distance_m=distance_m,
transportation_method=transportation_method,
package_mass_g=package_mass_g
)

# Create a vehicle estimate
distance_m = 1_000_000 # Pass in the distance traveled in meters
make = "Toyota"
model = "Corolla"
year = 1995
patch.estimates.create_mass_estimate(distance_m=distance_m, make=make, model=model, year=year)
patch.estimates.create_vehicle_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
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.24.1"
__version__ = "1.24.2"

# import ApiClient
from patch_api.api_client import ApiClient
Expand Down
190 changes: 190 additions & 0 deletions patch_api/api/estimates_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,196 @@ def create_bitcoin_estimate_with_http_info(
collection_formats=collection_formats,
)

def create_ecommerce_estimate(
self, create_ecommerce_estimate_request={}, **kwargs
): # noqa: E501
"""Create an e-commerce estimate given the distance traveled in meters, package weight, and transportation method. # noqa: E501

Creates a e-commerce estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters. # 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_ecommerce_estimate(create_ecommerce_estimate_request, async_req=True)
>>> result = thread.get()

:param async_req bool: execute request asynchronously
:param CreateEcommerceEstimateRequest create_ecommerce_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_ecommerce_estimate_with_http_info(
create_ecommerce_estimate_request, **kwargs
) # noqa: E501

def create_ecommerce_estimate_with_http_info(
self, create_ecommerce_estimate_request, **kwargs
): # noqa: E501
"""Create an e-commerce estimate given the distance traveled in meters, package weight, and transportation method. # noqa: E501

Creates a e-commerce estimate for the amount of CO2 to be compensated. An order in the `draft` state may be created based on the parameters. # 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_ecommerce_estimate_with_http_info(create_ecommerce_estimate_request, async_req=True)
>>> result = thread.get()

:param async_req bool: execute request asynchronously
:param CreateEcommerceEstimateRequest create_ecommerce_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_ecommerce_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("transaction_value_eth_gwei")
all_params.append("gas_used")
all_params.append("transaction_value_btc_sats")
all_params.append("average_daily_balance_btc_sats")
all_params.append("average_daily_balance_eth_gwei")
all_params.append("timestamp")
all_params.append("origin_airport")
all_params.append("destination_airport")
all_params.append("aircraft_code")
all_params.append("cabin_class")
all_params.append("passenger_count")
all_params.append("state")
all_params.append("country_code")
all_params.append("city")
all_params.append("region")
all_params.append("star_rating")
all_params.append("number_of_nights")
all_params.append("number_of_rooms")
all_params.append("vintage_year")
all_params.append("total_price")
all_params.append("currency")
all_params.append("amount")
all_params.append("unit")
all_params.append("issued_to")
all_params.append("cargo_type")
all_params.append("container_size_code")
all_params.append("destination_country_code")
all_params.append("destination_locode")
all_params.append("destination_postal_code")
all_params.append("emissions_scope")
all_params.append("freight_mass_g")
all_params.append("freight_volume_cubic_m")
all_params.append("fuel_type")
all_params.append("number_of_containers")
all_params.append("origin_country_code")
all_params.append("origin_locode")
all_params.append("origin_postal_code")
all_params.append("truck_weight_t")
all_params.append("vessel_imo")

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_ecommerce_estimate" % key
)
local_var_params[key] = val
del local_var_params["kwargs"]
# verify the required parameter 'create_ecommerce_estimate_request' is set
if (
"create_ecommerce_estimate_request" not in local_var_params
or local_var_params["create_ecommerce_estimate_request"] is None
):
raise ApiValueError(
"Missing the required parameter `create_ecommerce_estimate_request` when calling `create_ecommerce_estimate`"
) # noqa: E501

collection_formats = {}

path_params = {}

query_params = []

# do not add duplicate keys to query_params list
existing_keys = []
for param in query_params:
existing_keys.append(param[0])

for key in kwargs:
if key not in existing_keys:
query_params.append([key, kwargs.get(key)])

header_params = {}

form_params = []
local_var_files = {}

body_params = None
if "create_ecommerce_estimate_request" in local_var_params:
body_params = local_var_params["create_ecommerce_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/ecommerce",
"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_ethereum_estimate(
self, create_ethereum_estimate_request={}, **kwargs
): # noqa: E501
Expand Down
2 changes: 1 addition & 1 deletion patch_api/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
self.user_agent = "patch-python/1.24.1"
self.user_agent = "patch-python/1.24.2"

def __del__(self):
if self._pool:
Expand Down
2 changes: 1 addition & 1 deletion patch_api/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def to_debug_report(self):
"OS: {env}\n"
"Python Version: {pyversion}\n"
"Version of the API: v1\n"
"SDK Package Version: 1.24.1".format(
"SDK Package Version: 1.24.2".format(
env=sys.platform, pyversion=sys.version
)
)
Expand Down
3 changes: 3 additions & 0 deletions patch_api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
from patch_api.models.create_bitcoin_estimate_request import (
CreateBitcoinEstimateRequest,
)
from patch_api.models.create_ecommerce_estimate_request import (
CreateEcommerceEstimateRequest,
)
from patch_api.models.create_ethereum_estimate_request import (
CreateEthereumEstimateRequest,
)
Expand Down
2 changes: 1 addition & 1 deletion patch_api/models/create_air_shipping_estimate_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(
aircraft_code=None,
aircraft_type="unknown",
freight_mass_g=None,
emissions_scope="wtw",
emissions_scope="ttw",
project_id=None,
create_order=False,
local_vars_configuration=None,
Expand Down
Loading