Skip to content

Commit e8d29a0

Browse files
authored
Add support for accept-language headers (#63)
* Add support for accept-language * Correct value
1 parent b51bb15 commit e8d29a0

File tree

9 files changed

+69
-73
lines changed

9 files changed

+69
-73
lines changed

.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.2
1+
3.1.2

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.22.0] - 2022-05-16
9+
10+
### Added
11+
12+
- Adds support for the `accept_language` option on `projects`, to add support for the `Accept-Language` header.
13+
814
## [1.21.0] - 2022-05-03
915

1016
### Added

Gemfile.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
patch_ruby (1.21.0)
4+
patch_ruby (1.22.0)
55
typhoeus (~> 1.0, >= 1.0.1)
66

77
GEM
@@ -73,6 +73,7 @@ PLATFORMS
7373
arm64-darwin-20
7474
arm64-darwin-21
7575
x86_64-darwin-20
76+
x86_64-darwin-21
7677
x86_64-linux
7778

7879
DEPENDENCIES

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ Patch::Project.retrieve_projects(type: type)
189189
# Retrieve a list of projects with at least 100 grams of available offsets
190190
minimum_available_mass = 100
191191
Patch::Project.retrieve_projects(minimum_available_mass: minimum_available_mass)
192+
193+
# Retrieve a project in a different language
194+
# See http://docs.patch.test:3000/#/internationalization for more information and support
195+
project_id = 'pro_test_1234'
196+
Patch::Project.retrieve_project(project_id, accept_language: 'fr')
197+
198+
# Retrieve a list of projects in a different language
199+
# See http://docs.patch.test:3000/#/internationalization for more information and support
200+
Patch::Project.retrieve_projects(accept_language: 'fr')
192201
```
193202
## Contributing
194203

lib/patch_ruby/api/projects_api.rb

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def initialize(api_client = ApiClient.default)
2828
# Retrieves a project available on Patch's platform.
2929
# @param id [String]
3030
# @param [Hash] opts the optional parameters
31+
# @option opts [String] :accept_language
3132
# @return [ProjectResponse]
3233
def retrieve_project(id, opts = {})
3334

@@ -39,6 +40,7 @@ def retrieve_project(id, opts = {})
3940
# Retrieves a project available on Patch's platform.
4041
# @param id [String]
4142
# @param [Hash] opts the optional parameters
43+
# @option opts [String] :accept_language
4244
# @return [Array<(ProjectResponse, Integer, Hash)>] ProjectResponse data, response status code and response headers
4345
def retrieve_project_with_http_info(id, opts = {})
4446
if @api_client.config.debugging
@@ -58,6 +60,7 @@ def retrieve_project_with_http_info(id, opts = {})
5860
header_params = opts[:header_params] || {}
5961
# HTTP header 'Accept' (if needed)
6062
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
63+
header_params[:'Accept-Language'] = opts[:'accept_language'] if !opts[:'accept_language'].nil?
6164

6265
# form parameters
6366
form_params = opts[:form_params] || {}
@@ -95,6 +98,7 @@ def retrieve_project_with_http_info(id, opts = {})
9598
# @option opts [String] :country
9699
# @option opts [String] :type
97100
# @option opts [Integer] :minimum_available_mass
101+
# @option opts [String] :accept_language
98102
# @return [ProjectListResponse]
99103
def retrieve_projects(opts = {})
100104

@@ -109,6 +113,7 @@ def retrieve_projects(opts = {})
109113
# @option opts [String] :country
110114
# @option opts [String] :type
111115
# @option opts [Integer] :minimum_available_mass
116+
# @option opts [String] :accept_language
112117
# @return [Array<(ProjectListResponse, Integer, Hash)>] ProjectListResponse data, response status code and response headers
113118
def retrieve_projects_with_http_info(opts = {})
114119
if @api_client.config.debugging
@@ -128,6 +133,7 @@ def retrieve_projects_with_http_info(opts = {})
128133
header_params = opts[:header_params] || {}
129134
# HTTP header 'Accept' (if needed)
130135
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
136+
header_params[:'Accept-Language'] = opts[:'accept_language'] if !opts[:'accept_language'].nil?
131137

132138
# form parameters
133139
form_params = opts[:form_params] || {}

lib/patch_ruby/api_client.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ApiClient
3131
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
3232
def initialize(config = Configuration.default)
3333
@config = config
34-
@user_agent = "patch-ruby/1.21.0"
34+
@user_agent = "patch-ruby/1.22.0"
3535
@default_headers = {
3636
'Content-Type' => 'application/json',
3737
'User-Agent' => @user_agent

lib/patch_ruby/models/project.rb

-34
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,6 @@ class Project
7777
# An array of objects containing available inventory for a project. Available inventory is grouped by a project's vintage year and returns amount and pricing available for a given vintage year.
7878
attr_accessor :inventory
7979

80-
class EnumAttributeValidator
81-
attr_reader :datatype
82-
attr_reader :allowable_values
83-
84-
def initialize(datatype, allowable_values)
85-
@allowable_values = allowable_values.map do |value|
86-
case datatype.to_s
87-
when /Integer/i
88-
value.to_i
89-
when /Float/i
90-
value.to_f
91-
else
92-
value
93-
end
94-
end
95-
end
96-
97-
def valid?(value)
98-
!value || allowable_values.include?(value)
99-
end
100-
end
101-
10280
# Attribute mapping from ruby-style variable name to JSON key.
10381
def self.attribute_map
10482
{
@@ -351,8 +329,6 @@ def valid?
351329
return false if @production.nil?
352330
return false if @name.nil?
353331
return false if @description.nil?
354-
mechanism_validator = EnumAttributeValidator.new('String', ["removal", "avoidance"])
355-
return false unless mechanism_validator.valid?(@mechanism)
356332
return false if @country.nil?
357333
return false if @developer.nil?
358334
return false if @average_price_per_tonne_cents_usd.nil?
@@ -363,16 +339,6 @@ def valid?
363339
true
364340
end
365341

366-
# Custom attribute writer method checking allowed values (enum).
367-
# @param [Object] mechanism Object to be assigned
368-
def mechanism=(mechanism)
369-
validator = EnumAttributeValidator.new('String', ["removal", "avoidance"])
370-
unless validator.valid?(mechanism)
371-
fail ArgumentError, "invalid value for \"mechanism\", must be one of #{validator.allowable_values}."
372-
end
373-
@mechanism = mechanism
374-
end
375-
376342
# Checks equality by comparing each attribute.
377343
# @param [Object] Object to be compared
378344
def ==(o)

lib/patch_ruby/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
=end
1212

1313
module Patch
14-
VERSION = '1.21.0'
14+
VERSION = '1.22.0'
1515
end

spec/integration/projects_spec.rb

+43-35
Original file line numberDiff line numberDiff line change
@@ -38,40 +38,48 @@
3838
end
3939
end
4040

41-
describe 'returned fields' do
42-
it 'returns the expected fields' do
43-
project = Patch::Project.retrieve_projects(page: 1).data.first
44-
45-
keys = attributes_for(:project).keys
46-
expect(project.to_hash.keys).to include(*keys)
47-
48-
expect(project.photos).to be_an_instance_of(Array)
49-
expect(project.average_price_per_tonne_cents_usd)
50-
.to be_an_instance_of(Integer)
51-
expect(project.remaining_mass_g).to be_an_instance_of(Integer)
52-
expect(project.longitude).to be_an_instance_of(Float)
53-
expect(project.latitude).to be_an_instance_of(Float)
54-
55-
expect(project.technology_type)
56-
.to be_an_instance_of(Patch::TechnologyType)
57-
expect(project.technology_type.name).to be_an_instance_of(String)
58-
expect(project.technology_type.slug).to be_an_instance_of(String)
59-
60-
parent_type = project.technology_type.parent_technology_type
61-
expect(parent_type).to be_an_instance_of(Patch::ParentTechnologyType)
62-
expect(parent_type.name).to be_an_instance_of(String)
63-
expect(parent_type.slug).to be_an_instance_of(String)
64-
65-
expect(project.highlights).to be_an_instance_of(Array)
66-
67-
inventory = project.inventory
68-
expect(inventory).to be_an_instance_of(Array)
69-
expect(inventory[0]).to be_an_instance_of(Patch::Inventory)
70-
expect(inventory[0].vintage_year).to be_an_instance_of(Integer)
71-
expect(inventory[0].amount_available).to be_an_instance_of(Integer)
72-
expect(inventory[0].price).to be_an_instance_of(Integer)
73-
expect(inventory[0].currency).to be_an_instance_of(String)
74-
expect(inventory[0].unit).to be_an_instance_of(String)
75-
end
41+
it 'returns the expected fields' do
42+
project = Patch::Project.retrieve_projects(page: 1).data.first
43+
44+
keys = attributes_for(:project).keys
45+
expect(project.to_hash.keys).to include(*keys)
46+
47+
expect(project.photos).to be_an_instance_of(Array)
48+
expect(project.average_price_per_tonne_cents_usd)
49+
.to be_an_instance_of(Integer)
50+
expect(project.remaining_mass_g).to be_an_instance_of(Integer)
51+
expect(project.longitude).to be_an_instance_of(Float)
52+
expect(project.latitude).to be_an_instance_of(Float)
53+
54+
expect(project.technology_type)
55+
.to be_an_instance_of(Patch::TechnologyType)
56+
expect(project.technology_type.name).to be_an_instance_of(String)
57+
expect(project.technology_type.slug).to be_an_instance_of(String)
58+
59+
parent_type = project.technology_type.parent_technology_type
60+
expect(parent_type).to be_an_instance_of(Patch::ParentTechnologyType)
61+
expect(parent_type.name).to be_an_instance_of(String)
62+
expect(parent_type.slug).to be_an_instance_of(String)
63+
64+
expect(project.highlights).to be_an_instance_of(Array)
65+
66+
inventory = project.inventory
67+
expect(inventory).to be_an_instance_of(Array)
68+
expect(inventory[0]).to be_an_instance_of(Patch::Inventory)
69+
expect(inventory[0].vintage_year).to be_an_instance_of(Integer)
70+
expect(inventory[0].amount_available).to be_an_instance_of(Integer)
71+
expect(inventory[0].price).to be_an_instance_of(Integer)
72+
expect(inventory[0].currency).to be_an_instance_of(String)
73+
expect(inventory[0].unit).to be_an_instance_of(String)
74+
end
75+
76+
it 'retrieves projects in the requested language' do
77+
projects_response = Patch::Project.retrieve_projects(accept_language: 'fr')
78+
79+
expect(projects_response.data.first.name).to include 'Projet' # French
80+
81+
project_id = projects_response.data.first.id
82+
project_response = Patch::Project.retrieve_project(project_id, accept_language: 'fr')
83+
expect(project_response.data.name).to include 'Projet' # Frenc
7684
end
7785
end

0 commit comments

Comments
 (0)