diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b2e323..250f0e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Adds Sustainable Development Goals (SDGs) field to projects +- Adds the ability to filter Projects on country, type ### Changed diff --git a/README.md b/README.md index 74ed146..19e6f5e 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,10 @@ patch.estimates.retrieve_estimates(page=page) 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 @@ -168,6 +172,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/projects_api.py b/patch_api/api/projects_api.py index 9497918..384f7a7 100644 --- a/patch_api/api/projects_api.py +++ b/patch_api/api/projects_api.py @@ -183,6 +183,8 @@ def retrieve_projects(self, **kwargs): # noqa: E501 :param async_req bool: execute request asynchronously :param int page: + :param str country: + :param str type: :param _preload_content: if False, the urllib3.HTTPResponse object will be returned without reading/decoding response data. Default is True. @@ -208,6 +210,8 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501 :param async_req bool: execute request asynchronously :param int page: + :param str country: + :param str type: :param _return_http_data_only: response data without head status code and headers :param _preload_content: if False, the urllib3.HTTPResponse object will @@ -224,7 +228,7 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501 local_var_params = locals() - all_params = ["page"] # noqa: E501 + all_params = ["page", "country", "type"] # noqa: E501 all_params.append("async_req") all_params.append("_return_http_data_only") all_params.append("_preload_content") @@ -259,6 +263,10 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501 query_params.append([key, kwargs.get(key)]) if "page" in local_var_params: query_params.append(("page", local_var_params["page"])) # noqa: E501 + if "country" in local_var_params: + query_params.append(("country", local_var_params["country"])) # noqa: E501 + if "type" in local_var_params: + query_params.append(("type", local_var_params["type"])) # noqa: E501 header_params = {} 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()