Skip to content

Commit 2dde633

Browse files
authored
Add country/type filtering for Projects (#16)
1 parent 8fec6da commit 2dde633

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Adds Sustainable Development Goals (SDGs) field to projects
13+
- Adds the ability to filter Projects on country, type
1314

1415
### Changed
1516

Diff for: README.md

+10
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ patch.estimates.retrieve_estimates(page=page)
152152

153153
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.
154154

155+
When fetching projects, you can supply filters to the query to narrow your result. Currently supported filters are:
156+
- `country`
157+
- `type`
158+
155159
[API Reference](https://docs.usepatch.com/#/?id=projects)
156160

157161
#### Examples
@@ -168,6 +172,12 @@ patch.projects.retrieve_project(id=project_id)
168172
# Retrieve a list of projects
169173
page = 1 # Pass in which page of projects you'd like
170174
patch.projects.retrieve_projects(page=page)
175+
176+
# Retrieve a list of biomass projects
177+
patch.projects.retrieve_projects(type="biomass")
178+
179+
# Retrieve a list of projects from Canada
180+
patch.projects.retrieve_projects(country="CA")
171181
```
172182

173183
### Preferences

Diff for: patch_api/api/projects_api.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def retrieve_projects(self, **kwargs): # noqa: E501
183183
184184
:param async_req bool: execute request asynchronously
185185
:param int page:
186+
:param str country:
187+
:param str type:
186188
:param _preload_content: if False, the urllib3.HTTPResponse object will
187189
be returned without reading/decoding response
188190
data. Default is True.
@@ -208,6 +210,8 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501
208210
209211
:param async_req bool: execute request asynchronously
210212
:param int page:
213+
:param str country:
214+
:param str type:
211215
:param _return_http_data_only: response data without head status code
212216
and headers
213217
:param _preload_content: if False, the urllib3.HTTPResponse object will
@@ -224,7 +228,7 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501
224228

225229
local_var_params = locals()
226230

227-
all_params = ["page"] # noqa: E501
231+
all_params = ["page", "country", "type"] # noqa: E501
228232
all_params.append("async_req")
229233
all_params.append("_return_http_data_only")
230234
all_params.append("_preload_content")
@@ -259,6 +263,10 @@ def retrieve_projects_with_http_info(self, **kwargs): # noqa: E501
259263
query_params.append([key, kwargs.get(key)])
260264
if "page" in local_var_params:
261265
query_params.append(("page", local_var_params["page"])) # noqa: E501
266+
if "country" in local_var_params:
267+
query_params.append(("country", local_var_params["country"])) # noqa: E501
268+
if "type" in local_var_params:
269+
query_params.append(("type", local_var_params["type"])) # noqa: E501
262270

263271
header_params = {}
264272

Diff for: test/test_projects_api.py

+24
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ def test_retrieve_projects(self):
6262
self.assertEqual(project.developer, "Carbo Culture")
6363
self.assertTrue(isinstance(project.photos, list))
6464

65+
def test_retrieve_biomass_projects(self):
66+
"""Test case for retrieve_projects with a type filter
67+
68+
Retrieves a list of projects # noqa: E501
69+
"""
70+
project_type = "biomass"
71+
projects = self.api.retrieve_projects(type=project_type).data
72+
self.assertTrue(isinstance(projects, list))
73+
74+
for project in projects:
75+
self.assertEqual(project.type, project_type)
76+
77+
def test_retrieve_american_projects(self):
78+
"""Test case for retrieve_projects with a country filter
79+
80+
Retrieves a list of projects # noqa: E501
81+
"""
82+
project_country = "US"
83+
projects = self.api.retrieve_projects(country=project_country).data
84+
self.assertTrue(isinstance(projects, list))
85+
86+
for project in projects:
87+
self.assertEqual(project.country, project_country)
88+
6589

6690
if __name__ == "__main__":
6791
unittest.main()

0 commit comments

Comments
 (0)