diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..c5d27cb --- /dev/null +++ b/.flake8 @@ -0,0 +1,6 @@ +[flake8] +# E501 is the "Line too long" error and is disabled since we use the black code formatter. +# W504 is the "line break before binary operator" error and is disabled since we use +# the black code formatter. +# W503 is disabled by default, but must be disabled explicitly when using `ignore`. +ignore = E501, W503, W504 diff --git a/.github/PULL_REQUEST_TEMPLATTE.md b/.github/PULL_REQUEST_TEMPLATTE.md new file mode 100644 index 0000000..b3f9d31 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATTE.md @@ -0,0 +1,15 @@ +### What + +** CHANGEME: What are you changing? ** + +### Why + +** CHANGEME: Why are these changes needed? ** + +### SDK Release Checklist + +- [ ] Have you added an integration test for the changes? +- [ ] Have you built the gem locally and made queries against it successfully? +- [ ] Did you update the changelog? +- [ ] Did you bump the package version? +- [ ] For breaking changes, did you plan for the release of the new SDK versions and deploy the API to production? diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml new file mode 100644 index 0000000..3706536 --- /dev/null +++ b/.github/workflows/black.yml @@ -0,0 +1,15 @@ +name: Lint + +on: + push: + branches: + - main + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - uses: psf/black@stable diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fed4f8f --- /dev/null +++ b/.gitignore @@ -0,0 +1,67 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover +.hypothesis/ +venv/ +.python-version +.pytest_cache + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +#Ipython Notebook +.ipynb_checkpoints + +git_push.sh diff --git a/.openapi-generator-ignore b/.openapi-generator-ignore new file mode 100644 index 0000000..7484ee5 --- /dev/null +++ b/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/.openapi-generator/VERSION b/.openapi-generator/VERSION new file mode 100644 index 0000000..ecedc98 --- /dev/null +++ b/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.3.1 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..53ad7c4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,11 @@ +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 + hooks: + - id: flake8 + args: ['--config=.flake8'] diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..c64dc83 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +# Changelog + +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.0.0.pre] - 2021-01-22 + +### Added + +- Pre-release of v1 Library +- Adds support for Orders, Estimates, Projects and Preferences + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e4c7ea8 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +SHELL = /bin/bash + +build: + pip install -r requirements.txt \ + python setup.py install + +lint: + pre-commit + +test: + pip install -r test-requirements.txt && \ + python -m unittest discover test/ + +.PHONY: build test lint diff --git a/README.md b/README.md index 9a88f6c..76be6c8 100644 --- a/README.md +++ b/README.md @@ -22,37 +22,25 @@ pip install Or install it directly with ```shell -pip install patch +pip install patch_api ``` ### Requirements -- Python 3.0.0 +- Python 3.6.0 ## Usage ### Configuration -After installing the gem, you'll have to configure it with your API key which is available from the API key page in the Patch dashboard: +After installing the gem, you'll have to initialize it with your API key which is available from the API key page in the Patch dashboard. The `patch` object will be used to to make calls to the Patch API: ```python import patch_api -configuration = patch_api.Configuration(api_key=os.environ.get('SANDBOX_API_KEY')) -api_client = patch_api.ApiClient(configuration) +patch = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY')) +orders = patch.orders.retrieve_orders() ``` -The `api_client` will be used to instantiate other API objects for Patch resources, for example the `OrdersApi`: - -``` -import patch_api -from patch_api.api.orders_api import OrdersApi - -configuration = patch_api.Configuration(api_key=os.environ.get('SANDBOX_API_KEY')) -api_client = patch_api.ApiClient(configuration) -orders_api = OrdersApi(api_client=api_client) -``` - - ### Orders In Patch, orders represent a purchase of carbon offsets or negative emissions by mass. Place orders directly if you know the amount of carbon dioxide you would like to sequester. If you do not know how much to purchase, use an estimate. @@ -66,48 +54,43 @@ fulfill the order for you. #### Examples ```python +import patch_api + +patch = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY')) + # Create an order - you can create an order # providing either mass_g or total_price_cents_usd, but not both -from patch_api.models.create_order_request import CreateOrderRequest - # Create order with mass -mass_g = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne) -create_order_request = CreateOrderRequest(mass_g=mass_g) -OrdersApi.create_order(create_order_request) +patch.orders.create_order(mass_g=1_000_000) # Pass in the mass in grams (i.e. 1 metric tonne) # Create an order with maximum total price total_price_cents_usd = 5_00 # Pass in the total price in cents (i.e. 5 dollars) -create_order_request = CreateOrderRequest(total_price_cents_usd=total_price_cents_usd) -OrdersApi.create_order(create_order_request) +patch.orders.create_order(total_price_cents_usd=total_price_cents_usd) ## You can also specify a project-id field (optional) to be used instead of the preferred one project_id = 'pro_test_1234' # Pass in the project's ID -create_order_request = CreateOrderRequest(project_id=project_id, mass_g=mass_g) -OrdersApi.create_order(create_order_request) - +patch.orders.create_order(project_id=project_id, mass_g=mass_g) ## Orders also accept a metadata field (optional) metadata = {user: "john doe"} -create_order_request = CreateOrderRequest(metadata=metadata, mass_g=mass_g) -OrdersApi.create_order(create_order_request) - +patch.orders.create_order(metadata=metadata, mass_g=mass_g) # Retrieve an order order_id = 'ord_test_1234' # Pass in the order's id -OrdersApi.retrieve_order(id=order_id) +patch.orders.retrieve_order(id=order_id) # Place an order order_id = 'ord_test_1234' # Pass in the order's id -OrdersApi.place_order(id=order_id) +patch.orders.place_order(id=order_id) # Cancel an order order_id = 'ord_test_1234' # Pass in the order's id -OrdersApi.cancel_order(id=order_id) +patch.orders.cancel_order(id=order_id) # Retrieve a list of orders page = 1 # Pass in which page of orders you'd like -OrdersApi.retrieve_orders(page=page) +patch.orders.retrieve_orders(page=page) ``` ### Estimates @@ -117,25 +100,26 @@ Estimates allow API users to get a quote for the cost of compensating a certain #### Examples ```python +import patch_api + +patch = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY')) + # Create an estimate -from patch_api.models.create_estimate_request import CreateEstimateRequest mass_g = 1_000_000 # Pass in the mass in grams (i.e. 1 metric tonne) -create_estimate_request = CreateEstimateRequest(mass_g=mass_g) -EstimatesApi.create_estimate(create_estimate_request) +patch.estimates.create_estimate(mass_g=mass_g) ## You can also specify a project-id field (optional) to be used instead of the preferred one project_id = 'pro_test_1234' # Pass in the project's ID -create_estimate_request = CreateEstimateRequest(mass_g=mass_g, project_id=project_id) -EstimatesApi.create_estimate(create_estimate_request) +patch.estimates.create_estimate(mass_g=mass_g, project_id=project_id) # Retrieve an estimate estimate_id = 'est_test_1234' -EstimatesApi.retrieve_estimate(id=estimate_id) +patch.estimates.retrieve_estimate(id=estimate_id) # Retrieve a list of estimates page = 1 # Pass in which page of estimates you'd like -EstimatesApi.retrieve_estimates(page=page) +patch.estimates.retrieve_estimates(page=page) ``` ### Projects @@ -145,13 +129,17 @@ Projects are the ways Patch takes CO2 out of the air. They can represent refores #### Examples ```python +import patch_api + +patch = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY')) + # Retrieve a project project_id = 'pro_test_1234' # Pass in the project's ID -ProjectsApi.retrieve_project(id=project_id) +patch.projects.retrieve_project(id=project_id) # Retrieve a list of projects page = 1 # Pass in which page of projects you'd like -ProjectsApi.retrieve_projects(page=page) +patch.projects.retrieve_projects(page=page) ``` ### Preferences @@ -161,49 +149,73 @@ Preferences are how you route your orders in Patch. If you don't have a preferen #### Examples ```python +import patch_api + +patch = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY')) + # Create a preference -from patch_api.models.create_preference_request import CreatePreferenceRequest project_id = 'pro_test_1234' # Pass in the project_id for your preference -create_preference_request = CreatePreferenceRequest(project_id=project_id) -PreferencesApi.create_preference(create_preference_request) +patch.preferences.create_preference(project_id=project_id) # Retrieve a preference preference_id = 'pre_test_1234' # Pass in the preferences's id -PreferencesApi.retrieve_preference(preference_id=preference_id) +patch.preferences.retrieve_preference(preference_id=preference_id) # Delete a preference preference_id = 'pre_test_1234' # Pass in the preferences's id -PreferencesApi.delete_preference(preference_id=preference_id) +patch.preferences.delete_preference(preference_id=preference_id) # Retrieve a list of preferences page = 1 # Pass in which page of preferences you'd like -PreferencesApi.retrieve_preferences(page=page) +patch.preferences.retrieve_preferences(page=page) ``` ## Development +### Running tests + +Set up the required environment variable: +``` +$ export SANDBOX_API_KEY= +``` + +Run tests: +``` +$ make test +``` + +To run an individual test: +``` +$ python -m unittest +``` + +### Testing the built package locally + To build the library locally, run: ``` $ make build ``` -To test the library locally, create a python file in a sibling directory and add the following: -```python -import sys -sys.path.append("../patch-python") - -import patch_api +In another directory, create a file called `patch.py` and install the local package in this directory: -# ..... your Patch API code goes here +``` +$ touch patch.py +$ pip install ../patch-python ``` -Set up required environment variables: +Set up the required environment variable: ``` $ export SANDBOX_API_KEY= ``` -Run tests: -``` -$ make test +To test the package locally, create a python file in a sibling directory and add the following: +```python +import os +import patch_api + +patch = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY')) +orders = patch.orders.retrieve_orders(page=1) + +print(orders) ``` diff --git a/patch_api/__init__.py b/patch_api/__init__.py new file mode 100644 index 0000000..5cb843d --- /dev/null +++ b/patch_api/__init__.py @@ -0,0 +1,31 @@ +# coding: utf-8 + +# flake8: noqa + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +__version__ = "1.0.0" + +# import ApiClient +from patch_api.api_client import ApiClient +from patch_api.configuration import Configuration +from patch_api.exceptions import OpenApiException +from patch_api.exceptions import ApiTypeError +from patch_api.exceptions import ApiValueError +from patch_api.exceptions import ApiKeyError +from patch_api.exceptions import ApiException + +from patch_api.api import * + +from patch_api.models import * diff --git a/patch_api/api/__init__.py b/patch_api/api/__init__.py new file mode 100644 index 0000000..cd9725e --- /dev/null +++ b/patch_api/api/__init__.py @@ -0,0 +1,9 @@ +from __future__ import absolute_import + +# flake8: noqa + +# import apis into api package +from patch_api.api.estimates_api import EstimatesApi +from patch_api.api.orders_api import OrdersApi +from patch_api.api.preferences_api import PreferencesApi +from patch_api.api.projects_api import ProjectsApi diff --git a/patch_api/api/estimates_api.py b/patch_api/api/estimates_api.py new file mode 100644 index 0000000..07f42ac --- /dev/null +++ b/patch_api/api/estimates_api.py @@ -0,0 +1,405 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import re # noqa: F401 + +# python 2 and python 3 compatibility library +import six + +from patch_api.exceptions import ApiTypeError, ApiValueError + + +class EstimatesApi(object): + """NOTE: This class is auto generated by OpenAPI Generator + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + ALLOWED_QUERY_PARAMS = ["mass_g", "price_cents_usd", "project_id", "page"] + + def __init__(self, api_client=None): + self.api_client = api_client + + def create_mass_estimate( + self, create_mass_estimate_request={}, **kwargs + ): # noqa: E501 + """Create an estimate based on mass of CO2 # noqa: E501 + + Creates an estimate for the mass of CO2 to be compensated. An order in the `draft` state will also be created, 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_mass_estimate(create_mass_estimate_request, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param CreateMassEstimateRequest create_mass_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_mass_estimate_with_http_info( + create_mass_estimate_request, **kwargs + ) # noqa: E501 + + def create_mass_estimate_with_http_info( + self, create_mass_estimate_request, **kwargs + ): # noqa: E501 + """Create an estimate based on mass of CO2 # noqa: E501 + + Creates an estimate for the mass of CO2 to be compensated. An order in the `draft` state will also be created, 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_mass_estimate_with_http_info(create_mass_estimate_request, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param CreateMassEstimateRequest create_mass_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_mass_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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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_mass_estimate" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + # verify the required parameter 'create_mass_estimate_request' is set + if ( + "create_mass_estimate_request" not in local_var_params + or local_var_params["create_mass_estimate_request"] is None + ): + raise ApiValueError( + "Missing the required parameter `create_mass_estimate_request` when calling `create_mass_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_mass_estimate_request" in local_var_params: + body_params = local_var_params["create_mass_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/mass", + "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 retrieve_estimate(self, id={}, **kwargs): # noqa: E501 + """Retrieves an estimate # noqa: E501 + + Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_estimate(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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.retrieve_estimate_with_http_info(id, **kwargs) # noqa: E501 + + def retrieve_estimate_with_http_info(self, id, **kwargs): # noqa: E501 + """Retrieves an estimate # noqa: E501 + + Retrieves a given estimate and its associated order. You can only retrieve estimates associated with the organization you are querying for. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_estimate_with_http_info(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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 = ["id"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 retrieve_estimate" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + # verify the required parameter 'id' is set + if "id" not in local_var_params or local_var_params["id"] is None: + raise ApiValueError( + "Missing the required parameter `id` when calling `retrieve_estimate`" + ) # noqa: E501 + + collection_formats = {} + + path_params = {} + if "id" in local_var_params: + path_params["id"] = local_var_params["id"] # noqa: E501 + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/estimates/{id}", + "GET", + 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 retrieve_estimates(self, **kwargs): # noqa: E501 + """Retrieves a list of estimates # noqa: E501 + + Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_estimates(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param int page: + :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: EstimateListResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.retrieve_estimates_with_http_info(**kwargs) # noqa: E501 + + def retrieve_estimates_with_http_info(self, **kwargs): # noqa: E501 + """Retrieves a list of estimates # noqa: E501 + + Retrieves a list of estimates and their associated orders. You can only retrieve estimates associated with the organization you are querying for. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_estimates_with_http_info(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param int page: + :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(EstimateListResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["page"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 retrieve_estimates" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + + collection_formats = {} + + path_params = {} + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + if "page" in local_var_params: + query_params.append(("page", local_var_params["page"])) # noqa: E501 + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/estimates", + "GET", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="EstimateListResponse", # 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, + ) diff --git a/patch_api/api/orders_api.py b/patch_api/api/orders_api.py new file mode 100644 index 0000000..6e22be6 --- /dev/null +++ b/patch_api/api/orders_api.py @@ -0,0 +1,641 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import re # noqa: F401 + +# python 2 and python 3 compatibility library +import six + +from patch_api.exceptions import ApiTypeError, ApiValueError + + +class OrdersApi(object): + """NOTE: This class is auto generated by OpenAPI Generator + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + ALLOWED_QUERY_PARAMS = ["mass_g", "price_cents_usd", "project_id", "page"] + + def __init__(self, api_client=None): + self.api_client = api_client + + def cancel_order(self, id={}, **kwargs): # noqa: E501 + """Cancel an order # noqa: E501 + + Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` state can be cancelled. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.cancel_order(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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: OrderResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.cancel_order_with_http_info(id, **kwargs) # noqa: E501 + + def cancel_order_with_http_info(self, id, **kwargs): # noqa: E501 + """Cancel an order # noqa: E501 + + Cancelling an order removes the associated offset allocation from an order. You will not be charged for cancelled orders. Only orders in the `draft` state can be cancelled. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.cancel_order_with_http_info(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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(OrderResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["id"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 cancel_order" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + # verify the required parameter 'id' is set + if "id" not in local_var_params or local_var_params["id"] is None: + raise ApiValueError( + "Missing the required parameter `id` when calling `cancel_order`" + ) # noqa: E501 + + collection_formats = {} + + path_params = {} + if "id" in local_var_params: + path_params["id"] = local_var_params["id"] # noqa: E501 + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/orders/{id}/cancel", + "PATCH", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="OrderResponse", # 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_order(self, create_order_request={}, **kwargs): # noqa: E501 + """Creates an order # noqa: E501 + + Creates an order in the `placed` state. To create a `draft` order, create an estimate first. # 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_order(create_order_request, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param CreateOrderRequest create_order_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: OrderResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.create_order_with_http_info( + create_order_request, **kwargs + ) # noqa: E501 + + def create_order_with_http_info(self, create_order_request, **kwargs): # noqa: E501 + """Creates an order # noqa: E501 + + Creates an order in the `placed` state. To create a `draft` order, create an estimate first. # 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_order_with_http_info(create_order_request, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param CreateOrderRequest create_order_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(OrderResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["create_order_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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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_order" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + # verify the required parameter 'create_order_request' is set + if ( + "create_order_request" not in local_var_params + or local_var_params["create_order_request"] is None + ): + raise ApiValueError( + "Missing the required parameter `create_order_request` when calling `create_order`" + ) # 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_order_request" in local_var_params: + body_params = local_var_params["create_order_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/orders", + "POST", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="OrderResponse", # 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 place_order(self, id={}, **kwargs): # noqa: E501 + """Place an order # noqa: E501 + + Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.place_order(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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: OrderResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.place_order_with_http_info(id, **kwargs) # noqa: E501 + + def place_order_with_http_info(self, id, **kwargs): # noqa: E501 + """Place an order # noqa: E501 + + Placing an order confirms an order's allocation of offsets. Only orders that are in the `draft` state can be placed # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.place_order_with_http_info(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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(OrderResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["id"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 place_order" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + # verify the required parameter 'id' is set + if "id" not in local_var_params or local_var_params["id"] is None: + raise ApiValueError( + "Missing the required parameter `id` when calling `place_order`" + ) # noqa: E501 + + collection_formats = {} + + path_params = {} + if "id" in local_var_params: + path_params["id"] = local_var_params["id"] # noqa: E501 + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/orders/{id}/place", + "PATCH", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="OrderResponse", # 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 retrieve_order(self, id={}, **kwargs): # noqa: E501 + """Retrieves an order # noqa: E501 + + Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_order(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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: OrderResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.retrieve_order_with_http_info(id, **kwargs) # noqa: E501 + + def retrieve_order_with_http_info(self, id, **kwargs): # noqa: E501 + """Retrieves an order # noqa: E501 + + Retrieves a given order and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_order_with_http_info(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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(OrderResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["id"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 retrieve_order" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + # verify the required parameter 'id' is set + if "id" not in local_var_params or local_var_params["id"] is None: + raise ApiValueError( + "Missing the required parameter `id` when calling `retrieve_order`" + ) # noqa: E501 + + collection_formats = {} + + path_params = {} + if "id" in local_var_params: + path_params["id"] = local_var_params["id"] # noqa: E501 + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/orders/{id}", + "GET", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="OrderResponse", # 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 retrieve_orders(self, **kwargs): # noqa: E501 + """Retrieves a list of orders # noqa: E501 + + Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_orders(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param int page: + :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: OrderListResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.retrieve_orders_with_http_info(**kwargs) # noqa: E501 + + def retrieve_orders_with_http_info(self, **kwargs): # noqa: E501 + """Retrieves a list of orders # noqa: E501 + + Retrieves a list of orders and its allocation offsets or negative emissions. You can only retrieve orders associated with the organization you are querying for. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_orders_with_http_info(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param int page: + :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(OrderListResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["page"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 retrieve_orders" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + + collection_formats = {} + + path_params = {} + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + if "page" in local_var_params: + query_params.append(("page", local_var_params["page"])) # noqa: E501 + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/orders", + "GET", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="OrderListResponse", # 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, + ) diff --git a/patch_api/api/preferences_api.py b/patch_api/api/preferences_api.py new file mode 100644 index 0000000..5efddc3 --- /dev/null +++ b/patch_api/api/preferences_api.py @@ -0,0 +1,523 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import re # noqa: F401 + +# python 2 and python 3 compatibility library +import six + +from patch_api.exceptions import ApiTypeError, ApiValueError + + +class PreferencesApi(object): + """NOTE: This class is auto generated by OpenAPI Generator + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + ALLOWED_QUERY_PARAMS = ["mass_g", "price_cents_usd", "project_id", "page"] + + def __init__(self, api_client=None): + self.api_client = api_client + + def create_preference(self, create_preference_request={}, **kwargs): # noqa: E501 + """creates a project preference # noqa: E501 + + Creates a project preference for the given organization. If you have a `preference` in place, all of your orders will be directed to the project the preference points to. # 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_preference(create_preference_request, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param CreatePreferenceRequest create_preference_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: PreferenceResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.create_preference_with_http_info( + create_preference_request, **kwargs + ) # noqa: E501 + + def create_preference_with_http_info( + self, create_preference_request, **kwargs + ): # noqa: E501 + """creates a project preference # noqa: E501 + + Creates a project preference for the given organization. If you have a `preference` in place, all of your orders will be directed to the project the preference points to. # 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_preference_with_http_info(create_preference_request, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param CreatePreferenceRequest create_preference_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(PreferenceResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["create_preference_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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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_preference" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + # verify the required parameter 'create_preference_request' is set + if ( + "create_preference_request" not in local_var_params + or local_var_params["create_preference_request"] is None + ): + raise ApiValueError( + "Missing the required parameter `create_preference_request` when calling `create_preference`" + ) # 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_preference_request" in local_var_params: + body_params = local_var_params["create_preference_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/preferences", + "POST", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="PreferenceResponse", # 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 delete_preference(self, id={}, **kwargs): # noqa: E501 + """Deletes an organization's preference for a project # noqa: E501 + + Deletes the given `preference`. Once a preference is deleted, it cannot be undone. If you want to restore your previous preference, create a new one. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.delete_preference(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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: PreferenceResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.delete_preference_with_http_info(id, **kwargs) # noqa: E501 + + def delete_preference_with_http_info(self, id, **kwargs): # noqa: E501 + """Deletes an organization's preference for a project # noqa: E501 + + Deletes the given `preference`. Once a preference is deleted, it cannot be undone. If you want to restore your previous preference, create a new one. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.delete_preference_with_http_info(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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(PreferenceResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["id"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 delete_preference" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + # verify the required parameter 'id' is set + if "id" not in local_var_params or local_var_params["id"] is None: + raise ApiValueError( + "Missing the required parameter `id` when calling `delete_preference`" + ) # noqa: E501 + + collection_formats = {} + + path_params = {} + if "id" in local_var_params: + path_params["id"] = local_var_params["id"] # noqa: E501 + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/preferences/{id}", + "DELETE", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="PreferenceResponse", # 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 retrieve_preference(self, id={}, **kwargs): # noqa: E501 + """Retrieve the preference # noqa: E501 + + Retrieve the preference and project of an organization. You can only retrieve preferences associated with your organization. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_preference(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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: PreferenceResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.retrieve_preference_with_http_info(id, **kwargs) # noqa: E501 + + def retrieve_preference_with_http_info(self, id, **kwargs): # noqa: E501 + """Retrieve the preference # noqa: E501 + + Retrieve the preference and project of an organization. You can only retrieve preferences associated with your organization. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_preference_with_http_info(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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(PreferenceResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["id"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 retrieve_preference" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + # verify the required parameter 'id' is set + if "id" not in local_var_params or local_var_params["id"] is None: + raise ApiValueError( + "Missing the required parameter `id` when calling `retrieve_preference`" + ) # noqa: E501 + + collection_formats = {} + + path_params = {} + if "id" in local_var_params: + path_params["id"] = local_var_params["id"] # noqa: E501 + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/preferences/{id}", + "GET", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="PreferenceResponse", # 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 retrieve_preferences(self, **kwargs): # noqa: E501 + """Retrieves a list of preferences # noqa: E501 + + Retrieves a list of preferences and associated projects of an organization. You can only retrieve preferences associated with your organization. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_preferences(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param int page: + :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: PreferenceListResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.retrieve_preferences_with_http_info(**kwargs) # noqa: E501 + + def retrieve_preferences_with_http_info(self, **kwargs): # noqa: E501 + """Retrieves a list of preferences # noqa: E501 + + Retrieves a list of preferences and associated projects of an organization. You can only retrieve preferences associated with your organization. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_preferences_with_http_info(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param int page: + :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(PreferenceListResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["page"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 retrieve_preferences" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + + collection_formats = {} + + path_params = {} + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + if "page" in local_var_params: + query_params.append(("page", local_var_params["page"])) # noqa: E501 + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/preferences", + "GET", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="PreferenceListResponse", # 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, + ) diff --git a/patch_api/api/projects_api.py b/patch_api/api/projects_api.py new file mode 100644 index 0000000..4a6e3fe --- /dev/null +++ b/patch_api/api/projects_api.py @@ -0,0 +1,269 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import re # noqa: F401 + +# python 2 and python 3 compatibility library +import six + +from patch_api.exceptions import ApiTypeError, ApiValueError + + +class ProjectsApi(object): + """NOTE: This class is auto generated by OpenAPI Generator + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + ALLOWED_QUERY_PARAMS = ["mass_g", "price_cents_usd", "project_id", "page"] + + def __init__(self, api_client=None): + self.api_client = api_client + + def retrieve_project(self, id={}, **kwargs): # noqa: E501 + """Retrieves a project # noqa: E501 + + Retrieves a project available on Patch's platform. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_project(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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: ProjectResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.retrieve_project_with_http_info(id, **kwargs) # noqa: E501 + + def retrieve_project_with_http_info(self, id, **kwargs): # noqa: E501 + """Retrieves a project # noqa: E501 + + Retrieves a project available on Patch's platform. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_project_with_http_info(id, async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param str id: (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(ProjectResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["id"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 retrieve_project" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + # verify the required parameter 'id' is set + if "id" not in local_var_params or local_var_params["id"] is None: + raise ApiValueError( + "Missing the required parameter `id` when calling `retrieve_project`" + ) # noqa: E501 + + collection_formats = {} + + path_params = {} + if "id" in local_var_params: + path_params["id"] = local_var_params["id"] # noqa: E501 + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/projects/{id}", + "GET", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="ProjectResponse", # 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 retrieve_projects(self, **kwargs): # noqa: E501 + """Retrieves a list of projects # noqa: E501 + + Retrieves a list of projects available for purchase on Patch's platform. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_projects(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param int page: + :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: ProjectListResponse + If the method is called asynchronously, + returns the request thread. + """ + kwargs["_return_http_data_only"] = True + return self.retrieve_projects_with_http_info(**kwargs) # noqa: E501 + + def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501 + """Retrieves a list of projects # noqa: E501 + + Retrieves a list of projects available for purchase on Patch's platform. # noqa: E501 + This method makes a synchronous HTTP request by default. To make an + asynchronous HTTP request, please pass async_req=True + >>> thread = api.retrieve_projects_with_http_info(async_req=True) + >>> result = thread.get() + + :param async_req bool: execute request asynchronously + :param int page: + :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(ProjectListResponse, status_code(int), headers(HTTPHeaderDict)) + If the method is called asynchronously, + returns the request thread. + """ + + local_var_params = locals() + + all_params = ["page"] # 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("price_cents_usd") + all_params.append("project_id") + all_params.append("metadata") + + 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 retrieve_projects" % key + ) + local_var_params[key] = val + del local_var_params["kwargs"] + + collection_formats = {} + + path_params = {} + + query_params = [] + for key in kwargs: + query_params.append([key, kwargs.get(key)]) + if "page" in local_var_params: + query_params.append(("page", local_var_params["page"])) # noqa: E501 + + header_params = {} + + form_params = [] + local_var_files = {} + + body_params = None + # HTTP header `Accept` + header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) # noqa: E501 + + # Authentication setting + auth_settings = ["bearer_auth"] # noqa: E501 + + return self.api_client.call_api( + "/v1/projects", + "GET", + path_params, + query_params, + header_params, + body=body_params, + post_params=form_params, + files=local_var_files, + response_type="ProjectListResponse", # 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, + ) diff --git a/patch_api/api_client.py b/patch_api/api_client.py new file mode 100644 index 0000000..d57c691 --- /dev/null +++ b/patch_api/api_client.py @@ -0,0 +1,737 @@ +# coding: utf-8 +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + +from __future__ import absolute_import + +import datetime +import json +import mimetypes +from multiprocessing.pool import ThreadPool +import os +import re +import tempfile + +# python 2 and python 3 compatibility library +import six +from six.moves.urllib.parse import quote + +from patch_api.configuration import Configuration +import patch_api.models +from patch_api.api.estimates_api import EstimatesApi +from patch_api.api.orders_api import OrdersApi +from patch_api.api.preferences_api import PreferencesApi +from patch_api.api.projects_api import ProjectsApi + +from patch_api import rest +from patch_api.exceptions import ApiValueError + + +class ApiClient(object): + """Generic API client for OpenAPI client library builds. + + OpenAPI generic API client. This client handles the client- + server communication, and is invariant across implementations. Specifics of + the methods and models for each application are generated from the OpenAPI + templates. + + NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + Do not edit the class manually. + + :param configuration: .Configuration object for this client + :param header_name: a header to pass when making calls to the API. + :param header_value: a header value to pass when making calls to + the API. + :param cookie: a cookie to include in the header when making calls + to the API + :param pool_threads: The number of threads to use for async requests + to the API. More threads means more concurrent API requests. + """ + + PRIMITIVE_TYPES = (float, bool, bytes, six.text_type) + six.integer_types + NATIVE_TYPES_MAPPING = { + "int": int, + "long": int if six.PY3 else long, # noqa: F821 + "float": float, + "str": str, + "bool": bool, + "date": datetime.date, + "datetime": datetime.datetime, + "object": object, + } + _pool = None + + def __init__( + self, + api_key=None, + configuration=None, + header_name=None, + header_value=None, + cookie=None, + pool_threads=1, + ): + if api_key is None: + raise ValueError("ApiClient must be initialized with an api_key") + if configuration is None: + configuration = Configuration() + self.configuration = configuration + self.pool_threads = pool_threads + + self.rest_client = rest.RESTClientObject(api_key, configuration) + self.default_headers = {} + if header_name is not None: + self.default_headers[header_name] = header_value + self.cookie = cookie + # Set default User-Agent. + self.user_agent = "OpenAPI-Generator/1.0.0/python" + + def __del__(self): + if self._pool: + self._pool.close() + self._pool.join() + self._pool = None + + def __getattr__(self, method): + resource = { + "projects": ProjectsApi, + "orders": OrdersApi, + "preferences": PreferencesApi, + "estimates": EstimatesApi, + }[method] + return resource(api_client=self) + + @property + def pool(self): + """Create thread pool on first request + avoids instantiating unused threadpool for blocking clients. + """ + if self._pool is None: + self._pool = ThreadPool(self.pool_threads) + return self._pool + + @property + def user_agent(self): + """User agent for this API client""" + return self.default_headers["User-Agent"] + + @user_agent.setter + def user_agent(self, value): + self.default_headers["User-Agent"] = value + + def set_default_header(self, header_name, header_value): + self.default_headers[header_name] = header_value + + def __call_api( + self, + resource_path, + method, + path_params=None, + query_params=None, + header_params=None, + body=None, + post_params=None, + files=None, + response_type=None, + auth_settings=None, + _return_http_data_only=None, + collection_formats=None, + _preload_content=True, + _request_timeout=None, + _host=None, + ): + + config = self.configuration + + # header parameters + header_params = header_params or {} + header_params.update(self.default_headers) + if self.cookie: + header_params["Cookie"] = self.cookie + if header_params: + header_params = self.sanitize_for_serialization(header_params) + header_params = dict( + self.parameters_to_tuples(header_params, collection_formats) + ) + + # path parameters + if path_params: + path_params = self.sanitize_for_serialization(path_params) + path_params = self.parameters_to_tuples(path_params, collection_formats) + for k, v in path_params: + # specified safe chars, encode everything + resource_path = resource_path.replace( + "{%s}" % k, quote(str(v), safe=config.safe_chars_for_path_param) + ) + + # query parameters + if query_params: + query_params = self.sanitize_for_serialization(query_params) + query_params = self.parameters_to_tuples(query_params, collection_formats) + + # post parameters + if post_params or files: + post_params = post_params if post_params else [] + post_params = self.sanitize_for_serialization(post_params) + post_params = self.parameters_to_tuples(post_params, collection_formats) + post_params.extend(self.files_parameters(files)) + + # auth setting + self.update_params_for_auth(header_params, query_params, auth_settings) + + # body + if body: + body = self.sanitize_for_serialization(body) + + # request url + if _host is None: + url = self.configuration.host + resource_path + else: + # use server/host defined in path or operation instead + url = _host + resource_path + + # perform request and return response + response_data = self.request( + method, + url, + query_params=query_params, + headers=header_params, + post_params=post_params, + body=body, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + ) + + self.last_response = response_data + + return_data = response_data + if _preload_content: + # deserialize response data + if response_type: + return_data = self.deserialize(response_data, response_type) + else: + return_data = None + + if _return_http_data_only: + return return_data + else: + return (return_data, response_data.status, response_data.getheaders()) + + def sanitize_for_serialization(self, obj): + """Builds a JSON POST object. + + If obj is None, return None. + If obj is str, int, long, float, bool, return directly. + If obj is datetime.datetime, datetime.date + convert to string in iso8601 format. + If obj is list, sanitize each element in the list. + If obj is dict, return the dict. + If obj is OpenAPI model, return the properties dict. + + :param obj: The data to serialize. + :return: The serialized form of data. + """ + if obj is None: + return None + elif isinstance(obj, self.PRIMITIVE_TYPES): + return obj + elif isinstance(obj, list): + return [self.sanitize_for_serialization(sub_obj) for sub_obj in obj] + elif isinstance(obj, tuple): + return tuple(self.sanitize_for_serialization(sub_obj) for sub_obj in obj) + elif isinstance(obj, (datetime.datetime, datetime.date)): + return obj.isoformat() + + if isinstance(obj, dict): + obj_dict = obj + else: + # Convert model obj to dict except + # attributes `openapi_types`, `attribute_map` + # and attributes which value is not None. + # Convert attribute name to json key in + # model definition for request. + obj_dict = { + obj.attribute_map[attr]: getattr(obj, attr) + for attr, _ in six.iteritems(obj.openapi_types) + if getattr(obj, attr) is not None + } + + return { + key: self.sanitize_for_serialization(val) + for key, val in six.iteritems(obj_dict) + } + + def deserialize(self, response, response_type): + """Deserializes response into an object. + + :param response: RESTResponse object to be deserialized. + :param response_type: class literal for + deserialized object, or string of class name. + + :return: deserialized object. + """ + # handle file downloading + # save response body into a tmp file and return the instance + if response_type == "file": + return self.__deserialize_file(response) + + # fetch data from response object + try: + data = json.loads(response.data) + except ValueError: + data = response.data + + return self.__deserialize(data, response_type) + + def __deserialize(self, data, klass): + """Deserializes dict, list, str into an object. + + :param data: dict, list or str. + :param klass: class literal, or string of class name. + + :return: object. + """ + if data is None: + return None + + if type(klass) == str: + if klass.startswith("list["): + sub_kls = re.match(r"list\[(.*)\]", klass).group(1) + return [self.__deserialize(sub_data, sub_kls) for sub_data in data] + + if klass.startswith("dict("): + sub_kls = re.match(r"dict\(([^,]*), (.*)\)", klass).group(2) + return { + k: self.__deserialize(v, sub_kls) for k, v in six.iteritems(data) + } + + # convert str to class + if klass in self.NATIVE_TYPES_MAPPING: + klass = self.NATIVE_TYPES_MAPPING[klass] + else: + klass = getattr(patch_api.models, klass) + + if klass in self.PRIMITIVE_TYPES: + return self.__deserialize_primitive(data, klass) + elif klass == object: + return self.__deserialize_object(data) + elif klass == datetime.date: + return self.__deserialize_date(data) + elif klass == datetime.datetime: + return self.__deserialize_datatime(data) + else: + return self.__deserialize_model(data, klass) + + def call_api( + self, + resource_path, + method, + path_params=None, + query_params=None, + header_params=None, + body=None, + post_params=None, + files=None, + response_type=None, + auth_settings=None, + async_req=None, + _return_http_data_only=None, + collection_formats=None, + _preload_content=True, + _request_timeout=None, + _host=None, + ): + """Makes the HTTP request (synchronous) and returns deserialized data. + + To make an async_req request, set the async_req parameter. + + :param resource_path: Path to method endpoint. + :param method: Method to call. + :param path_params: Path parameters in the url. + :param query_params: Query parameters in the url. + :param header_params: Header parameters to be + placed in the request header. + :param body: Request body. + :param post_params dict: Request post form parameters, + for `application/x-www-form-urlencoded`, `multipart/form-data`. + :param auth_settings list: Auth Settings names for the request. + :param response: Response data type. + :param files dict: key -> filename, value -> filepath, + for `multipart/form-data`. + :param async_req bool: execute request asynchronously + :param _return_http_data_only: response data without head status code + and headers + :param collection_formats: dict of collection formats for path, query, + header, and post parameters. + :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: + If async_req parameter is True, + the request will be called asynchronously. + The method will return the request thread. + If parameter async_req is False or missing, + then the method will return the response directly. + """ + if not async_req: + return self.__call_api( + resource_path, + method, + path_params, + query_params, + header_params, + body, + post_params, + files, + response_type, + auth_settings, + _return_http_data_only, + collection_formats, + _preload_content, + _request_timeout, + _host, + ) + else: + thread = self.pool.apply_async( + self.__call_api, + ( + resource_path, + method, + path_params, + query_params, + header_params, + body, + post_params, + files, + response_type, + auth_settings, + _return_http_data_only, + collection_formats, + _preload_content, + _request_timeout, + _host, + ), + ) + return thread + + def request( + self, + method, + url, + query_params=None, + headers=None, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ): + """Makes the HTTP request using RESTClient.""" + if method == "GET": + return self.rest_client.GET( + url, + query_params=query_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + headers=headers, + ) + elif method == "HEAD": + return self.rest_client.HEAD( + url, + query_params=query_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + headers=headers, + ) + elif method == "OPTIONS": + return self.rest_client.OPTIONS( + url, + query_params=query_params, + headers=headers, + post_params=post_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + body=body, + ) + elif method == "POST": + return self.rest_client.POST( + url, + query_params=query_params, + headers=headers, + post_params=post_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + body=body, + ) + elif method == "PUT": + return self.rest_client.PUT( + url, + query_params=query_params, + headers=headers, + post_params=post_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + body=body, + ) + elif method == "PATCH": + return self.rest_client.PATCH( + url, + query_params=query_params, + headers=headers, + post_params=post_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + body=body, + ) + elif method == "DELETE": + return self.rest_client.DELETE( + url, + query_params=query_params, + headers=headers, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + body=body, + ) + else: + raise ApiValueError( + "http method must be `GET`, `HEAD`, `OPTIONS`," + " `POST`, `PATCH`, `PUT` or `DELETE`." + ) + + def parameters_to_tuples(self, params, collection_formats): + """Get parameters as list of tuples, formatting collections. + + :param params: Parameters as dict or list of two-tuples + :param dict collection_formats: Parameter collection formats + :return: Parameters as list of tuples, collections formatted + """ + new_params = [] + if collection_formats is None: + collection_formats = {} + for k, v in ( + six.iteritems(params) if isinstance(params, dict) else params + ): # noqa: E501 + if k in collection_formats: + collection_format = collection_formats[k] + if collection_format == "multi": + new_params.extend((k, value) for value in v) + else: + if collection_format == "ssv": + delimiter = " " + elif collection_format == "tsv": + delimiter = "\t" + elif collection_format == "pipes": + delimiter = "|" + else: # csv is the default + delimiter = "," + new_params.append((k, delimiter.join(str(value) for value in v))) + else: + new_params.append((k, v)) + return new_params + + def files_parameters(self, files=None): + """Builds form parameters. + + :param files: File parameters. + :return: Form parameters with files. + """ + params = [] + + if files: + for k, v in six.iteritems(files): + if not v: + continue + file_names = v if type(v) is list else [v] + for n in file_names: + with open(n, "rb") as f: + filename = os.path.basename(f.name) + filedata = f.read() + mimetype = ( + mimetypes.guess_type(filename)[0] + or "application/octet-stream" + ) + params.append(tuple([k, tuple([filename, filedata, mimetype])])) + + return params + + def select_header_accept(self, accepts): + """Returns `Accept` based on an array of accepts provided. + + :param accepts: List of headers. + :return: Accept (e.g. application/json). + """ + if not accepts: + return + + accepts = [x.lower() for x in accepts] + + if "application/json" in accepts: + return "application/json" + else: + return ", ".join(accepts) + + def select_header_content_type(self, content_types): + """Returns `Content-Type` based on an array of content_types provided. + + :param content_types: List of content-types. + :return: Content-Type (e.g. application/json). + """ + if not content_types: + return "application/json" + + content_types = [x.lower() for x in content_types] + + if "application/json" in content_types or "*/*" in content_types: + return "application/json" + else: + return content_types[0] + + def update_params_for_auth(self, headers, querys, auth_settings): + """Updates header and query params based on authentication setting. + + :param headers: Header parameters dict to be updated. + :param querys: Query parameters tuple list to be updated. + :param auth_settings: Authentication setting identifiers list. + """ + if not auth_settings: + return + + for auth in auth_settings: + auth_setting = self.configuration.auth_settings().get(auth) + if auth_setting: + if not auth_setting["value"]: + continue + elif auth_setting["in"] == "cookie": + headers["Cookie"] = auth_setting["value"] + elif auth_setting["in"] == "header": + headers[auth_setting["key"]] = auth_setting["value"] + elif auth_setting["in"] == "query": + querys.append((auth_setting["key"], auth_setting["value"])) + else: + raise ApiValueError( + "Authentication token must be in `query` or `header`" + ) + + def __deserialize_file(self, response): + """Deserializes body to file + + Saves response body into a file in a temporary folder, + using the filename from the `Content-Disposition` header if provided. + + :param response: RESTResponse. + :return: file path. + """ + fd, path = tempfile.mkstemp(dir=self.configuration.temp_folder_path) + os.close(fd) + os.remove(path) + + content_disposition = response.getheader("Content-Disposition") + if content_disposition: + filename = re.search( + r'filename=[\'"]?([^\'"\s]+)[\'"]?', content_disposition + ).group(1) + path = os.path.join(os.path.dirname(path), filename) + + with open(path, "wb") as f: + f.write(response.data) + + return path + + def __deserialize_primitive(self, data, klass): + """Deserializes string to primitive type. + + :param data: str. + :param klass: class literal. + + :return: int, long, float, str, bool. + """ + try: + return klass(data) + except UnicodeEncodeError: + return six.text_type(data) + except TypeError: + return data + + def __deserialize_object(self, value): + """Return an original value. + + :return: object. + """ + return value + + def __deserialize_date(self, string): + """Deserializes string to date. + + :param string: str. + :return: date. + """ + try: + from dateutil.parser import parse + + return parse(string).date() + except ImportError: + return string + except ValueError: + raise rest.ApiException( + status=0, reason="Failed to parse `{0}` as date object".format(string) + ) + + def __deserialize_datatime(self, string): + """Deserializes string to datetime. + + The string should be in iso8601 datetime format. + + :param string: str. + :return: datetime. + """ + try: + from dateutil.parser import parse + + return parse(string) + except ImportError: + return string + except ValueError: + raise rest.ApiException( + status=0, + reason=("Failed to parse `{0}` as datetime object".format(string)), + ) + + def __deserialize_model(self, data, klass): + """Deserializes list or dict to model. + + :param data: dict, list. + :param klass: class literal. + :return: model object. + """ + + if not klass.openapi_types and not hasattr(klass, "get_real_child_model"): + return data + + kwargs = {} + if klass.openapi_types is not None: + for attr, attr_type in six.iteritems(klass.openapi_types): + if ( + data is not None + and klass.attribute_map[attr] in data + and isinstance(data, (list, dict)) + ): + value = data[klass.attribute_map[attr]] + kwargs[attr] = self.__deserialize(value, attr_type) + + instance = klass(**kwargs) + + if hasattr(instance, "get_real_child_model"): + klass_name = instance.get_real_child_model(data) + if klass_name: + instance = self.__deserialize(data, klass_name) + return instance diff --git a/patch_api/configuration.py b/patch_api/configuration.py new file mode 100644 index 0000000..4da45bf --- /dev/null +++ b/patch_api/configuration.py @@ -0,0 +1,398 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import copy +import logging +import multiprocessing +import sys +import urllib3 + +import six +from six.moves import http_client as httplib + + +class Configuration(object): + """NOTE: This class is auto generated by OpenAPI Generator + + Ref: https://openapi-generator.tech + Do not edit the class manually. + + :param host: Base url + :param api_key: Dict to store API key(s). + Each entry in the dict specifies an API key. + The dict key is the name of the security scheme in the OAS specification. + The dict value is the API key secret. + :param api_key_prefix: Dict to store API prefix (e.g. Bearer) + The dict key is the name of the security scheme in the OAS specification. + The dict value is an API key prefix when generating the auth data. + :param username: Username for HTTP basic authentication + :param password: Password for HTTP basic authentication + :param discard_unknown_keys: Boolean value indicating whether to discard + unknown properties. A server may send a response that includes additional + properties that are not known by the client in the following scenarios: + 1. The OpenAPI document is incomplete, i.e. it does not match the server + implementation. + 2. The client was generated using an older version of the OpenAPI document + and the server has been upgraded since then. + If a schema in the OpenAPI document defines the additionalProperties attribute, + then all undeclared properties received by the server are injected into the + additional properties map. In that case, there are undeclared properties, and + nothing to discard. + + :Example: + """ + + _default = None + + def __init__( + self, + host="https://api.usepatch.com", + api_key=None, + api_key_prefix=None, + username=None, + password=None, + discard_unknown_keys=False, + ): + """Constructor""" + self.host = host + """Default Base url + """ + self.temp_folder_path = None + """Temp file folder for downloading files + """ + # Authentication Settings + self.api_key = {} + if api_key: + self.api_key = api_key + """dict to store API key(s) + """ + self.api_key_prefix = {} + if api_key_prefix: + self.api_key_prefix = api_key_prefix + """dict to store API prefix (e.g. Bearer) + """ + self.refresh_api_key_hook = None + """function hook to refresh API key if expired + """ + self.username = username + """Username for HTTP basic authentication + """ + self.password = password + """Password for HTTP basic authentication + """ + self.discard_unknown_keys = discard_unknown_keys + self.access_token = None + """access token for OAuth/Bearer + """ + self.logger = {} + """Logging Settings + """ + self.logger["package_logger"] = logging.getLogger("patch_api") + self.logger["urllib3_logger"] = logging.getLogger("urllib3") + self.logger_format = "%(asctime)s %(levelname)s %(message)s" + """Log format + """ + self.logger_stream_handler = None + """Log stream handler + """ + self.logger_file_handler = None + """Log file handler + """ + self.logger_file = None + """Debug file location + """ + self.debug = False + """Debug switch + """ + + self.verify_ssl = True + """SSL/TLS verification + Set this to false to skip verifying SSL certificate when calling API + from https server. + """ + self.ssl_ca_cert = None + """Set this to customize the certificate file to verify the peer. + """ + self.cert_file = None + """client certificate file + """ + self.key_file = None + """client key file + """ + self.assert_hostname = None + """Set this to True/False to enable/disable SSL hostname verification. + """ + + self.connection_pool_maxsize = multiprocessing.cpu_count() * 5 + """urllib3 connection pool's maximum number of connections saved + per pool. urllib3 uses 1 connection as default value, but this is + not the best value when you are making a lot of possibly parallel + requests to the same host, which is often the case here. + cpu_count * 5 is used as default value to increase performance. + """ + + self.proxy = None + """Proxy URL + """ + self.proxy_headers = None + """Proxy headers + """ + self.safe_chars_for_path_param = "" + """Safe chars for path_param + """ + self.retries = None + """Adding retries to override urllib3 default value 3 + """ + # Disable client side validation + self.client_side_validation = True + + def __deepcopy__(self, memo): + cls = self.__class__ + result = cls.__new__(cls) + memo[id(self)] = result + for k, v in self.__dict__.items(): + if k not in ("logger", "logger_file_handler"): + setattr(result, k, copy.deepcopy(v, memo)) + # shallow copy of loggers + result.logger = copy.copy(self.logger) + # use setters to configure loggers + result.logger_file = self.logger_file + result.debug = self.debug + return result + + def __setattr__(self, name, value): + object.__setattr__(self, name, value) + + @classmethod + def set_default(cls, default): + """Set default instance of configuration. + + It stores default configuration, which can be + returned by get_default_copy method. + + :param default: object of Configuration + """ + cls._default = copy.deepcopy(default) + + @classmethod + def get_default_copy(cls): + """Return new instance of configuration. + + This method returns newly created, based on default constructor, + object of Configuration class or returns a copy of default + configuration passed by the set_default method. + + :return: The configuration object. + """ + if cls._default is not None: + return copy.deepcopy(cls._default) + return Configuration() + + @property + def logger_file(self): + """The logger file. + + If the logger_file is None, then add stream handler and remove file + handler. Otherwise, add file handler and remove stream handler. + + :param value: The logger_file path. + :type: str + """ + return self.__logger_file + + @logger_file.setter + def logger_file(self, value): + """The logger file. + + If the logger_file is None, then add stream handler and remove file + handler. Otherwise, add file handler and remove stream handler. + + :param value: The logger_file path. + :type: str + """ + self.__logger_file = value + if self.__logger_file: + # If set logging file, + # then add file handler and remove stream handler. + self.logger_file_handler = logging.FileHandler(self.__logger_file) + self.logger_file_handler.setFormatter(self.logger_formatter) + for _, logger in six.iteritems(self.logger): + logger.addHandler(self.logger_file_handler) + + @property + def debug(self): + """Debug status + + :param value: The debug status, True or False. + :type: bool + """ + return self.__debug + + @debug.setter + def debug(self, value): + """Debug status + + :param value: The debug status, True or False. + :type: bool + """ + self.__debug = value + if self.__debug: + # if debug status is True, turn on debug logging + for _, logger in six.iteritems(self.logger): + logger.setLevel(logging.DEBUG) + # turn on httplib debug + httplib.HTTPConnection.debuglevel = 1 + else: + # if debug status is False, turn off debug logging, + # setting log level to default `logging.WARNING` + for _, logger in six.iteritems(self.logger): + logger.setLevel(logging.WARNING) + # turn off httplib debug + httplib.HTTPConnection.debuglevel = 0 + + @property + def logger_format(self): + """The logger format. + + The logger_formatter will be updated when sets logger_format. + + :param value: The format string. + :type: str + """ + return self.__logger_format + + @logger_format.setter + def logger_format(self, value): + """The logger format. + + The logger_formatter will be updated when sets logger_format. + + :param value: The format string. + :type: str + """ + self.__logger_format = value + self.logger_formatter = logging.Formatter(self.__logger_format) + + def get_api_key_with_prefix(self, identifier): + """Gets API key (with prefix if set). + + :param identifier: The identifier of apiKey. + :return: The token for api key authentication. + """ + if self.refresh_api_key_hook is not None: + self.refresh_api_key_hook(self) + key = self.api_key.get(identifier) + if key: + prefix = self.api_key_prefix.get(identifier) + if prefix: + return "%s %s" % (prefix, key) + else: + return key + + def get_basic_auth_token(self): + """Gets HTTP basic authentication header (string). + + :return: The token for basic HTTP authentication. + """ + username = "" + if self.username is not None: + username = self.username + password = "" + if self.password is not None: + password = self.password + return urllib3.util.make_headers(basic_auth=username + ":" + password).get( + "authorization" + ) + + def auth_settings(self): + """Gets Auth Settings dict for api client. + + :return: The Auth Settings information dict. + """ + auth = {} + if self.access_token is not None: + auth["bearer_auth"] = { + "type": "bearer", + "in": "header", + "key": "Authorization", + "value": "Bearer " + self.access_token, + } + return auth + + def to_debug_report(self): + """Gets the essential information for debugging. + + :return: The report for debugging. + """ + return ( + "Python SDK Debug Report:\n" + "OS: {env}\n" + "Python Version: {pyversion}\n" + "Version of the API: v1\n" + "SDK Package Version: 1.0.0".format(env=sys.platform, pyversion=sys.version) + ) + + def get_host_settings(self): + """Gets an array of host settings + + :return: An array of host settings + """ + return [ + { + "url": "https://{defaultHost}", + "description": "No description provided", + "variables": { + "defaultHost": { + "description": "No description provided", + "default_value": "api.usepatch.com", + } + }, + } + ] + + def get_host_from_settings(self, index, variables=None): + """Gets host URL based on the index and variables + :param index: array index of the host settings + :param variables: hash of variable and the corresponding value + :return: URL based on host settings + """ + variables = {} if variables is None else variables + servers = self.get_host_settings() + + try: + server = servers[index] + except IndexError: + raise ValueError( + "Invalid index {0} when selecting the host settings. " + "Must be less than {1}".format(index, len(servers)) + ) + + url = server["url"] + + # go through variables and replace placeholders + for variable_name, variable in server["variables"].items(): + used_value = variables.get(variable_name, variable["default_value"]) + + if "enum_values" in variable and used_value not in variable["enum_values"]: + raise ValueError( + "The variable `{0}` in the host URL has invalid value " + "{1}. Must be {2}.".format( + variable_name, variables[variable_name], variable["enum_values"] + ) + ) + + url = url.replace("{" + variable_name + "}", used_value) + + return url diff --git a/patch_api/exceptions.py b/patch_api/exceptions.py new file mode 100644 index 0000000..64b8229 --- /dev/null +++ b/patch_api/exceptions.py @@ -0,0 +1,117 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import six + + +class OpenApiException(Exception): + """The base exception class for all OpenAPIExceptions""" + + +class ApiTypeError(OpenApiException, TypeError): + def __init__(self, msg, path_to_item=None, valid_classes=None, key_type=None): + """Raises an exception for TypeErrors + + Args: + msg (str): the exception message + + Keyword Args: + path_to_item (list): a list of keys an indices to get to the + current_item + None if unset + valid_classes (tuple): the primitive classes that current item + should be an instance of + None if unset + key_type (bool): False if our value is a value in a dict + True if it is a key in a dict + False if our item is an item in a list + None if unset + """ + self.path_to_item = path_to_item + self.valid_classes = valid_classes + self.key_type = key_type + full_msg = msg + if path_to_item: + full_msg = "{0} at {1}".format(msg, render_path(path_to_item)) + super(ApiTypeError, self).__init__(full_msg) + + +class ApiValueError(OpenApiException, ValueError): + def __init__(self, msg, path_to_item=None): + """ + Args: + msg (str): the exception message + + Keyword Args: + path_to_item (list) the path to the exception in the + received_data dict. None if unset + """ + + self.path_to_item = path_to_item + full_msg = msg + if path_to_item: + full_msg = "{0} at {1}".format(msg, render_path(path_to_item)) + super(ApiValueError, self).__init__(full_msg) + + +class ApiKeyError(OpenApiException, KeyError): + def __init__(self, msg, path_to_item=None): + """ + Args: + msg (str): the exception message + + Keyword Args: + path_to_item (None/list) the path to the exception in the + received_data dict + """ + self.path_to_item = path_to_item + full_msg = msg + if path_to_item: + full_msg = "{0} at {1}".format(msg, render_path(path_to_item)) + super(ApiKeyError, self).__init__(full_msg) + + +class ApiException(OpenApiException): + def __init__(self, status=None, reason=None, http_resp=None): + if http_resp: + self.status = http_resp.status + self.reason = http_resp.reason + self.body = http_resp.data + self.headers = http_resp.getheaders() + else: + self.status = status + self.reason = reason + self.body = None + self.headers = None + + def __str__(self): + """Custom error messages for exception""" + error_message = "({0})\n" "Reason: {1}\n".format(self.status, self.reason) + if self.headers: + error_message += "HTTP response headers: {0}\n".format(self.headers) + + if self.body: + error_message += "HTTP response body: {0}\n".format(self.body) + + return error_message + + +def render_path(path_to_item): + """Returns a string representation of a path""" + result = "" + for pth in path_to_item: + if isinstance(pth, six.integer_types): + result += "[{0}]".format(pth) + else: + result += "['{0}']".format(pth) + return result diff --git a/patch_api/models/__init__.py b/patch_api/models/__init__.py new file mode 100644 index 0000000..54572e0 --- /dev/null +++ b/patch_api/models/__init__.py @@ -0,0 +1,34 @@ +# coding: utf-8 + +# flake8: noqa +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +# import models into model package +from patch_api.models.allocation import Allocation +from patch_api.models.error_response import ErrorResponse +from patch_api.models.estimate import Estimate +from patch_api.models.estimate_list_response import EstimateListResponse +from patch_api.models.estimate_response import EstimateResponse +from patch_api.models.meta_index_object import MetaIndexObject +from patch_api.models.order import Order +from patch_api.models.order_list_response import OrderListResponse +from patch_api.models.order_response import OrderResponse +from patch_api.models.photo import Photo +from patch_api.models.preference import Preference +from patch_api.models.preference_list_response import PreferenceListResponse +from patch_api.models.preference_response import PreferenceResponse +from patch_api.models.project import Project +from patch_api.models.project_list_response import ProjectListResponse +from patch_api.models.project_response import ProjectResponse +from patch_api.models.standard import Standard diff --git a/patch_api/models/allocation.py b/patch_api/models/allocation.py new file mode 100644 index 0000000..b6629ae --- /dev/null +++ b/patch_api/models/allocation.py @@ -0,0 +1,188 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class Allocation(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"id": "str", "production": "bool", "mass_g": "int"} + + attribute_map = {"id": "id", "production": "production", "mass_g": "mass_g"} + + def __init__( + self, id=None, production=None, mass_g=None, local_vars_configuration=None + ): # noqa: E501 + """Allocation - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._id = None + self._production = None + self._mass_g = None + self.discriminator = None + + self.id = id + self.production = production + self.mass_g = mass_g + + @property + def id(self): + """Gets the id of this Allocation. # noqa: E501 + + A unique uid for the record. UIDs will be prepended by all_prod or all_test depending on the mode it was created in. # noqa: E501 + + :return: The id of this Allocation. # noqa: E501 + :rtype: str + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this Allocation. + + A unique uid for the record. UIDs will be prepended by all_prod or all_test depending on the mode it was created in. # noqa: E501 + + :param id: The id of this Allocation. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and id is None + ): # noqa: E501 + raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 + + self._id = id + + @property + def production(self): + """Gets the production of this Allocation. # noqa: E501 + + A boolean indicating if this project is a production or test mode project. # noqa: E501 + + :return: The production of this Allocation. # noqa: E501 + :rtype: bool + """ + return self._production + + @production.setter + def production(self, production): + """Sets the production of this Allocation. + + A boolean indicating if this project is a production or test mode project. # noqa: E501 + + :param production: The production of this Allocation. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and production is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `production`, must not be `None`" + ) # noqa: E501 + + self._production = production + + @property + def mass_g(self): + """Gets the mass_g of this Allocation. # noqa: E501 + + The amount (in grams) of allocated carbon offsets. # noqa: E501 + + :return: The mass_g of this Allocation. # noqa: E501 + :rtype: int + """ + return self._mass_g + + @mass_g.setter + def mass_g(self, mass_g): + """Sets the mass_g of this Allocation. + + The amount (in grams) of allocated carbon offsets. # noqa: E501 + + :param mass_g: The mass_g of this Allocation. # noqa: E501 + :type: int + """ + if ( + self.local_vars_configuration.client_side_validation and mass_g is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `mass_g`, must not be `None`" + ) # noqa: E501 + + self._mass_g = mass_g + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, Allocation): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, Allocation): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/error_response.py b/patch_api/models/error_response.py new file mode 100644 index 0000000..8303054 --- /dev/null +++ b/patch_api/models/error_response.py @@ -0,0 +1,178 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class ErrorResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"success": "bool", "error": "object", "data": "object"} + + attribute_map = {"success": "success", "error": "error", "data": "data"} + + def __init__( + self, success=None, error=None, data=None, local_vars_configuration=None + ): # noqa: E501 + """ErrorResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._success = None + self._error = None + self._data = None + self.discriminator = None + + self.success = success + self.error = error + self.data = data + + @property + def success(self): + """Gets the success of this ErrorResponse. # noqa: E501 + + + :return: The success of this ErrorResponse. # noqa: E501 + :rtype: bool + """ + return self._success + + @success.setter + def success(self, success): + """Sets the success of this ErrorResponse. + + + :param success: The success of this ErrorResponse. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and success is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `success`, must not be `None`" + ) # noqa: E501 + + self._success = success + + @property + def error(self): + """Gets the error of this ErrorResponse. # noqa: E501 + + + :return: The error of this ErrorResponse. # noqa: E501 + :rtype: object + """ + return self._error + + @error.setter + def error(self, error): + """Sets the error of this ErrorResponse. + + + :param error: The error of this ErrorResponse. # noqa: E501 + :type: object + """ + if ( + self.local_vars_configuration.client_side_validation and error is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `error`, must not be `None`" + ) # noqa: E501 + + self._error = error + + @property + def data(self): + """Gets the data of this ErrorResponse. # noqa: E501 + + + :return: The data of this ErrorResponse. # noqa: E501 + :rtype: object + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this ErrorResponse. + + + :param data: The data of this ErrorResponse. # noqa: E501 + :type: object + """ + + self._data = data + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, ErrorResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, ErrorResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/estimate.py b/patch_api/models/estimate.py new file mode 100644 index 0000000..b64185f --- /dev/null +++ b/patch_api/models/estimate.py @@ -0,0 +1,223 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class Estimate(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"id": "str", "production": "bool", "type": "str", "order": "Order"} + + attribute_map = { + "id": "id", + "production": "production", + "type": "type", + "order": "order", + } + + def __init__( + self, + id=None, + production=None, + type=None, + order=None, + local_vars_configuration=None, + ): # noqa: E501 + """Estimate - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._id = None + self._production = None + self._type = None + self._order = None + self.discriminator = None + + self.id = id + self.production = production + self.type = type + self.order = order + + @property + def id(self): + """Gets the id of this Estimate. # noqa: E501 + + A unique uid for the record. UIDs will be prepended by est_prod or est_test depending on the mode it was created in. # noqa: E501 + + :return: The id of this Estimate. # noqa: E501 + :rtype: str + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this Estimate. + + A unique uid for the record. UIDs will be prepended by est_prod or est_test depending on the mode it was created in. # noqa: E501 + + :param id: The id of this Estimate. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and id is None + ): # noqa: E501 + raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 + + self._id = id + + @property + def production(self): + """Gets the production of this Estimate. # noqa: E501 + + A boolean indicating if this estimate is a production or test mode estimate. # noqa: E501 + + :return: The production of this Estimate. # noqa: E501 + :rtype: bool + """ + return self._production + + @production.setter + def production(self, production): + """Sets the production of this Estimate. + + A boolean indicating if this estimate is a production or test mode estimate. # noqa: E501 + + :param production: The production of this Estimate. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and production is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `production`, must not be `None`" + ) # noqa: E501 + + self._production = production + + @property + def type(self): + """Gets the type of this Estimate. # noqa: E501 + + The type of estimate. Currently mass is the only supported value. # noqa: E501 + + :return: The type of this Estimate. # noqa: E501 + :rtype: str + """ + return self._type + + @type.setter + def type(self, type): + """Sets the type of this Estimate. + + The type of estimate. Currently mass is the only supported value. # noqa: E501 + + :param type: The type of this Estimate. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and type is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `type`, must not be `None`" + ) # noqa: E501 + + self._type = type + + @property + def order(self): + """Gets the order of this Estimate. # noqa: E501 + + An object returning the order associated with this estimate. See the [Order section](/?id=orders) for the full schema. # noqa: E501 + + :return: The order of this Estimate. # noqa: E501 + :rtype: Order + """ + return self._order + + @order.setter + def order(self, order): + """Sets the order of this Estimate. + + An object returning the order associated with this estimate. See the [Order section](/?id=orders) for the full schema. # noqa: E501 + + :param order: The order of this Estimate. # noqa: E501 + :type: Order + """ + + self._order = order + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, Estimate): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, Estimate): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/estimate_list_response.py b/patch_api/models/estimate_list_response.py new file mode 100644 index 0000000..ccb0a68 --- /dev/null +++ b/patch_api/models/estimate_list_response.py @@ -0,0 +1,222 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class EstimateListResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + "success": "bool", + "error": "object", + "data": "list[Estimate]", + "meta": "MetaIndexObject", + } + + attribute_map = { + "success": "success", + "error": "error", + "data": "data", + "meta": "meta", + } + + def __init__( + self, + success=None, + error=None, + data=None, + meta=None, + local_vars_configuration=None, + ): # noqa: E501 + """EstimateListResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._success = None + self._error = None + self._data = None + self._meta = None + self.discriminator = None + + self.success = success + self.error = error + self.data = data + self.meta = meta + + @property + def success(self): + """Gets the success of this EstimateListResponse. # noqa: E501 + + + :return: The success of this EstimateListResponse. # noqa: E501 + :rtype: bool + """ + return self._success + + @success.setter + def success(self, success): + """Sets the success of this EstimateListResponse. + + + :param success: The success of this EstimateListResponse. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and success is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `success`, must not be `None`" + ) # noqa: E501 + + self._success = success + + @property + def error(self): + """Gets the error of this EstimateListResponse. # noqa: E501 + + + :return: The error of this EstimateListResponse. # noqa: E501 + :rtype: object + """ + return self._error + + @error.setter + def error(self, error): + """Sets the error of this EstimateListResponse. + + + :param error: The error of this EstimateListResponse. # noqa: E501 + :type: object + """ + + self._error = error + + @property + def data(self): + """Gets the data of this EstimateListResponse. # noqa: E501 + + + :return: The data of this EstimateListResponse. # noqa: E501 + :rtype: list[Estimate] + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this EstimateListResponse. + + + :param data: The data of this EstimateListResponse. # noqa: E501 + :type: list[Estimate] + """ + if ( + self.local_vars_configuration.client_side_validation and data is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `data`, must not be `None`" + ) # noqa: E501 + + self._data = data + + @property + def meta(self): + """Gets the meta of this EstimateListResponse. # noqa: E501 + + + :return: The meta of this EstimateListResponse. # noqa: E501 + :rtype: MetaIndexObject + """ + return self._meta + + @meta.setter + def meta(self, meta): + """Sets the meta of this EstimateListResponse. + + + :param meta: The meta of this EstimateListResponse. # noqa: E501 + :type: MetaIndexObject + """ + if ( + self.local_vars_configuration.client_side_validation and meta is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `meta`, must not be `None`" + ) # noqa: E501 + + self._meta = meta + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, EstimateListResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, EstimateListResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/estimate_response.py b/patch_api/models/estimate_response.py new file mode 100644 index 0000000..f15ac7c --- /dev/null +++ b/patch_api/models/estimate_response.py @@ -0,0 +1,178 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class EstimateResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"success": "bool", "error": "object", "data": "Estimate"} + + attribute_map = {"success": "success", "error": "error", "data": "data"} + + def __init__( + self, success=None, error=None, data=None, local_vars_configuration=None + ): # noqa: E501 + """EstimateResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._success = None + self._error = None + self._data = None + self.discriminator = None + + self.success = success + self.error = error + self.data = data + + @property + def success(self): + """Gets the success of this EstimateResponse. # noqa: E501 + + + :return: The success of this EstimateResponse. # noqa: E501 + :rtype: bool + """ + return self._success + + @success.setter + def success(self, success): + """Sets the success of this EstimateResponse. + + + :param success: The success of this EstimateResponse. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and success is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `success`, must not be `None`" + ) # noqa: E501 + + self._success = success + + @property + def error(self): + """Gets the error of this EstimateResponse. # noqa: E501 + + + :return: The error of this EstimateResponse. # noqa: E501 + :rtype: object + """ + return self._error + + @error.setter + def error(self, error): + """Sets the error of this EstimateResponse. + + + :param error: The error of this EstimateResponse. # noqa: E501 + :type: object + """ + + self._error = error + + @property + def data(self): + """Gets the data of this EstimateResponse. # noqa: E501 + + + :return: The data of this EstimateResponse. # noqa: E501 + :rtype: Estimate + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this EstimateResponse. + + + :param data: The data of this EstimateResponse. # noqa: E501 + :type: Estimate + """ + if ( + self.local_vars_configuration.client_side_validation and data is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `data`, must not be `None`" + ) # noqa: E501 + + self._data = data + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, EstimateResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, EstimateResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/meta_index_object.py b/patch_api/models/meta_index_object.py new file mode 100644 index 0000000..cbc5313 --- /dev/null +++ b/patch_api/models/meta_index_object.py @@ -0,0 +1,143 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class MetaIndexObject(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"prev_page": "int", "next_page": "int"} + + attribute_map = {"prev_page": "prev_page", "next_page": "next_page"} + + def __init__( + self, prev_page=None, next_page=None, local_vars_configuration=None + ): # noqa: E501 + """MetaIndexObject - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._prev_page = None + self._next_page = None + self.discriminator = None + + self.prev_page = prev_page + self.next_page = next_page + + @property + def prev_page(self): + """Gets the prev_page of this MetaIndexObject. # noqa: E501 + + + :return: The prev_page of this MetaIndexObject. # noqa: E501 + :rtype: int + """ + return self._prev_page + + @prev_page.setter + def prev_page(self, prev_page): + """Sets the prev_page of this MetaIndexObject. + + + :param prev_page: The prev_page of this MetaIndexObject. # noqa: E501 + :type: int + """ + + self._prev_page = prev_page + + @property + def next_page(self): + """Gets the next_page of this MetaIndexObject. # noqa: E501 + + + :return: The next_page of this MetaIndexObject. # noqa: E501 + :rtype: int + """ + return self._next_page + + @next_page.setter + def next_page(self, next_page): + """Sets the next_page of this MetaIndexObject. + + + :param next_page: The next_page of this MetaIndexObject. # noqa: E501 + :type: int + """ + + self._next_page = next_page + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, MetaIndexObject): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, MetaIndexObject): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/order.py b/patch_api/models/order.py new file mode 100644 index 0000000..b27261c --- /dev/null +++ b/patch_api/models/order.py @@ -0,0 +1,429 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class Order(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + "id": "str", + "mass_g": "int", + "production": "bool", + "state": "str", + "allocation_state": "str", + "price_cents_usd": "str", + "patch_fee_cents_usd": "str", + "allocations": "list[Allocation]", + "metadata": "object", + } + + attribute_map = { + "id": "id", + "mass_g": "mass_g", + "production": "production", + "state": "state", + "allocation_state": "allocation_state", + "price_cents_usd": "price_cents_usd", + "patch_fee_cents_usd": "patch_fee_cents_usd", + "allocations": "allocations", + "metadata": "metadata", + } + + def __init__( + self, + id=None, + mass_g=None, + production=None, + state=None, + allocation_state=None, + price_cents_usd=None, + patch_fee_cents_usd=None, + allocations=None, + metadata=None, + local_vars_configuration=None, + ): # noqa: E501 + """Order - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._id = None + self._mass_g = None + self._production = None + self._state = None + self._allocation_state = None + self._price_cents_usd = None + self._patch_fee_cents_usd = None + self._allocations = None + self._metadata = None + self.discriminator = None + + self.id = id + self.mass_g = mass_g + self.production = production + self.state = state + self.allocation_state = allocation_state + self.price_cents_usd = price_cents_usd + self.patch_fee_cents_usd = patch_fee_cents_usd + self.allocations = allocations + self.metadata = metadata + + @property + def id(self): + """Gets the id of this Order. # noqa: E501 + + A unique uid for the record. UIDs will be prepended by ord_prod or ord_test depending on the mode it was created in. # noqa: E501 + + :return: The id of this Order. # noqa: E501 + :rtype: str + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this Order. + + A unique uid for the record. UIDs will be prepended by ord_prod or ord_test depending on the mode it was created in. # noqa: E501 + + :param id: The id of this Order. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and id is None + ): # noqa: E501 + raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 + + self._id = id + + @property + def mass_g(self): + """Gets the mass_g of this Order. # noqa: E501 + + The amount of carbon offsets in grams purchased through this order. # noqa: E501 + + :return: The mass_g of this Order. # noqa: E501 + :rtype: int + """ + return self._mass_g + + @mass_g.setter + def mass_g(self, mass_g): + """Sets the mass_g of this Order. + + The amount of carbon offsets in grams purchased through this order. # noqa: E501 + + :param mass_g: The mass_g of this Order. # noqa: E501 + :type: int + """ + if ( + self.local_vars_configuration.client_side_validation and mass_g is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `mass_g`, must not be `None`" + ) # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and mass_g is not None + and mass_g > 2000000000 + ): # noqa: E501 + raise ValueError( + "Invalid value for `mass_g`, must be a value less than or equal to `2000000000`" + ) # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and mass_g is not None + and mass_g < 1 + ): # noqa: E501 + raise ValueError( + "Invalid value for `mass_g`, must be a value greater than or equal to `1`" + ) # noqa: E501 + + self._mass_g = mass_g + + @property + def production(self): + """Gets the production of this Order. # noqa: E501 + + A boolean indicating if this order is a production or test mode order. # noqa: E501 + + :return: The production of this Order. # noqa: E501 + :rtype: bool + """ + return self._production + + @production.setter + def production(self, production): + """Sets the production of this Order. + + A boolean indicating if this order is a production or test mode order. # noqa: E501 + + :param production: The production of this Order. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and production is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `production`, must not be `None`" + ) # noqa: E501 + + self._production = production + + @property + def state(self): + """Gets the state of this Order. # noqa: E501 + + The current state of the order. # noqa: E501 + + :return: The state of this Order. # noqa: E501 + :rtype: str + """ + return self._state + + @state.setter + def state(self, state): + """Sets the state of this Order. + + The current state of the order. # noqa: E501 + + :param state: The state of this Order. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and state is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `state`, must not be `None`" + ) # noqa: E501 + allowed_values = ["draft", "placed", "complete", "cancelled"] # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and state not in allowed_values + ): # noqa: E501 + raise ValueError( + "Invalid value for `state` ({0}), must be one of {1}".format( # noqa: E501 + state, allowed_values + ) + ) + + self._state = state + + @property + def allocation_state(self): + """Gets the allocation_state of this Order. # noqa: E501 + + The current state of the allocated carbon offsets of the order. # noqa: E501 + + :return: The allocation_state of this Order. # noqa: E501 + :rtype: str + """ + return self._allocation_state + + @allocation_state.setter + def allocation_state(self, allocation_state): + """Sets the allocation_state of this Order. + + The current state of the allocated carbon offsets of the order. # noqa: E501 + + :param allocation_state: The allocation_state of this Order. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation + and allocation_state is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `allocation_state`, must not be `None`" + ) # noqa: E501 + allowed_values = ["pending", "partially_allocated", "allocated"] # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and allocation_state not in allowed_values + ): # noqa: E501 + raise ValueError( + "Invalid value for `allocation_state` ({0}), must be one of {1}".format( # noqa: E501 + allocation_state, allowed_values + ) + ) + + self._allocation_state = allocation_state + + @property + def price_cents_usd(self): + """Gets the price_cents_usd of this Order. # noqa: E501 + + The total price in cents USD of the carbon offsets purchased through this order. # noqa: E501 + + :return: The price_cents_usd of this Order. # noqa: E501 + :rtype: str + """ + return self._price_cents_usd + + @price_cents_usd.setter + def price_cents_usd(self, price_cents_usd): + """Sets the price_cents_usd of this Order. + + The total price in cents USD of the carbon offsets purchased through this order. # noqa: E501 + + :param price_cents_usd: The price_cents_usd of this Order. # noqa: E501 + :type: str + """ + + self._price_cents_usd = price_cents_usd + + @property + def patch_fee_cents_usd(self): + """Gets the patch_fee_cents_usd of this Order. # noqa: E501 + + The Patch Fee in cents USD for this order. # noqa: E501 + + :return: The patch_fee_cents_usd of this Order. # noqa: E501 + :rtype: str + """ + return self._patch_fee_cents_usd + + @patch_fee_cents_usd.setter + def patch_fee_cents_usd(self, patch_fee_cents_usd): + """Sets the patch_fee_cents_usd of this Order. + + The Patch Fee in cents USD for this order. # noqa: E501 + + :param patch_fee_cents_usd: The patch_fee_cents_usd of this Order. # noqa: E501 + :type: str + """ + + self._patch_fee_cents_usd = patch_fee_cents_usd + + @property + def allocations(self): + """Gets the allocations of this Order. # noqa: E501 + + An array containing the inventory allocations for this order. # noqa: E501 + + :return: The allocations of this Order. # noqa: E501 + :rtype: list[Allocation] + """ + return self._allocations + + @allocations.setter + def allocations(self, allocations): + """Sets the allocations of this Order. + + An array containing the inventory allocations for this order. # noqa: E501 + + :param allocations: The allocations of this Order. # noqa: E501 + :type: list[Allocation] + """ + if ( + self.local_vars_configuration.client_side_validation and allocations is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `allocations`, must not be `None`" + ) # noqa: E501 + + self._allocations = allocations + + @property + def metadata(self): + """Gets the metadata of this Order. # noqa: E501 + + An optional JSON object containing metadata for this order. # noqa: E501 + + :return: The metadata of this Order. # noqa: E501 + :rtype: object + """ + return self._metadata + + @metadata.setter + def metadata(self, metadata): + """Sets the metadata of this Order. + + An optional JSON object containing metadata for this order. # noqa: E501 + + :param metadata: The metadata of this Order. # noqa: E501 + :type: object + """ + if ( + self.local_vars_configuration.client_side_validation and metadata is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `metadata`, must not be `None`" + ) # noqa: E501 + + self._metadata = metadata + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, Order): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, Order): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/order_list_response.py b/patch_api/models/order_list_response.py new file mode 100644 index 0000000..a558841 --- /dev/null +++ b/patch_api/models/order_list_response.py @@ -0,0 +1,222 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class OrderListResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + "success": "bool", + "error": "object", + "data": "list[Order]", + "meta": "MetaIndexObject", + } + + attribute_map = { + "success": "success", + "error": "error", + "data": "data", + "meta": "meta", + } + + def __init__( + self, + success=None, + error=None, + data=None, + meta=None, + local_vars_configuration=None, + ): # noqa: E501 + """OrderListResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._success = None + self._error = None + self._data = None + self._meta = None + self.discriminator = None + + self.success = success + self.error = error + self.data = data + self.meta = meta + + @property + def success(self): + """Gets the success of this OrderListResponse. # noqa: E501 + + + :return: The success of this OrderListResponse. # noqa: E501 + :rtype: bool + """ + return self._success + + @success.setter + def success(self, success): + """Sets the success of this OrderListResponse. + + + :param success: The success of this OrderListResponse. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and success is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `success`, must not be `None`" + ) # noqa: E501 + + self._success = success + + @property + def error(self): + """Gets the error of this OrderListResponse. # noqa: E501 + + + :return: The error of this OrderListResponse. # noqa: E501 + :rtype: object + """ + return self._error + + @error.setter + def error(self, error): + """Sets the error of this OrderListResponse. + + + :param error: The error of this OrderListResponse. # noqa: E501 + :type: object + """ + + self._error = error + + @property + def data(self): + """Gets the data of this OrderListResponse. # noqa: E501 + + + :return: The data of this OrderListResponse. # noqa: E501 + :rtype: list[Order] + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this OrderListResponse. + + + :param data: The data of this OrderListResponse. # noqa: E501 + :type: list[Order] + """ + if ( + self.local_vars_configuration.client_side_validation and data is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `data`, must not be `None`" + ) # noqa: E501 + + self._data = data + + @property + def meta(self): + """Gets the meta of this OrderListResponse. # noqa: E501 + + + :return: The meta of this OrderListResponse. # noqa: E501 + :rtype: MetaIndexObject + """ + return self._meta + + @meta.setter + def meta(self, meta): + """Sets the meta of this OrderListResponse. + + + :param meta: The meta of this OrderListResponse. # noqa: E501 + :type: MetaIndexObject + """ + if ( + self.local_vars_configuration.client_side_validation and meta is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `meta`, must not be `None`" + ) # noqa: E501 + + self._meta = meta + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, OrderListResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, OrderListResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/order_response.py b/patch_api/models/order_response.py new file mode 100644 index 0000000..971e9a1 --- /dev/null +++ b/patch_api/models/order_response.py @@ -0,0 +1,178 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class OrderResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"success": "bool", "error": "object", "data": "Order"} + + attribute_map = {"success": "success", "error": "error", "data": "data"} + + def __init__( + self, success=None, error=None, data=None, local_vars_configuration=None + ): # noqa: E501 + """OrderResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._success = None + self._error = None + self._data = None + self.discriminator = None + + self.success = success + self.error = error + self.data = data + + @property + def success(self): + """Gets the success of this OrderResponse. # noqa: E501 + + + :return: The success of this OrderResponse. # noqa: E501 + :rtype: bool + """ + return self._success + + @success.setter + def success(self, success): + """Sets the success of this OrderResponse. + + + :param success: The success of this OrderResponse. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and success is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `success`, must not be `None`" + ) # noqa: E501 + + self._success = success + + @property + def error(self): + """Gets the error of this OrderResponse. # noqa: E501 + + + :return: The error of this OrderResponse. # noqa: E501 + :rtype: object + """ + return self._error + + @error.setter + def error(self, error): + """Sets the error of this OrderResponse. + + + :param error: The error of this OrderResponse. # noqa: E501 + :type: object + """ + + self._error = error + + @property + def data(self): + """Gets the data of this OrderResponse. # noqa: E501 + + + :return: The data of this OrderResponse. # noqa: E501 + :rtype: Order + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this OrderResponse. + + + :param data: The data of this OrderResponse. # noqa: E501 + :type: Order + """ + if ( + self.local_vars_configuration.client_side_validation and data is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `data`, must not be `None`" + ) # noqa: E501 + + self._data = data + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, OrderResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, OrderResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/photo.py b/patch_api/models/photo.py new file mode 100644 index 0000000..65be8bc --- /dev/null +++ b/patch_api/models/photo.py @@ -0,0 +1,151 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class Photo(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"url": "str", "id": "str"} + + attribute_map = {"url": "url", "id": "id"} + + def __init__(self, url=None, id=None, local_vars_configuration=None): # noqa: E501 + """Photo - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._url = None + self._id = None + self.discriminator = None + + self.url = url + self.id = id + + @property + def url(self): + """Gets the url of this Photo. # noqa: E501 + + + :return: The url of this Photo. # noqa: E501 + :rtype: str + """ + return self._url + + @url.setter + def url(self, url): + """Sets the url of this Photo. + + + :param url: The url of this Photo. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and url is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `url`, must not be `None`" + ) # noqa: E501 + + self._url = url + + @property + def id(self): + """Gets the id of this Photo. # noqa: E501 + + + :return: The id of this Photo. # noqa: E501 + :rtype: str + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this Photo. + + + :param id: The id of this Photo. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and id is None + ): # noqa: E501 + raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 + + self._id = id + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, Photo): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, Photo): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/preference.py b/patch_api/models/preference.py new file mode 100644 index 0000000..ad87aa0 --- /dev/null +++ b/patch_api/models/preference.py @@ -0,0 +1,197 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class Preference(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"id": "str", "allocation_percentage": "int", "project": "Project"} + + attribute_map = { + "id": "id", + "allocation_percentage": "allocation_percentage", + "project": "project", + } + + def __init__( + self, + id=None, + allocation_percentage=None, + project=None, + local_vars_configuration=None, + ): # noqa: E501 + """Preference - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._id = None + self._allocation_percentage = None + self._project = None + self.discriminator = None + + self.id = id + self.allocation_percentage = allocation_percentage + self.project = project + + @property + def id(self): + """Gets the id of this Preference. # noqa: E501 + + A unique uid for the record. UIDs will be prepended by pre_prod or pre_test depending on the mode it was created in. # noqa: E501 + + :return: The id of this Preference. # noqa: E501 + :rtype: str + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this Preference. + + A unique uid for the record. UIDs will be prepended by pre_prod or pre_test depending on the mode it was created in. # noqa: E501 + + :param id: The id of this Preference. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and id is None + ): # noqa: E501 + raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 + + self._id = id + + @property + def allocation_percentage(self): + """Gets the allocation_percentage of this Preference. # noqa: E501 + + Percentage of total purchased offsets that should go to a project. Default is 100%. # noqa: E501 + + :return: The allocation_percentage of this Preference. # noqa: E501 + :rtype: int + """ + return self._allocation_percentage + + @allocation_percentage.setter + def allocation_percentage(self, allocation_percentage): + """Sets the allocation_percentage of this Preference. + + Percentage of total purchased offsets that should go to a project. Default is 100%. # noqa: E501 + + :param allocation_percentage: The allocation_percentage of this Preference. # noqa: E501 + :type: int + """ + if ( + self.local_vars_configuration.client_side_validation + and allocation_percentage is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `allocation_percentage`, must not be `None`" + ) # noqa: E501 + + self._allocation_percentage = allocation_percentage + + @property + def project(self): + """Gets the project of this Preference. # noqa: E501 + + An object returning the Project record this Preference is associated with. See the [Project section](/?id=projects) for the full schema. # noqa: E501 + + :return: The project of this Preference. # noqa: E501 + :rtype: Project + """ + return self._project + + @project.setter + def project(self, project): + """Sets the project of this Preference. + + An object returning the Project record this Preference is associated with. See the [Project section](/?id=projects) for the full schema. # noqa: E501 + + :param project: The project of this Preference. # noqa: E501 + :type: Project + """ + if ( + self.local_vars_configuration.client_side_validation and project is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `project`, must not be `None`" + ) # noqa: E501 + + self._project = project + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, Preference): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, Preference): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/preference_list_response.py b/patch_api/models/preference_list_response.py new file mode 100644 index 0000000..0e06bef --- /dev/null +++ b/patch_api/models/preference_list_response.py @@ -0,0 +1,222 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class PreferenceListResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + "success": "bool", + "error": "object", + "data": "list[Preference]", + "meta": "MetaIndexObject", + } + + attribute_map = { + "success": "success", + "error": "error", + "data": "data", + "meta": "meta", + } + + def __init__( + self, + success=None, + error=None, + data=None, + meta=None, + local_vars_configuration=None, + ): # noqa: E501 + """PreferenceListResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._success = None + self._error = None + self._data = None + self._meta = None + self.discriminator = None + + self.success = success + self.error = error + self.data = data + self.meta = meta + + @property + def success(self): + """Gets the success of this PreferenceListResponse. # noqa: E501 + + + :return: The success of this PreferenceListResponse. # noqa: E501 + :rtype: bool + """ + return self._success + + @success.setter + def success(self, success): + """Sets the success of this PreferenceListResponse. + + + :param success: The success of this PreferenceListResponse. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and success is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `success`, must not be `None`" + ) # noqa: E501 + + self._success = success + + @property + def error(self): + """Gets the error of this PreferenceListResponse. # noqa: E501 + + + :return: The error of this PreferenceListResponse. # noqa: E501 + :rtype: object + """ + return self._error + + @error.setter + def error(self, error): + """Sets the error of this PreferenceListResponse. + + + :param error: The error of this PreferenceListResponse. # noqa: E501 + :type: object + """ + + self._error = error + + @property + def data(self): + """Gets the data of this PreferenceListResponse. # noqa: E501 + + + :return: The data of this PreferenceListResponse. # noqa: E501 + :rtype: list[Preference] + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this PreferenceListResponse. + + + :param data: The data of this PreferenceListResponse. # noqa: E501 + :type: list[Preference] + """ + if ( + self.local_vars_configuration.client_side_validation and data is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `data`, must not be `None`" + ) # noqa: E501 + + self._data = data + + @property + def meta(self): + """Gets the meta of this PreferenceListResponse. # noqa: E501 + + + :return: The meta of this PreferenceListResponse. # noqa: E501 + :rtype: MetaIndexObject + """ + return self._meta + + @meta.setter + def meta(self, meta): + """Sets the meta of this PreferenceListResponse. + + + :param meta: The meta of this PreferenceListResponse. # noqa: E501 + :type: MetaIndexObject + """ + if ( + self.local_vars_configuration.client_side_validation and meta is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `meta`, must not be `None`" + ) # noqa: E501 + + self._meta = meta + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, PreferenceListResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, PreferenceListResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/preference_response.py b/patch_api/models/preference_response.py new file mode 100644 index 0000000..73d5fc4 --- /dev/null +++ b/patch_api/models/preference_response.py @@ -0,0 +1,178 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class PreferenceResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"success": "bool", "error": "object", "data": "Preference"} + + attribute_map = {"success": "success", "error": "error", "data": "data"} + + def __init__( + self, success=None, error=None, data=None, local_vars_configuration=None + ): # noqa: E501 + """PreferenceResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._success = None + self._error = None + self._data = None + self.discriminator = None + + self.success = success + self.error = error + self.data = data + + @property + def success(self): + """Gets the success of this PreferenceResponse. # noqa: E501 + + + :return: The success of this PreferenceResponse. # noqa: E501 + :rtype: bool + """ + return self._success + + @success.setter + def success(self, success): + """Sets the success of this PreferenceResponse. + + + :param success: The success of this PreferenceResponse. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and success is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `success`, must not be `None`" + ) # noqa: E501 + + self._success = success + + @property + def error(self): + """Gets the error of this PreferenceResponse. # noqa: E501 + + + :return: The error of this PreferenceResponse. # noqa: E501 + :rtype: object + """ + return self._error + + @error.setter + def error(self, error): + """Sets the error of this PreferenceResponse. + + + :param error: The error of this PreferenceResponse. # noqa: E501 + :type: object + """ + + self._error = error + + @property + def data(self): + """Gets the data of this PreferenceResponse. # noqa: E501 + + + :return: The data of this PreferenceResponse. # noqa: E501 + :rtype: Preference + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this PreferenceResponse. + + + :param data: The data of this PreferenceResponse. # noqa: E501 + :type: Preference + """ + if ( + self.local_vars_configuration.client_side_validation and data is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `data`, must not be `None`" + ) # noqa: E501 + + self._data = data + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, PreferenceResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, PreferenceResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/project.py b/patch_api/models/project.py new file mode 100644 index 0000000..cc59a6f --- /dev/null +++ b/patch_api/models/project.py @@ -0,0 +1,474 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class Project(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + "id": "str", + "production": "bool", + "name": "str", + "description": "str", + "type": "str", + "country": "str", + "developer": "str", + "photos": "list[Photo]", + "average_price_per_tonne_cents_usd": "int", + "remaining_mass_g": "int", + "standard": "Standard", + } + + attribute_map = { + "id": "id", + "production": "production", + "name": "name", + "description": "description", + "type": "type", + "country": "country", + "developer": "developer", + "photos": "photos", + "average_price_per_tonne_cents_usd": "average_price_per_tonne_cents_usd", + "remaining_mass_g": "remaining_mass_g", + "standard": "standard", + } + + def __init__( + self, + id=None, + production=None, + name=None, + description=None, + type=None, + country=None, + developer=None, + photos=None, + average_price_per_tonne_cents_usd=None, + remaining_mass_g=None, + standard=None, + local_vars_configuration=None, + ): # noqa: E501 + """Project - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._id = None + self._production = None + self._name = None + self._description = None + self._type = None + self._country = None + self._developer = None + self._photos = None + self._average_price_per_tonne_cents_usd = None + self._remaining_mass_g = None + self._standard = None + self.discriminator = None + + self.id = id + self.production = production + self.name = name + self.description = description + if type is not None: + self.type = type + self.country = country + self.developer = developer + self.photos = photos + self.average_price_per_tonne_cents_usd = average_price_per_tonne_cents_usd + self.remaining_mass_g = remaining_mass_g + self.standard = standard + + @property + def id(self): + """Gets the id of this Project. # noqa: E501 + + A unique uid for the record. UIDs will be prepended by pro_prod or pro_test depending on the mode it was created in. # noqa: E501 + + :return: The id of this Project. # noqa: E501 + :rtype: str + """ + return self._id + + @id.setter + def id(self, id): + """Sets the id of this Project. + + A unique uid for the record. UIDs will be prepended by pro_prod or pro_test depending on the mode it was created in. # noqa: E501 + + :param id: The id of this Project. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and id is None + ): # noqa: E501 + raise ValueError("Invalid value for `id`, must not be `None`") # noqa: E501 + + self._id = id + + @property + def production(self): + """Gets the production of this Project. # noqa: E501 + + A boolean indicating if this project is a production or test mode project. # noqa: E501 + + :return: The production of this Project. # noqa: E501 + :rtype: bool + """ + return self._production + + @production.setter + def production(self, production): + """Sets the production of this Project. + + A boolean indicating if this project is a production or test mode project. # noqa: E501 + + :param production: The production of this Project. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and production is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `production`, must not be `None`" + ) # noqa: E501 + + self._production = production + + @property + def name(self): + """Gets the name of this Project. # noqa: E501 + + The name of the project. # noqa: E501 + + :return: The name of this Project. # noqa: E501 + :rtype: str + """ + return self._name + + @name.setter + def name(self, name): + """Sets the name of this Project. + + The name of the project. # noqa: E501 + + :param name: The name of this Project. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and name is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `name`, must not be `None`" + ) # noqa: E501 + + self._name = name + + @property + def description(self): + """Gets the description of this Project. # noqa: E501 + + The description of the project. # noqa: E501 + + :return: The description of this Project. # noqa: E501 + :rtype: str + """ + return self._description + + @description.setter + def description(self, description): + """Sets the description of this Project. + + The description of the project. # noqa: E501 + + :param description: The description of this Project. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and description is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `description`, must not be `None`" + ) # noqa: E501 + + self._description = description + + @property + def type(self): + """Gets the type of this Project. # noqa: E501 + + The type of carbon removal project, currently available project types are Biomass, Dac, Forestry, Mineralization, Ocean, Soil. # noqa: E501 + + :return: The type of this Project. # noqa: E501 + :rtype: str + """ + return self._type + + @type.setter + def type(self, type): + """Sets the type of this Project. + + The type of carbon removal project, currently available project types are Biomass, Dac, Forestry, Mineralization, Ocean, Soil. # noqa: E501 + + :param type: The type of this Project. # noqa: E501 + :type: str + """ + allowed_values = [ + "biomass", + "dac", + "forestry", + "mineralization", + "ocean", + "soil", + ] # noqa: E501 + if ( + self.local_vars_configuration.client_side_validation + and type not in allowed_values + ): # noqa: E501 + raise ValueError( + "Invalid value for `type` ({0}), must be one of {1}".format( # noqa: E501 + type, allowed_values + ) + ) + + self._type = type + + @property + def country(self): + """Gets the country of this Project. # noqa: E501 + + The country of origin of the project. # noqa: E501 + + :return: The country of this Project. # noqa: E501 + :rtype: str + """ + return self._country + + @country.setter + def country(self, country): + """Sets the country of this Project. + + The country of origin of the project. # noqa: E501 + + :param country: The country of this Project. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and country is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `country`, must not be `None`" + ) # noqa: E501 + + self._country = country + + @property + def developer(self): + """Gets the developer of this Project. # noqa: E501 + + The name of the project developer. # noqa: E501 + + :return: The developer of this Project. # noqa: E501 + :rtype: str + """ + return self._developer + + @developer.setter + def developer(self, developer): + """Sets the developer of this Project. + + The name of the project developer. # noqa: E501 + + :param developer: The developer of this Project. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and developer is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `developer`, must not be `None`" + ) # noqa: E501 + + self._developer = developer + + @property + def photos(self): + """Gets the photos of this Project. # noqa: E501 + + An array of URLs for photos of the project. # noqa: E501 + + :return: The photos of this Project. # noqa: E501 + :rtype: list[Photo] + """ + return self._photos + + @photos.setter + def photos(self, photos): + """Sets the photos of this Project. + + An array of URLs for photos of the project. # noqa: E501 + + :param photos: The photos of this Project. # noqa: E501 + :type: list[Photo] + """ + + self._photos = photos + + @property + def average_price_per_tonne_cents_usd(self): + """Gets the average_price_per_tonne_cents_usd of this Project. # noqa: E501 + + The average price per tonne in USD cents for carbon offsets supplied by this project. # noqa: E501 + + :return: The average_price_per_tonne_cents_usd of this Project. # noqa: E501 + :rtype: int + """ + return self._average_price_per_tonne_cents_usd + + @average_price_per_tonne_cents_usd.setter + def average_price_per_tonne_cents_usd(self, average_price_per_tonne_cents_usd): + """Sets the average_price_per_tonne_cents_usd of this Project. + + The average price per tonne in USD cents for carbon offsets supplied by this project. # noqa: E501 + + :param average_price_per_tonne_cents_usd: The average_price_per_tonne_cents_usd of this Project. # noqa: E501 + :type: int + """ + if ( + self.local_vars_configuration.client_side_validation + and average_price_per_tonne_cents_usd is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `average_price_per_tonne_cents_usd`, must not be `None`" + ) # noqa: E501 + + self._average_price_per_tonne_cents_usd = average_price_per_tonne_cents_usd + + @property + def remaining_mass_g(self): + """Gets the remaining_mass_g of this Project. # noqa: E501 + + The remaining mass in grams available for purchase for this project. # noqa: E501 + + :return: The remaining_mass_g of this Project. # noqa: E501 + :rtype: int + """ + return self._remaining_mass_g + + @remaining_mass_g.setter + def remaining_mass_g(self, remaining_mass_g): + """Sets the remaining_mass_g of this Project. + + The remaining mass in grams available for purchase for this project. # noqa: E501 + + :param remaining_mass_g: The remaining_mass_g of this Project. # noqa: E501 + :type: int + """ + if ( + self.local_vars_configuration.client_side_validation + and remaining_mass_g is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `remaining_mass_g`, must not be `None`" + ) # noqa: E501 + + self._remaining_mass_g = remaining_mass_g + + @property + def standard(self): + """Gets the standard of this Project. # noqa: E501 + + An object returning the Standard associated with this project. # noqa: E501 + + :return: The standard of this Project. # noqa: E501 + :rtype: Standard + """ + return self._standard + + @standard.setter + def standard(self, standard): + """Sets the standard of this Project. + + An object returning the Standard associated with this project. # noqa: E501 + + :param standard: The standard of this Project. # noqa: E501 + :type: Standard + """ + + self._standard = standard + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, Project): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, Project): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/project_list_response.py b/patch_api/models/project_list_response.py new file mode 100644 index 0000000..466d482 --- /dev/null +++ b/patch_api/models/project_list_response.py @@ -0,0 +1,222 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class ProjectListResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = { + "success": "bool", + "error": "object", + "data": "list[Project]", + "meta": "MetaIndexObject", + } + + attribute_map = { + "success": "success", + "error": "error", + "data": "data", + "meta": "meta", + } + + def __init__( + self, + success=None, + error=None, + data=None, + meta=None, + local_vars_configuration=None, + ): # noqa: E501 + """ProjectListResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._success = None + self._error = None + self._data = None + self._meta = None + self.discriminator = None + + self.success = success + self.error = error + self.data = data + self.meta = meta + + @property + def success(self): + """Gets the success of this ProjectListResponse. # noqa: E501 + + + :return: The success of this ProjectListResponse. # noqa: E501 + :rtype: bool + """ + return self._success + + @success.setter + def success(self, success): + """Sets the success of this ProjectListResponse. + + + :param success: The success of this ProjectListResponse. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and success is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `success`, must not be `None`" + ) # noqa: E501 + + self._success = success + + @property + def error(self): + """Gets the error of this ProjectListResponse. # noqa: E501 + + + :return: The error of this ProjectListResponse. # noqa: E501 + :rtype: object + """ + return self._error + + @error.setter + def error(self, error): + """Sets the error of this ProjectListResponse. + + + :param error: The error of this ProjectListResponse. # noqa: E501 + :type: object + """ + + self._error = error + + @property + def data(self): + """Gets the data of this ProjectListResponse. # noqa: E501 + + + :return: The data of this ProjectListResponse. # noqa: E501 + :rtype: list[Project] + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this ProjectListResponse. + + + :param data: The data of this ProjectListResponse. # noqa: E501 + :type: list[Project] + """ + if ( + self.local_vars_configuration.client_side_validation and data is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `data`, must not be `None`" + ) # noqa: E501 + + self._data = data + + @property + def meta(self): + """Gets the meta of this ProjectListResponse. # noqa: E501 + + + :return: The meta of this ProjectListResponse. # noqa: E501 + :rtype: MetaIndexObject + """ + return self._meta + + @meta.setter + def meta(self, meta): + """Sets the meta of this ProjectListResponse. + + + :param meta: The meta of this ProjectListResponse. # noqa: E501 + :type: MetaIndexObject + """ + if ( + self.local_vars_configuration.client_side_validation and meta is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `meta`, must not be `None`" + ) # noqa: E501 + + self._meta = meta + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, ProjectListResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, ProjectListResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/project_response.py b/patch_api/models/project_response.py new file mode 100644 index 0000000..3de074c --- /dev/null +++ b/patch_api/models/project_response.py @@ -0,0 +1,178 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class ProjectResponse(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"success": "bool", "error": "object", "data": "Project"} + + attribute_map = {"success": "success", "error": "error", "data": "data"} + + def __init__( + self, success=None, error=None, data=None, local_vars_configuration=None + ): # noqa: E501 + """ProjectResponse - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._success = None + self._error = None + self._data = None + self.discriminator = None + + self.success = success + self.error = error + self.data = data + + @property + def success(self): + """Gets the success of this ProjectResponse. # noqa: E501 + + + :return: The success of this ProjectResponse. # noqa: E501 + :rtype: bool + """ + return self._success + + @success.setter + def success(self, success): + """Sets the success of this ProjectResponse. + + + :param success: The success of this ProjectResponse. # noqa: E501 + :type: bool + """ + if ( + self.local_vars_configuration.client_side_validation and success is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `success`, must not be `None`" + ) # noqa: E501 + + self._success = success + + @property + def error(self): + """Gets the error of this ProjectResponse. # noqa: E501 + + + :return: The error of this ProjectResponse. # noqa: E501 + :rtype: object + """ + return self._error + + @error.setter + def error(self, error): + """Sets the error of this ProjectResponse. + + + :param error: The error of this ProjectResponse. # noqa: E501 + :type: object + """ + + self._error = error + + @property + def data(self): + """Gets the data of this ProjectResponse. # noqa: E501 + + + :return: The data of this ProjectResponse. # noqa: E501 + :rtype: Project + """ + return self._data + + @data.setter + def data(self, data): + """Sets the data of this ProjectResponse. + + + :param data: The data of this ProjectResponse. # noqa: E501 + :type: Project + """ + if ( + self.local_vars_configuration.client_side_validation and data is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `data`, must not be `None`" + ) # noqa: E501 + + self._data = data + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, ProjectResponse): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, ProjectResponse): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/models/standard.py b/patch_api/models/standard.py new file mode 100644 index 0000000..40f18a1 --- /dev/null +++ b/patch_api/models/standard.py @@ -0,0 +1,190 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +import pprint +import re # noqa: F401 + +import six + +from patch_api.configuration import Configuration + + +class Standard(object): + """NOTE: This class is auto generated by OpenAPI Generator. + Ref: https://openapi-generator.tech + + Do not edit the class manually. + """ + + """ + Attributes: + openapi_types (dict): The key is attribute name + and the value is attribute type. + attribute_map (dict): The key is attribute name + and the value is json key in definition. + """ + openapi_types = {"type": "str", "acronym": "str", "description": "str"} + + attribute_map = {"type": "type", "acronym": "acronym", "description": "description"} + + def __init__( + self, type=None, acronym=None, description=None, local_vars_configuration=None + ): # noqa: E501 + """Standard - a model defined in OpenAPI""" # noqa: E501 + if local_vars_configuration is None: + local_vars_configuration = Configuration() + self.local_vars_configuration = local_vars_configuration + + self._type = None + self._acronym = None + self._description = None + self.discriminator = None + + self.type = type + self.acronym = acronym + self.description = description + + @property + def type(self): + """Gets the type of this Standard. # noqa: E501 + + The standard type. # noqa: E501 + + :return: The type of this Standard. # noqa: E501 + :rtype: str + """ + return self._type + + @type.setter + def type(self, type): + """Sets the type of this Standard. + + The standard type. # noqa: E501 + + :param type: The type of this Standard. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and type is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `type`, must not be `None`" + ) # noqa: E501 + + self._type = type + + @property + def acronym(self): + """Gets the acronym of this Standard. # noqa: E501 + + The acronym for the standard. # noqa: E501 + + :return: The acronym of this Standard. # noqa: E501 + :rtype: str + """ + return self._acronym + + @acronym.setter + def acronym(self, acronym): + """Sets the acronym of this Standard. + + The acronym for the standard. # noqa: E501 + + :param acronym: The acronym of this Standard. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and acronym is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `acronym`, must not be `None`" + ) # noqa: E501 + + self._acronym = acronym + + @property + def description(self): + """Gets the description of this Standard. # noqa: E501 + + The description of the standard. # noqa: E501 + + :return: The description of this Standard. # noqa: E501 + :rtype: str + """ + return self._description + + @description.setter + def description(self, description): + """Sets the description of this Standard. + + The description of the standard. # noqa: E501 + + :param description: The description of this Standard. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and description is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `description`, must not be `None`" + ) # noqa: E501 + + self._description = description + + def to_dict(self): + """Returns the model properties as a dict""" + result = {} + + for attr, _ in six.iteritems(self.openapi_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list( + map(lambda x: x.to_dict() if hasattr(x, "to_dict") else x, value) + ) + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict( + map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") + else item, + value.items(), + ) + ) + else: + result[attr] = value + + return result + + def to_str(self): + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + """Returns true if both objects are equal""" + if not isinstance(other, Standard): + return False + + return self.to_dict() == other.to_dict() + + def __ne__(self, other): + """Returns true if both objects are not equal""" + if not isinstance(other, Standard): + return True + + return self.to_dict() != other.to_dict() diff --git a/patch_api/rest.py b/patch_api/rest.py new file mode 100644 index 0000000..f67e65f --- /dev/null +++ b/patch_api/rest.py @@ -0,0 +1,397 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import io +import json +import logging +import re +import ssl + +import certifi + +# python 2 and python 3 compatibility library +import six +from six.moves.urllib.parse import urlencode +import urllib3 + +from patch_api.exceptions import ApiException, ApiValueError + + +logger = logging.getLogger(__name__) + + +class RESTResponse(io.IOBase): + def __init__(self, resp): + self.urllib3_response = resp + self.status = resp.status + self.reason = resp.reason + self.data = resp.data + + def getheaders(self): + """Returns a dictionary of the response headers.""" + return self.urllib3_response.getheaders() + + def getheader(self, name, default=None): + """Returns a given response header.""" + return self.urllib3_response.getheader(name, default) + + +class RESTClientObject(object): + def __init__(self, api_key, configuration, pools_size=4, maxsize=None): + # urllib3.PoolManager will pass all kw parameters to connectionpool + # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501 + # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501 + # maxsize is the number of requests to host that are allowed in parallel # noqa: E501 + # Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html # noqa: E501 + + # cert_reqs + if configuration.verify_ssl: + cert_reqs = ssl.CERT_REQUIRED + else: + cert_reqs = ssl.CERT_NONE + + self.api_key = api_key + + # ca_certs + if configuration.ssl_ca_cert: + ca_certs = configuration.ssl_ca_cert + else: + # if not set certificate file, use Mozilla's root certificates. + ca_certs = certifi.where() + + addition_pool_args = {} + if configuration.assert_hostname is not None: + addition_pool_args[ + "assert_hostname" + ] = configuration.assert_hostname # noqa: E501 + + if configuration.retries is not None: + addition_pool_args["retries"] = configuration.retries + + if maxsize is None: + if configuration.connection_pool_maxsize is not None: + maxsize = configuration.connection_pool_maxsize + else: + maxsize = 4 + + # https pool manager + if configuration.proxy: + self.pool_manager = urllib3.ProxyManager( + num_pools=pools_size, + maxsize=maxsize, + cert_reqs=cert_reqs, + ca_certs=ca_certs, + cert_file=configuration.cert_file, + key_file=configuration.key_file, + proxy_url=configuration.proxy, + proxy_headers=configuration.proxy_headers, + **addition_pool_args + ) + else: + self.pool_manager = urllib3.PoolManager( + num_pools=pools_size, + maxsize=maxsize, + cert_reqs=cert_reqs, + ca_certs=ca_certs, + cert_file=configuration.cert_file, + key_file=configuration.key_file, + **addition_pool_args + ) + + def request( + self, + method, + url, + query_params=None, + headers=None, + body=None, + post_params=None, + _preload_content=True, + _request_timeout=None, + ): + """Perform requests. + + :param method: http request method + :param url: http request url + :param query_params: query parameters in the url + :param headers: http request headers + :param body: request json body, for `application/json` + :param post_params: request post parameters, + `application/x-www-form-urlencoded` + and `multipart/form-data` + :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. + """ + method = method.upper() + assert method in ["GET", "HEAD", "DELETE", "POST", "PUT", "PATCH", "OPTIONS"] + + if post_params and body: + raise ApiValueError( + "body parameter cannot be used with post_params parameter." + ) + + post_params = post_params or {} + headers = headers or {} + + timeout = None + if _request_timeout: + if isinstance( + _request_timeout, (int,) if six.PY3 else (int, long) + ): # noqa: E501,F821 + timeout = urllib3.Timeout(total=_request_timeout) + elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2: + timeout = urllib3.Timeout( + connect=_request_timeout[0], read=_request_timeout[1] + ) + + if "Content-Type" not in headers: + headers["Content-Type"] = "application/json" + + if "Authorization" not in headers: + headers["Authorization"] = "Bearer " + self.api_key + + try: + # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE` + if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]: + if query_params: + url += "?" + urlencode(query_params) + if re.search("json", headers["Content-Type"], re.IGNORECASE): + request_body = None + if body is not None: + request_body = json.dumps(body) + r = self.pool_manager.request( + method, + url, + body=request_body, + preload_content=_preload_content, + timeout=timeout, + headers=headers, + ) + elif ( + headers["Content-Type"] == "application/x-www-form-urlencoded" + ): # noqa: E501 + r = self.pool_manager.request( + method, + url, + fields=post_params, + encode_multipart=False, + preload_content=_preload_content, + timeout=timeout, + headers=headers, + ) + elif headers["Content-Type"] == "multipart/form-data": + # must del headers['Content-Type'], or the correct + # Content-Type which generated by urllib3 will be + # overwritten. + del headers["Content-Type"] + r = self.pool_manager.request( + method, + url, + fields=post_params, + encode_multipart=True, + preload_content=_preload_content, + timeout=timeout, + headers=headers, + ) + # Pass a `string` parameter directly in the body to support + # other content types than Json when `body` argument is + # provided in serialized form + elif isinstance(body, str) or isinstance(body, bytes): + request_body = body + r = self.pool_manager.request( + method, + url, + body=request_body, + preload_content=_preload_content, + timeout=timeout, + headers=headers, + ) + else: + # Cannot generate the request from given parameters + msg = """Cannot prepare a request message for provided + arguments. Please check that your arguments match + declared content type.""" + raise ApiException(status=0, reason=msg) + # For `GET`, `HEAD` + else: + r = self.pool_manager.request( + method, + url, + fields=query_params, + preload_content=_preload_content, + timeout=timeout, + headers=headers, + ) + except urllib3.exceptions.SSLError as e: + msg = "{0}\n{1}".format(type(e).__name__, str(e)) + raise ApiException(status=0, reason=msg) + + if _preload_content: + r = RESTResponse(r) + + # In the python 3, the response.data is bytes. + # we need to decode it to string. + if six.PY3: + r.data = r.data.decode("utf8") + + # log response body + logger.debug("response body: %s", r.data) + + if not 200 <= r.status <= 299: + raise ApiException(http_resp=r) + + return r + + def GET( + self, + url, + headers=None, + query_params=None, + _preload_content=True, + _request_timeout=None, + ): + return self.request( + "GET", + url, + headers=headers, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + query_params=query_params, + ) + + def HEAD( + self, + url, + headers=None, + query_params=None, + _preload_content=True, + _request_timeout=None, + ): + return self.request( + "HEAD", + url, + headers=headers, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + query_params=query_params, + ) + + def OPTIONS( + self, + url, + headers=None, + query_params=None, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ): + return self.request( + "OPTIONS", + url, + headers=headers, + query_params=query_params, + post_params=post_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + body=body, + ) + + def DELETE( + self, + url, + headers=None, + query_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ): + return self.request( + "DELETE", + url, + headers=headers, + query_params=query_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + body=body, + ) + + def POST( + self, + url, + headers=None, + query_params=None, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ): + return self.request( + "POST", + url, + headers=headers, + query_params=query_params, + post_params=post_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + body=body, + ) + + def PUT( + self, + url, + headers=None, + query_params=None, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ): + return self.request( + "PUT", + url, + headers=headers, + query_params=query_params, + post_params=post_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + body=body, + ) + + def PATCH( + self, + url, + headers=None, + query_params=None, + post_params=None, + body=None, + _preload_content=True, + _request_timeout=None, + ): + return self.request( + "PATCH", + url, + headers=headers, + query_params=query_params, + post_params=post_params, + _preload_content=_preload_content, + _request_timeout=_request_timeout, + body=body, + ) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..26e1a7b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +certifi >= 14.05.14 +six >= 1.10 +python_dateutil >= 2.5.3 +setuptools >= 21.0.0 +urllib3 >= 1.15.1 +pre-commit >= 2.9.3 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..11433ee --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[flake8] +max-line-length=99 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..5702b6d --- /dev/null +++ b/setup.py @@ -0,0 +1,43 @@ +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from setuptools import setup, find_packages # noqa: H301 + +NAME = "patch-api" +VERSION = "1.0.0" +# To install the library, run the following +# +# python setup.py install +# +# prerequisite: setuptools +# http://pypi.python.org/pypi/setuptools + +REQUIRES = [ + "urllib3 >= 1.25.3", + "python-dateutil", +] + +setup( + name=NAME, + version=VERSION, + description="Patch API V1", + author="Developer Support", + author_email="developers@usepatch.com", + url="", + keywords=["OpenAPI", "OpenAPI-Generator", "Patch API V1"], + python_requires=">=3.6", + install_requires=REQUIRES, + packages=find_packages(exclude=["test", "tests"]), + include_package_data=True, + long_description="""\ + The core API used to integrate with Patch's service # noqa: E501 + """, +) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..4ed3991 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,3 @@ +pytest~=4.6.7 # needed for python 2.7+3.4 +pytest-cov>=2.8.1 +pytest-randomly==1.2.3 # needed for python 2.7+3.4 diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/test/test_estimates_api.py b/test/test_estimates_api.py new file mode 100644 index 0000000..9e5ffe3 --- /dev/null +++ b/test/test_estimates_api.py @@ -0,0 +1,48 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +import os + +from patch_api.api_client import ApiClient + + +class TestEstimatesApi(unittest.TestCase): + """EstimatesApi unit test stubs""" + + def setUp(self): + api_client = ApiClient(api_key=os.environ.get("SANDBOX_API_KEY")) + self.api = api_client.estimates # noqa: E501 + + def tearDown(self): + self.api = None + + def test_create_and_retrieve_mass_estimate(self): + """Test case for create_mass_estimate + + Create an estimate based on mass of CO2 # noqa: E501 + """ + mass_g = 100 + project_id = "pro_test_2b67b11a030b66e0a6dd61a56b49079a" + estimate = self.api.create_mass_estimate(mass_g=mass_g, project_id=project_id) + self.assertTrue(estimate) + self.assertEqual(estimate.data.order.mass_g, mass_g) + + retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id) + self.assertTrue(retrieved_estimate) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_orders_api.py b/test/test_orders_api.py new file mode 100644 index 0000000..976a337 --- /dev/null +++ b/test/test_orders_api.py @@ -0,0 +1,68 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +import os + +from patch_api.api_client import ApiClient + + +class TestOrdersApi(unittest.TestCase): + """OrdersApi unit test stubs""" + + def setUp(self): + api_client = ApiClient(api_key=os.environ.get("SANDBOX_API_KEY")) + self.api = api_client.orders # noqa: E501 + + def tearDown(self): + self.api = None + + def test_interactions_with_an_order(self): + """Test case for create_order, retrieve_order""" + + """Create an order + """ + order = self.api.create_order(mass_g=100) + + self.assertTrue(order) + + """Retrieve an order + """ + order = self.api.create_order(mass_g=100) + retrieved_order = self.api.retrieve_order(id=order.data.id) + + self.assertTrue(retrieved_order) + + def test_retrieve_orders(self): + """Test case for retrieve_orders + + Retrieves a list of orders # noqa: E501 + """ + orders = self.api.retrieve_orders().data + self.assertTrue(isinstance(orders, list)) + + if len(orders) > 1: + retrieved_order = orders[0] + + self.assertTrue(retrieved_order.id) + self.assertEqual(retrieved_order.production, False) + self.assertEqual(retrieved_order.state, "placed") + self.assertEqual(retrieved_order.allocation_state, "allocated") + self.assertEqual(retrieved_order.metadata, {}) + self.assertTrue(isinstance(retrieved_order.allocations, list)) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_preferences_api.py b/test/test_preferences_api.py new file mode 100644 index 0000000..f7b8edf --- /dev/null +++ b/test/test_preferences_api.py @@ -0,0 +1,65 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +import os + +from patch_api.api_client import ApiClient + + +class TestPreferencesApi(unittest.TestCase): + """PreferencesApi unit test stubs""" + + def setUp(self): + api_client = ApiClient(api_key=os.environ.get("SANDBOX_API_KEY")) + self.api = api_client.preferences # noqa: E501 + + def tearDown(self): + self.api = None + + def test_retrieve_preferences_and_preference(self): + """Test case for retrieve_preferences and retrieve_preference + + creates a project preference # noqa: E501 + """ + preferences = self.api.retrieve_preferences() + self.assertTrue(isinstance(preferences.data, list)) + + if len(preferences.data) > 0: + preference_id = preferences.data[0].id + preference = self.api.retrieve_preference(id=preference_id).data + + self.assertTrue(preference.allocation_percentage) + self.assertTrue(preference.id) + self.assertTrue(preference.project) + + def test_delete_and_create_preferences(self): + """Test case for create_preference and delete_preference""" + project_id = "pro_test_0de1a59eed9ff8474e09077ddb3714b2" + preferences = self.api.retrieve_preferences() + if len(preferences.data) > 0: + preference_id = preferences.data[0].id + deleted_preference = self.api.delete_preference(id=preference_id) + + self.assertTrue(deleted_preference) + + preference = self.api.create_preference(project_id=project_id).data + self.assertTrue(preference.allocation_percentage) + self.assertTrue(preference.id) + self.assertTrue(preference.project) + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_projects_api.py b/test/test_projects_api.py new file mode 100644 index 0000000..4be6581 --- /dev/null +++ b/test/test_projects_api.py @@ -0,0 +1,67 @@ +# coding: utf-8 + +""" + Patch API V1 + + The core API used to integrate with Patch's service # noqa: E501 + + The version of the OpenAPI document: v1 + Contact: developers@usepatch.com + Generated by: https://openapi-generator.tech +""" + + +from __future__ import absolute_import + +import unittest +import os + +from patch_api.api_client import ApiClient + + +class TestProjectsApi(unittest.TestCase): + """ProjectsApi unit test stubs""" + + def setUp(self): + api_client = ApiClient(api_key=os.environ.get("SANDBOX_API_KEY")) + self.api = api_client.projects # noqa: E501 + + def tearDown(self): + self.api = None + + def test_retrieve_project(self): + """Test case for retrieve_project + + Retrieves a project # noqa: E501 + """ + project_id = "pro_test_2b67b11a030b66e0a6dd61a56b49079a" + project = self.api.retrieve_project(id=project_id).data + self.assertTrue(project) + self.assertEqual(project.production, False) + self.assertTrue(isinstance(project.photos, list)) + + def test_retrieve_projects(self): + """Test case for retrieve_projects + + Retrieves a list of projects # noqa: E501 + """ + projects = self.api.retrieve_projects().data + self.assertTrue(isinstance(projects, list)) + + if len(projects) > 0: + project = projects[0] + + self.assertEqual(project.production, False) + self.assertEqual(project.average_price_per_tonne_cents_usd, 0) + self.assertEqual(project.remaining_mass_g, 0) + self.assertEqual(project.standard, None) + self.assertEqual(project.name, "Carbo Culture Biochar") + self.assertTrue(project.description) + self.assertEqual(project.country, "US") + self.assertEqual(project.type, "biomass") + self.assertEqual(project.developer, "Carbo Culture Biochar") + self.assertTrue(isinstance(project.photos, list)) + + +if __name__ == "__main__": + unittest.main()