Skip to content

Commit f52104d

Browse files
authored
Merge pull request #24 from patch-technology/lovisa/filter-projects
Filter Projects
2 parents 0cc9890 + a0c30e9 commit f52104d

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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 filtering to Projects by country, type
1314

1415
### Changed
1516

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ Patch::Estimate.retrieve_estimates(page: page)
144144
### Projects
145145
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.
146146

147+
When fetching Projects, you can add filters to the query to narrow the result. Currently supported filters are:
148+
149+
- `country`
150+
- `type`
151+
147152
[API Reference](https://docs.usepatch.com/#/?id=projects)
148153

149154
#### Examples
@@ -155,6 +160,14 @@ Patch::Project.retrieve_project(project_id)
155160
# Retrieve a list of projects
156161
page = 1 # Pass in which page of projects you'd like
157162
Patch::Project.retrieve_projects(page: page)
163+
164+
# Retrieve a all projects from the United States
165+
country = 'US' # Pass in the country code of the country you'd like to get Projects from
166+
Patch::Project.retrieve_projects(country: country)
167+
168+
# Retrieve a all biomass projects
169+
type = 'biomass' # Pass in the type of Projects you'd like to get
170+
Patch::Project.retrieve_projects(type: type)
158171
```
159172

160173
### Preferences

lib/patch_ruby/api/projects_api.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def retrieve_project_with_http_info(id, opts = {})
9090
# Retrieves a list of projects available for purchase on Patch's platform.
9191
# @param [Hash] opts the optional parameters
9292
# @option opts [Integer] :page
93+
# @option opts [String] :country
94+
# @option opts [String] :type
9395
# @return [ProjectListResponse]
9496
def retrieve_projects(opts = {})
9597
data, _status_code, _headers = retrieve_projects_with_http_info(opts)
@@ -100,6 +102,8 @@ def retrieve_projects(opts = {})
100102
# Retrieves a list of projects available for purchase on Patch's platform.
101103
# @param [Hash] opts the optional parameters
102104
# @option opts [Integer] :page
105+
# @option opts [String] :country
106+
# @option opts [String] :type
103107
# @return [Array<(ProjectListResponse, Integer, Hash)>] ProjectListResponse data, response status code and response headers
104108
def retrieve_projects_with_http_info(opts = {})
105109
if @api_client.config.debugging
@@ -111,6 +115,8 @@ def retrieve_projects_with_http_info(opts = {})
111115
# query parameters
112116
query_params = opts[:query_params] || {}
113117
query_params[:'page'] = opts[:'page'] if !opts[:'page'].nil?
118+
query_params[:'country'] = opts[:'country'] if !opts[:'country'].nil?
119+
query_params[:'type'] = opts[:'type'] if !opts[:'type'].nil?
114120

115121
# header parameters
116122
header_params = opts[:header_params] || {}

spec/integration/projects_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
expect(retrieve_project_response.data.id).to eq project_id
2323
end
2424

25+
it 'supports filtering projects' do
26+
country = 'US'
27+
projects = Patch::Project.retrieve_projects(country: country)
28+
projects.data.map do |project|
29+
expect(project.country).to eq country
30+
end
31+
32+
type = 'dac'
33+
projects = Patch::Project.retrieve_projects(type: type)
34+
projects.data.map do |project|
35+
expect(project.type).to eq type
36+
end
37+
end
38+
2539
describe 'returned fields' do
2640
before do
2741
@project = Patch::Project.retrieve_projects(page: 1).data.first

0 commit comments

Comments
 (0)