patch_ruby 1.19.0 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -0
- data/Gemfile.lock +3 -1
- data/README.md +22 -11
- data/lib/patch_ruby/api/projects_api.rb +6 -0
- data/lib/patch_ruby/api_client.rb +1 -1
- data/lib/patch_ruby/models/create_order_request.rb +134 -4
- data/lib/patch_ruby/models/inventory.rb +294 -0
- data/lib/patch_ruby/models/order.rb +122 -7
- data/lib/patch_ruby/models/order_inventory.rb +312 -0
- data/lib/patch_ruby/models/order_inventory_project.rb +249 -0
- data/lib/patch_ruby/models/project.rb +23 -40
- data/lib/patch_ruby/version.rb +1 -1
- data/lib/patch_ruby.rb +3 -0
- data/spec/integration/estimates_spec.rb +3 -3
- data/spec/integration/orders_spec.rb +38 -1
- data/spec/integration/projects_spec.rb +43 -26
- data/spec/models/create_order_request_spec.rb +3 -1
- metadata +27 -24
@@ -0,0 +1,249 @@
|
|
1
|
+
=begin
|
2
|
+
#Patch API V1
|
3
|
+
|
4
|
+
#The core API used to integrate with Patch's service
|
5
|
+
|
6
|
+
The version of the OpenAPI document: v1
|
7
|
+
Contact: engineering@usepatch.com
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 5.3.1
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'time'
|
15
|
+
|
16
|
+
module Patch
|
17
|
+
class OrderInventoryProject
|
18
|
+
# The unique uid for a project. UIDs will be prepended by pro_prod or pro_test depending on the mode it was created in.
|
19
|
+
attr_accessor :id
|
20
|
+
|
21
|
+
# The name of the project.
|
22
|
+
attr_accessor :name
|
23
|
+
|
24
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
25
|
+
def self.attribute_map
|
26
|
+
{
|
27
|
+
:'id' => :'id',
|
28
|
+
:'name' => :'name'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns all the JSON keys this model knows about
|
33
|
+
def self.acceptable_attributes
|
34
|
+
attribute_map.values
|
35
|
+
end
|
36
|
+
|
37
|
+
# Attribute type mapping.
|
38
|
+
def self.openapi_types
|
39
|
+
{
|
40
|
+
:'id' => :'String',
|
41
|
+
:'name' => :'String'
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
# List of attributes with nullable: true
|
46
|
+
def self.openapi_nullable
|
47
|
+
Set.new([
|
48
|
+
])
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
# Allows models with corresponding API classes to delegate API operations to those API classes
|
53
|
+
# Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
|
54
|
+
# Eg. Order.create_order delegates to OrdersApi.new.create_order
|
55
|
+
def self.method_missing(message, *args, &block)
|
56
|
+
if Object.const_defined?('Patch::OrderInventoryProjectsApi::OPERATIONS') && Patch::OrderInventoryProjectsApi::OPERATIONS.include?(message)
|
57
|
+
Patch::OrderInventoryProjectsApi.new.send(message, *args)
|
58
|
+
else
|
59
|
+
super
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Initializes the object
|
64
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
65
|
+
def initialize(attributes = {})
|
66
|
+
if (!attributes.is_a?(Hash))
|
67
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::OrderInventoryProject` initialize method"
|
68
|
+
end
|
69
|
+
|
70
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
71
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
72
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
73
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::OrderInventoryProject`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
74
|
+
end
|
75
|
+
h[k.to_sym] = v
|
76
|
+
}
|
77
|
+
|
78
|
+
if attributes.key?(:'id')
|
79
|
+
self.id = attributes[:'id']
|
80
|
+
end
|
81
|
+
|
82
|
+
if attributes.key?(:'name')
|
83
|
+
self.name = attributes[:'name']
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
88
|
+
# @return Array for valid properties with the reasons
|
89
|
+
def list_invalid_properties
|
90
|
+
invalid_properties = Array.new
|
91
|
+
if @id.nil?
|
92
|
+
invalid_properties.push('invalid value for "id", id cannot be nil.')
|
93
|
+
end
|
94
|
+
|
95
|
+
if @name.nil?
|
96
|
+
invalid_properties.push('invalid value for "name", name cannot be nil.')
|
97
|
+
end
|
98
|
+
|
99
|
+
invalid_properties
|
100
|
+
end
|
101
|
+
|
102
|
+
# Check to see if the all the properties in the model are valid
|
103
|
+
# @return true if the model is valid
|
104
|
+
def valid?
|
105
|
+
return false if @id.nil?
|
106
|
+
return false if @name.nil?
|
107
|
+
true
|
108
|
+
end
|
109
|
+
|
110
|
+
# Checks equality by comparing each attribute.
|
111
|
+
# @param [Object] Object to be compared
|
112
|
+
def ==(o)
|
113
|
+
return true if self.equal?(o)
|
114
|
+
self.class == o.class &&
|
115
|
+
id == o.id &&
|
116
|
+
name == o.name
|
117
|
+
end
|
118
|
+
|
119
|
+
# @see the `==` method
|
120
|
+
# @param [Object] Object to be compared
|
121
|
+
def eql?(o)
|
122
|
+
self == o
|
123
|
+
end
|
124
|
+
|
125
|
+
# Calculates hash code according to all attributes.
|
126
|
+
# @return [Integer] Hash code
|
127
|
+
def hash
|
128
|
+
[id, name].hash
|
129
|
+
end
|
130
|
+
|
131
|
+
# Builds the object from hash
|
132
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
133
|
+
# @return [Object] Returns the model itself
|
134
|
+
def self.build_from_hash(attributes)
|
135
|
+
new.build_from_hash(attributes)
|
136
|
+
end
|
137
|
+
|
138
|
+
# Builds the object from hash
|
139
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
140
|
+
# @return [Object] Returns the model itself
|
141
|
+
def build_from_hash(attributes)
|
142
|
+
return nil unless attributes.is_a?(Hash)
|
143
|
+
self.class.openapi_types.each_pair do |key, type|
|
144
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
145
|
+
self.send("#{key}=", nil)
|
146
|
+
elsif type =~ /\AArray<(.*)>/i
|
147
|
+
# check to ensure the input is an array given that the attribute
|
148
|
+
# is documented as an array but the input is not
|
149
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
150
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
151
|
+
end
|
152
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
153
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
self
|
158
|
+
end
|
159
|
+
|
160
|
+
# Deserializes the data based on type
|
161
|
+
# @param string type Data type
|
162
|
+
# @param string value Value to be deserialized
|
163
|
+
# @return [Object] Deserialized data
|
164
|
+
def _deserialize(type, value)
|
165
|
+
case type.to_sym
|
166
|
+
when :Time
|
167
|
+
Time.parse(value)
|
168
|
+
when :Date
|
169
|
+
Date.parse(value)
|
170
|
+
when :String
|
171
|
+
value.to_s
|
172
|
+
when :Integer
|
173
|
+
value.to_i
|
174
|
+
when :Float
|
175
|
+
value.to_f
|
176
|
+
when :Boolean
|
177
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
178
|
+
true
|
179
|
+
else
|
180
|
+
false
|
181
|
+
end
|
182
|
+
when :Object
|
183
|
+
# generic object (usually a Hash), return directly
|
184
|
+
value
|
185
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
186
|
+
inner_type = Regexp.last_match[:inner_type]
|
187
|
+
value.map { |v| _deserialize(inner_type, v) }
|
188
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
189
|
+
k_type = Regexp.last_match[:k_type]
|
190
|
+
v_type = Regexp.last_match[:v_type]
|
191
|
+
{}.tap do |hash|
|
192
|
+
value.each do |k, v|
|
193
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
else # model
|
197
|
+
# models (e.g. Pet) or oneOf
|
198
|
+
klass = Patch.const_get(type)
|
199
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
# Returns the string representation of the object
|
204
|
+
# @return [String] String presentation of the object
|
205
|
+
def to_s
|
206
|
+
to_hash.to_s
|
207
|
+
end
|
208
|
+
|
209
|
+
# to_body is an alias to to_hash (backward compatibility)
|
210
|
+
# @return [Hash] Returns the object in the form of hash
|
211
|
+
def to_body
|
212
|
+
to_hash
|
213
|
+
end
|
214
|
+
|
215
|
+
# Returns the object in the form of hash
|
216
|
+
# @return [Hash] Returns the object in the form of hash
|
217
|
+
def to_hash
|
218
|
+
hash = {}
|
219
|
+
self.class.attribute_map.each_pair do |attr, param|
|
220
|
+
value = self.send(attr)
|
221
|
+
if value.nil?
|
222
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
223
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
224
|
+
end
|
225
|
+
|
226
|
+
hash[param] = _to_hash(value)
|
227
|
+
end
|
228
|
+
hash
|
229
|
+
end
|
230
|
+
|
231
|
+
# Outputs non-array value in the form of hash
|
232
|
+
# For object, use to_hash. Otherwise, just return the value
|
233
|
+
# @param [Object] value Any valid value
|
234
|
+
# @return [Hash] Returns the value in the form of hash
|
235
|
+
def _to_hash(value)
|
236
|
+
if value.is_a?(Array)
|
237
|
+
value.compact.map { |v| _to_hash(v) }
|
238
|
+
elsif value.is_a?(Hash)
|
239
|
+
{}.tap do |hash|
|
240
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
241
|
+
end
|
242
|
+
elsif value.respond_to? :to_hash
|
243
|
+
value.to_hash
|
244
|
+
else
|
245
|
+
value
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
@@ -51,10 +51,10 @@ module Patch
|
|
51
51
|
# An array of URLs for photos of the project.
|
52
52
|
attr_accessor :photos
|
53
53
|
|
54
|
-
# The average price per tonne in USD cents for carbon offsets supplied by this project.
|
54
|
+
# DEPRECATED. The average price per tonne in USD cents for carbon offsets supplied by this project.
|
55
55
|
attr_accessor :average_price_per_tonne_cents_usd
|
56
56
|
|
57
|
-
# The remaining mass in grams available for purchase for this project.
|
57
|
+
# DEPRECATED. The remaining mass in grams available for purchase for this project.
|
58
58
|
attr_accessor :remaining_mass_g
|
59
59
|
|
60
60
|
# The name of the project verifier, when applicable. A verifier is the organization that verifies the calculations of the actual amount of greenhouse gas emissions that have been avoided or sequestered through implementation of the project.
|
@@ -71,30 +71,11 @@ module Patch
|
|
71
71
|
|
72
72
|
attr_accessor :technology_type
|
73
73
|
|
74
|
-
# An array of objects containing the highlight's slug, title, and a URL for the corresponding icon.
|
74
|
+
# An array of objects containing the highlight's slug, title, and a URL for the corresponding icon. A highlight's title is a short string that spotlights a characteristic about the project.
|
75
75
|
attr_accessor :highlights
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
attr_reader :allowable_values
|
80
|
-
|
81
|
-
def initialize(datatype, allowable_values)
|
82
|
-
@allowable_values = allowable_values.map do |value|
|
83
|
-
case datatype.to_s
|
84
|
-
when /Integer/i
|
85
|
-
value.to_i
|
86
|
-
when /Float/i
|
87
|
-
value.to_f
|
88
|
-
else
|
89
|
-
value
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def valid?(value)
|
95
|
-
!value || allowable_values.include?(value)
|
96
|
-
end
|
97
|
-
end
|
77
|
+
# 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.
|
78
|
+
attr_accessor :inventory
|
98
79
|
|
99
80
|
# Attribute mapping from ruby-style variable name to JSON key.
|
100
81
|
def self.attribute_map
|
@@ -118,7 +99,8 @@ module Patch
|
|
118
99
|
:'sdgs' => :'sdgs',
|
119
100
|
:'tagline' => :'tagline',
|
120
101
|
:'technology_type' => :'technology_type',
|
121
|
-
:'highlights' => :'highlights'
|
102
|
+
:'highlights' => :'highlights',
|
103
|
+
:'inventory' => :'inventory'
|
122
104
|
}
|
123
105
|
end
|
124
106
|
|
@@ -149,7 +131,8 @@ module Patch
|
|
149
131
|
:'sdgs' => :'Array<Sdg>',
|
150
132
|
:'tagline' => :'String',
|
151
133
|
:'technology_type' => :'TechnologyType',
|
152
|
-
:'highlights' => :'Array<Highlight>'
|
134
|
+
:'highlights' => :'Array<Highlight>',
|
135
|
+
:'inventory' => :'Array<Inventory>'
|
153
136
|
}
|
154
137
|
end
|
155
138
|
|
@@ -280,6 +263,12 @@ module Patch
|
|
280
263
|
self.highlights = value
|
281
264
|
end
|
282
265
|
end
|
266
|
+
|
267
|
+
if attributes.key?(:'inventory')
|
268
|
+
if (value = attributes[:'inventory']).is_a?(Array)
|
269
|
+
self.inventory = value
|
270
|
+
end
|
271
|
+
end
|
283
272
|
end
|
284
273
|
|
285
274
|
# Show invalid properties with the reasons. Usually used together with valid?
|
@@ -326,6 +315,10 @@ module Patch
|
|
326
315
|
invalid_properties.push('invalid value for "highlights", highlights cannot be nil.')
|
327
316
|
end
|
328
317
|
|
318
|
+
if @inventory.nil?
|
319
|
+
invalid_properties.push('invalid value for "inventory", inventory cannot be nil.')
|
320
|
+
end
|
321
|
+
|
329
322
|
invalid_properties
|
330
323
|
end
|
331
324
|
|
@@ -336,27 +329,16 @@ module Patch
|
|
336
329
|
return false if @production.nil?
|
337
330
|
return false if @name.nil?
|
338
331
|
return false if @description.nil?
|
339
|
-
mechanism_validator = EnumAttributeValidator.new('String', ["removal", "avoidance"])
|
340
|
-
return false unless mechanism_validator.valid?(@mechanism)
|
341
332
|
return false if @country.nil?
|
342
333
|
return false if @developer.nil?
|
343
334
|
return false if @average_price_per_tonne_cents_usd.nil?
|
344
335
|
return false if @remaining_mass_g.nil?
|
345
336
|
return false if @technology_type.nil?
|
346
337
|
return false if @highlights.nil?
|
338
|
+
return false if @inventory.nil?
|
347
339
|
true
|
348
340
|
end
|
349
341
|
|
350
|
-
# Custom attribute writer method checking allowed values (enum).
|
351
|
-
# @param [Object] mechanism Object to be assigned
|
352
|
-
def mechanism=(mechanism)
|
353
|
-
validator = EnumAttributeValidator.new('String', ["removal", "avoidance"])
|
354
|
-
unless validator.valid?(mechanism)
|
355
|
-
fail ArgumentError, "invalid value for \"mechanism\", must be one of #{validator.allowable_values}."
|
356
|
-
end
|
357
|
-
@mechanism = mechanism
|
358
|
-
end
|
359
|
-
|
360
342
|
# Checks equality by comparing each attribute.
|
361
343
|
# @param [Object] Object to be compared
|
362
344
|
def ==(o)
|
@@ -381,7 +363,8 @@ module Patch
|
|
381
363
|
sdgs == o.sdgs &&
|
382
364
|
tagline == o.tagline &&
|
383
365
|
technology_type == o.technology_type &&
|
384
|
-
highlights == o.highlights
|
366
|
+
highlights == o.highlights &&
|
367
|
+
inventory == o.inventory
|
385
368
|
end
|
386
369
|
|
387
370
|
# @see the `==` method
|
@@ -393,7 +376,7 @@ module Patch
|
|
393
376
|
# Calculates hash code according to all attributes.
|
394
377
|
# @return [Integer] Hash code
|
395
378
|
def hash
|
396
|
-
[id, production, name, description, type, mechanism, country, state, latitude, longitude, developer, photos, average_price_per_tonne_cents_usd, remaining_mass_g, verifier, standard, sdgs, tagline, technology_type, highlights].hash
|
379
|
+
[id, production, name, description, type, mechanism, country, state, latitude, longitude, developer, photos, average_price_per_tonne_cents_usd, remaining_mass_g, verifier, standard, sdgs, tagline, technology_type, highlights, inventory].hash
|
397
380
|
end
|
398
381
|
|
399
382
|
# Builds the object from hash
|
data/lib/patch_ruby/version.rb
CHANGED
data/lib/patch_ruby.rb
CHANGED
@@ -32,8 +32,11 @@ require 'patch_ruby/models/estimate'
|
|
32
32
|
require 'patch_ruby/models/estimate_list_response'
|
33
33
|
require 'patch_ruby/models/estimate_response'
|
34
34
|
require 'patch_ruby/models/highlight'
|
35
|
+
require 'patch_ruby/models/inventory'
|
35
36
|
require 'patch_ruby/models/meta_index_object'
|
36
37
|
require 'patch_ruby/models/order'
|
38
|
+
require 'patch_ruby/models/order_inventory'
|
39
|
+
require 'patch_ruby/models/order_inventory_project'
|
37
40
|
require 'patch_ruby/models/order_list_response'
|
38
41
|
require 'patch_ruby/models/order_response'
|
39
42
|
require 'patch_ruby/models/parent_technology_type'
|
@@ -27,7 +27,7 @@ RSpec.describe 'Estimates Integration' do
|
|
27
27
|
)
|
28
28
|
|
29
29
|
expect(flight_estimate.data.type).to eq 'flight'
|
30
|
-
expect(flight_estimate.data.mass_g).to
|
30
|
+
expect(flight_estimate.data.mass_g).to be >= 1_000_000
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'supports creating flight estimates with origin and destination' do
|
@@ -60,8 +60,8 @@ RSpec.describe 'Estimates Integration' do
|
|
60
60
|
)
|
61
61
|
|
62
62
|
expect(vehicle_estimate.data.type).to eq 'vehicle'
|
63
|
-
expect(vehicle_estimate.data.mass_g).to
|
64
|
-
expect(vehicle_estimate.data.order.
|
63
|
+
expect(vehicle_estimate.data.mass_g).to be >= 1_000
|
64
|
+
expect(vehicle_estimate.data.order.amount).to be >= 1_000
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'supports creating vehicle estimates with partial information' do
|
@@ -94,7 +94,7 @@ RSpec.describe 'Orders Integration' do
|
|
94
94
|
expect(create_order_response.data.state).to eq("draft")
|
95
95
|
end
|
96
96
|
|
97
|
-
|
97
|
+
it 'supports place and cancel for orders created via an estimate' do
|
98
98
|
create_estimate_to_place_response = Patch::Estimate.create_mass_estimate(mass_g: 100, create_order: true)
|
99
99
|
order_to_place_id = create_estimate_to_place_response.data.order.id
|
100
100
|
|
@@ -107,4 +107,41 @@ RSpec.describe 'Orders Integration' do
|
|
107
107
|
cancel_order_response = Patch::Order.cancel_order(order_to_cancel_id)
|
108
108
|
expect(cancel_order_response.data.state).to eq 'cancelled'
|
109
109
|
end
|
110
|
+
|
111
|
+
it 'supports create with a vintage year' do
|
112
|
+
create_order_response =
|
113
|
+
Patch::Order.create_order(mass_g: 100, vintage_year: 2022)
|
114
|
+
|
115
|
+
expect(create_order_response.success).to eq true
|
116
|
+
expect(create_order_response.data.id).not_to be_nil
|
117
|
+
expect(create_order_response.data.mass_g).to eq(100)
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'supports create with an amount and unit' do
|
121
|
+
create_order_response =
|
122
|
+
Patch::Order.create_order(amount: 100, unit: "g")
|
123
|
+
|
124
|
+
expect(create_order_response.success).to eq true
|
125
|
+
expect(create_order_response.data.id).not_to be_nil
|
126
|
+
expect(create_order_response.data.amount).to eq(100)
|
127
|
+
expect(create_order_response.data.unit).to eq("g")
|
128
|
+
expect(create_order_response.data.inventory[0]).to be_an_instance_of(
|
129
|
+
Patch::OrderInventory
|
130
|
+
)
|
131
|
+
expect(create_order_response.data.inventory[0].project).to be_an_instance_of(
|
132
|
+
Patch::OrderInventoryProject
|
133
|
+
)
|
134
|
+
expect(create_order_response.data.inventory[0].unit).to eq("g")
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'supports create with a total price and currency' do
|
138
|
+
create_order_response =
|
139
|
+
Patch::Order.create_order(total_price: 100, currency: "EUR")
|
140
|
+
|
141
|
+
expect(create_order_response.success).to eq true
|
142
|
+
expect(create_order_response.data.id).not_to be_nil
|
143
|
+
expect(create_order_response.data.price + create_order_response.data.patch_fee
|
144
|
+
).to be_within(1).of(100)
|
145
|
+
expect(create_order_response.data.currency).to eq "EUR"
|
146
|
+
end
|
110
147
|
end
|
@@ -38,31 +38,48 @@ RSpec.describe 'Projects Integration' do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
67
84
|
end
|
68
85
|
end
|
@@ -30,7 +30,9 @@ describe 'CreateOrderRequest' do
|
|
30
30
|
it_behaves_like "a generated class" do
|
31
31
|
let(:instance) { @instance }
|
32
32
|
let(:instance_hash) { { project_id: @instance.project_id, mass_g: @instance.mass_g, total_price_cents_usd: @instance.total_price_cents_usd, metadata: @instance.metadata } }
|
33
|
-
let(:nullable_properties)
|
33
|
+
let(:nullable_properties) do
|
34
|
+
Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year total_price currency amount unit])
|
35
|
+
end
|
34
36
|
end
|
35
37
|
|
36
38
|
describe 'test an instance of CreateOrderRequest' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: patch_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.22.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patch Technology
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -115,8 +115,11 @@ files:
|
|
115
115
|
- lib/patch_ruby/models/estimate_list_response.rb
|
116
116
|
- lib/patch_ruby/models/estimate_response.rb
|
117
117
|
- lib/patch_ruby/models/highlight.rb
|
118
|
+
- lib/patch_ruby/models/inventory.rb
|
118
119
|
- lib/patch_ruby/models/meta_index_object.rb
|
119
120
|
- lib/patch_ruby/models/order.rb
|
121
|
+
- lib/patch_ruby/models/order_inventory.rb
|
122
|
+
- lib/patch_ruby/models/order_inventory_project.rb
|
120
123
|
- lib/patch_ruby/models/order_list_response.rb
|
121
124
|
- lib/patch_ruby/models/order_response.rb
|
122
125
|
- lib/patch_ruby/models/parent_technology_type.rb
|
@@ -200,47 +203,47 @@ specification_version: 4
|
|
200
203
|
summary: Ruby wrapper for the Patch API
|
201
204
|
test_files:
|
202
205
|
- spec/api/projects_api_spec.rb
|
206
|
+
- spec/api/orders_api_spec.rb
|
203
207
|
- spec/api/estimates_api_spec.rb
|
204
208
|
- spec/api/technology_types_api_spec.rb
|
205
|
-
- spec/api/orders_api_spec.rb
|
206
209
|
- spec/api_client_spec.rb
|
207
210
|
- spec/configuration_spec.rb
|
208
211
|
- spec/constants.rb
|
209
|
-
- spec/factories/project_list_responses.rb
|
210
|
-
- spec/factories/orders.rb
|
211
212
|
- spec/factories/estimates.rb
|
212
|
-
- spec/factories/
|
213
|
-
- spec/factories/create_mass_estimate_requests.rb
|
214
|
-
- spec/factories/estimate_list_responses.rb
|
213
|
+
- spec/factories/meta_index_objects.rb
|
215
214
|
- spec/factories/order_responses.rb
|
215
|
+
- spec/factories/orders.rb
|
216
|
+
- spec/factories/estimate_responses.rb
|
217
|
+
- spec/factories/project_list_responses.rb
|
216
218
|
- spec/factories/projects.rb
|
217
|
-
- spec/factories/technology_type.rb
|
218
|
-
- spec/factories/parent_technology_type.rb
|
219
|
-
- spec/factories/order_list_responses.rb
|
220
|
-
- spec/factories/error_responses.rb
|
221
219
|
- spec/factories/allocations.rb
|
220
|
+
- spec/factories/error_responses.rb
|
222
221
|
- spec/factories/project_responses.rb
|
222
|
+
- spec/factories/create_order_requests.rb
|
223
|
+
- spec/factories/technology_type.rb
|
224
|
+
- spec/factories/estimate_list_responses.rb
|
225
|
+
- spec/factories/create_mass_estimate_requests.rb
|
223
226
|
- spec/factories/sdgs.rb
|
224
|
-
- spec/factories/
|
225
|
-
- spec/factories/
|
226
|
-
- spec/integration/projects_spec.rb
|
227
|
+
- spec/factories/parent_technology_type.rb
|
228
|
+
- spec/factories/order_list_responses.rb
|
227
229
|
- spec/integration/estimates_spec.rb
|
228
|
-
- spec/integration/orders_spec.rb
|
229
230
|
- spec/integration/projects/technology_types_spec.rb
|
231
|
+
- spec/integration/projects_spec.rb
|
232
|
+
- spec/integration/orders_spec.rb
|
233
|
+
- spec/models/order_spec.rb
|
234
|
+
- spec/models/project_spec.rb
|
235
|
+
- spec/models/project_list_response_spec.rb
|
236
|
+
- spec/models/project_response_spec.rb
|
237
|
+
- spec/models/estimate_list_response_spec.rb
|
238
|
+
- spec/models/estimate_response_spec.rb
|
239
|
+
- spec/models/order_list_response_spec.rb
|
230
240
|
- spec/models/estimate_spec.rb
|
231
241
|
- spec/models/create_order_request_spec.rb
|
242
|
+
- spec/models/meta_index_object_spec.rb
|
232
243
|
- spec/models/create_mass_estimate_request_spec.rb
|
233
244
|
- spec/models/error_response_spec.rb
|
234
|
-
- spec/models/order_list_response_spec.rb
|
235
245
|
- spec/models/order_response_spec.rb
|
236
|
-
- spec/models/estimate_response_spec.rb
|
237
|
-
- spec/models/order_spec.rb
|
238
|
-
- spec/models/project_spec.rb
|
239
|
-
- spec/models/project_list_response_spec.rb
|
240
|
-
- spec/models/project_response_spec.rb
|
241
246
|
- spec/models/allocation_spec.rb
|
242
|
-
- spec/models/meta_index_object_spec.rb
|
243
|
-
- spec/models/estimate_list_response_spec.rb
|
244
247
|
- spec/patch_ruby_spec.rb
|
245
248
|
- spec/spec_helper.rb
|
246
249
|
- spec/support/shared/generated_classes.rb
|