Skip to content

Filter projects #16

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion patch_api/api/projects_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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 = {}

Expand Down
24 changes: 24 additions & 0 deletions test/test_projects_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()