From 835ca571abe032e4b32a67bfe9dc4e6a3210f979 Mon Sep 17 00:00:00 2001 From: Lovisa Svallingson Date: Tue, 16 Feb 2021 09:53:19 -0700 Subject: [PATCH] Add country/type filtering for Projects --- README.md | 10 ++ patch_api/api/estimates_api.py | 14 ++ patch_api/api/orders_api.py | 12 ++ patch_api/api/preferences_api.py | 10 ++ patch_api/api/projects_api.py | 6 + patch_api/models/project.py | 28 ++++ patch_api/models/sdg.py | 236 +++++++++++++++++++++++++++++++ test/test_estimates_api.py | 4 +- test/test_projects_api.py | 24 ++++ 9 files changed, 342 insertions(+), 2 deletions(-) create mode 100644 patch_api/models/sdg.py diff --git a/README.md b/README.md index 6db953b..0fe5ef0 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,10 @@ patch.estimates.retrieve_estimates(page=page) ### Projects Projects are the ways Patch takes CO2 out of the air. They can represent reforestation, enhanced weathering, direct air carbon capture, etc. When you place an order via Patch, it is allocated to a project. +When fetching projects, you can supply filters to the query to narrow your result. Currently supported filters are: +- `country` +- `type` + [API Reference](https://docs.usepatch.com/#/?id=projects) #### Examples @@ -156,6 +160,12 @@ patch.projects.retrieve_project(id=project_id) # Retrieve a list of projects page = 1 # Pass in which page of projects you'd like patch.projects.retrieve_projects(page=page) + +# Retrieve a list of biomass projects +patch.projects.retrieve_projects(type="biomass") + +# Retrieve a list of projects from Canada +patch.projects.retrieve_projects(country="CA") ``` ### Preferences diff --git a/patch_api/api/estimates_api.py b/patch_api/api/estimates_api.py index 2ac3624..a1016eb 100644 --- a/patch_api/api/estimates_api.py +++ b/patch_api/api/estimates_api.py @@ -40,6 +40,8 @@ class EstimatesApi(object): "model", "make", "year", + "type", + "country", ] def __init__(self, api_client=None): @@ -119,6 +121,8 @@ def create_flight_estimate_with_http_info( all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -262,6 +266,8 @@ def create_mass_estimate_with_http_info( all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -405,6 +411,8 @@ def create_shipping_estimate_with_http_info( all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -548,6 +556,8 @@ def create_vehicle_estimate_with_http_info( all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -685,6 +695,8 @@ def retrieve_estimate_with_http_info(self, id, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -812,6 +824,8 @@ def retrieve_estimates_with_http_info(self, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: diff --git a/patch_api/api/orders_api.py b/patch_api/api/orders_api.py index 015c140..e62ae2b 100644 --- a/patch_api/api/orders_api.py +++ b/patch_api/api/orders_api.py @@ -40,6 +40,8 @@ class OrdersApi(object): "model", "make", "year", + "type", + "country", ] def __init__(self, api_client=None): @@ -113,6 +115,8 @@ def cancel_order_with_http_info(self, id, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -242,6 +246,8 @@ def create_order_with_http_info(self, create_order_request, **kwargs): # noqa: all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -379,6 +385,8 @@ def place_order_with_http_info(self, id, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -506,6 +514,8 @@ def retrieve_order_with_http_info(self, id, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -633,6 +643,8 @@ def retrieve_orders_with_http_info(self, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: diff --git a/patch_api/api/preferences_api.py b/patch_api/api/preferences_api.py index fbd78ae..825ed6e 100644 --- a/patch_api/api/preferences_api.py +++ b/patch_api/api/preferences_api.py @@ -40,6 +40,8 @@ class PreferencesApi(object): "model", "make", "year", + "type", + "country", ] def __init__(self, api_client=None): @@ -117,6 +119,8 @@ def create_preference_with_http_info( all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -254,6 +258,8 @@ def delete_preference_with_http_info(self, id, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -381,6 +387,8 @@ def retrieve_preference_with_http_info(self, id, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -508,6 +516,8 @@ def retrieve_preferences_with_http_info(self, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: diff --git a/patch_api/api/projects_api.py b/patch_api/api/projects_api.py index 9497918..5297c88 100644 --- a/patch_api/api/projects_api.py +++ b/patch_api/api/projects_api.py @@ -40,6 +40,8 @@ class ProjectsApi(object): "model", "make", "year", + "type", + "country", ] def __init__(self, api_client=None): @@ -113,6 +115,8 @@ def retrieve_project_with_http_info(self, id, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: @@ -240,6 +244,8 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501 all_params.append("make") all_params.append("model") all_params.append("year") + all_params.append("type") + all_params.append("country") for key, val in six.iteritems(local_var_params["kwargs"]): if key not in all_params: diff --git a/patch_api/models/project.py b/patch_api/models/project.py index cc59a6f..0f30ab0 100644 --- a/patch_api/models/project.py +++ b/patch_api/models/project.py @@ -45,6 +45,7 @@ class Project(object): "average_price_per_tonne_cents_usd": "int", "remaining_mass_g": "int", "standard": "Standard", + "sdgs": "list[Sdg]", } attribute_map = { @@ -59,6 +60,7 @@ class Project(object): "average_price_per_tonne_cents_usd": "average_price_per_tonne_cents_usd", "remaining_mass_g": "remaining_mass_g", "standard": "standard", + "sdgs": "sdgs", } def __init__( @@ -74,6 +76,7 @@ def __init__( average_price_per_tonne_cents_usd=None, remaining_mass_g=None, standard=None, + sdgs=None, local_vars_configuration=None, ): # noqa: E501 """Project - a model defined in OpenAPI""" # noqa: E501 @@ -92,6 +95,7 @@ def __init__( self._average_price_per_tonne_cents_usd = None self._remaining_mass_g = None self._standard = None + self._sdgs = None self.discriminator = None self.id = id @@ -106,6 +110,7 @@ def __init__( self.average_price_per_tonne_cents_usd = average_price_per_tonne_cents_usd self.remaining_mass_g = remaining_mass_g self.standard = standard + self.sdgs = sdgs @property def id(self): @@ -425,6 +430,29 @@ def standard(self, standard): self._standard = standard + @property + def sdgs(self): + """Gets the sdgs of this Project. # noqa: E501 + + An array returning the UN Sustainable Development Goals associated with this project. # noqa: E501 + + :return: The sdgs of this Project. # noqa: E501 + :rtype: list[Sdg] + """ + return self._sdgs + + @sdgs.setter + def sdgs(self, sdgs): + """Sets the sdgs of this Project. + + An array returning the UN Sustainable Development Goals associated with this project. # noqa: E501 + + :param sdgs: The sdgs of this Project. # noqa: E501 + :type: list[Sdg] + """ + + self._sdgs = sdgs + def to_dict(self): """Returns the model properties as a dict""" result = {} diff --git a/patch_api/models/sdg.py b/patch_api/models/sdg.py new file mode 100644 index 0000000..9c3e143 --- /dev/null +++ b/patch_api/models/sdg.py @@ -0,0 +1,236 @@ +# 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 Sdg(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 = { + "title": "str", + "number": "int", + "description": "str", + "url": "str", + } + + attribute_map = { + "title": "title", + "number": "number", + "description": "description", + "url": "url", + } + + def __init__( + self, + title=None, + number=None, + description=None, + url=None, + local_vars_configuration=None, + ): # noqa: E501 + """Sdg - 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._title = None + self._number = None + self._description = None + self._url = None + self.discriminator = None + + self.title = title + self.number = number + self.description = description + self.url = url + + @property + def title(self): + """Gets the title of this Sdg. # noqa: E501 + + The title of the Sustainable Development Goal. # noqa: E501 + + :return: The title of this Sdg. # noqa: E501 + :rtype: str + """ + return self._title + + @title.setter + def title(self, title): + """Sets the title of this Sdg. + + The title of the Sustainable Development Goal. # noqa: E501 + + :param title: The title of this Sdg. # noqa: E501 + :type: str + """ + if ( + self.local_vars_configuration.client_side_validation and title is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `title`, must not be `None`" + ) # noqa: E501 + + self._title = title + + @property + def number(self): + """Gets the number of this Sdg. # noqa: E501 + + The Sustainable Development Goal number. # noqa: E501 + + :return: The number of this Sdg. # noqa: E501 + :rtype: int + """ + return self._number + + @number.setter + def number(self, number): + """Sets the number of this Sdg. + + The Sustainable Development Goal number. # noqa: E501 + + :param number: The number of this Sdg. # noqa: E501 + :type: int + """ + if ( + self.local_vars_configuration.client_side_validation and number is None + ): # noqa: E501 + raise ValueError( + "Invalid value for `number`, must not be `None`" + ) # noqa: E501 + + self._number = number + + @property + def description(self): + """Gets the description of this Sdg. # noqa: E501 + + The description of the Sustainable Development Goal. # noqa: E501 + + :return: The description of this Sdg. # noqa: E501 + :rtype: str + """ + return self._description + + @description.setter + def description(self, description): + """Sets the description of this Sdg. + + The description of the Sustainable Development Goal. # noqa: E501 + + :param description: The description of this Sdg. # 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 url(self): + """Gets the url of this Sdg. # noqa: E501 + + The url to an information page for the Sustainable Development Goal. # noqa: E501 + + :return: The url of this Sdg. # noqa: E501 + :rtype: str + """ + return self._url + + @url.setter + def url(self, url): + """Sets the url of this Sdg. + + The url to an information page for the Sustainable Development Goal. # noqa: E501 + + :param url: The url of this Sdg. # 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 + + 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, Sdg): + 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, Sdg): + return True + + return self.to_dict() != other.to_dict() diff --git a/test/test_estimates_api.py b/test/test_estimates_api.py index 1480c64..290e598 100644 --- a/test/test_estimates_api.py +++ b/test/test_estimates_api.py @@ -53,8 +53,8 @@ def test_create_and_retrieve_flight_estimate(self): distance_m=distance_m, create_order=True ) self.assertEqual(estimate.data.type, "flight") - self.assertEqual(estimate.data.order.mass_g, 1032000) - self.assertEqual(estimate.data.mass_g, 1032000) + self.assertEqual(estimate.data.order.mass_g, 1031697) + self.assertEqual(estimate.data.mass_g, 1031697) retrieved_estimate = self.api.retrieve_estimate(id=estimate.data.id) self.assertTrue(retrieved_estimate) diff --git a/test/test_projects_api.py b/test/test_projects_api.py index f4b4379..1235487 100644 --- a/test/test_projects_api.py +++ b/test/test_projects_api.py @@ -62,6 +62,30 @@ def test_retrieve_projects(self): self.assertEqual(project.developer, "Carbo Culture") self.assertTrue(isinstance(project.photos, list)) + def test_retrieve_biomass_projects(self): + """Test case for retrieve_projects with a type filter + + Retrieves a list of projects # noqa: E501 + """ + project_type = "biomass" + projects = self.api.retrieve_projects(type=project_type).data + self.assertTrue(isinstance(projects, list)) + + for project in projects: + self.assertEqual(project.type, project_type) + + def test_retrieve_american_projects(self): + """Test case for retrieve_projects with a country filter + + Retrieves a list of projects # noqa: E501 + """ + project_country = "US" + projects = self.api.retrieve_projects(country=project_country).data + self.assertTrue(isinstance(projects, list)) + + for project in projects: + self.assertEqual(project.country, project_country) + if __name__ == "__main__": unittest.main()