patch_ruby 1.20.0 → 1.21.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,9 +71,12 @@ 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. A highlight's title is a short string that spotlights a characteristic about the project.
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
+ # 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
79
+
77
80
  class EnumAttributeValidator
78
81
  attr_reader :datatype
79
82
  attr_reader :allowable_values
@@ -118,7 +121,8 @@ module Patch
118
121
  :'sdgs' => :'sdgs',
119
122
  :'tagline' => :'tagline',
120
123
  :'technology_type' => :'technology_type',
121
- :'highlights' => :'highlights'
124
+ :'highlights' => :'highlights',
125
+ :'inventory' => :'inventory'
122
126
  }
123
127
  end
124
128
 
@@ -149,7 +153,8 @@ module Patch
149
153
  :'sdgs' => :'Array<Sdg>',
150
154
  :'tagline' => :'String',
151
155
  :'technology_type' => :'TechnologyType',
152
- :'highlights' => :'Array<Highlight>'
156
+ :'highlights' => :'Array<Highlight>',
157
+ :'inventory' => :'Array<Inventory>'
153
158
  }
154
159
  end
155
160
 
@@ -280,6 +285,12 @@ module Patch
280
285
  self.highlights = value
281
286
  end
282
287
  end
288
+
289
+ if attributes.key?(:'inventory')
290
+ if (value = attributes[:'inventory']).is_a?(Array)
291
+ self.inventory = value
292
+ end
293
+ end
283
294
  end
284
295
 
285
296
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -326,6 +337,10 @@ module Patch
326
337
  invalid_properties.push('invalid value for "highlights", highlights cannot be nil.')
327
338
  end
328
339
 
340
+ if @inventory.nil?
341
+ invalid_properties.push('invalid value for "inventory", inventory cannot be nil.')
342
+ end
343
+
329
344
  invalid_properties
330
345
  end
331
346
 
@@ -344,6 +359,7 @@ module Patch
344
359
  return false if @remaining_mass_g.nil?
345
360
  return false if @technology_type.nil?
346
361
  return false if @highlights.nil?
362
+ return false if @inventory.nil?
347
363
  true
348
364
  end
349
365
 
@@ -381,7 +397,8 @@ module Patch
381
397
  sdgs == o.sdgs &&
382
398
  tagline == o.tagline &&
383
399
  technology_type == o.technology_type &&
384
- highlights == o.highlights
400
+ highlights == o.highlights &&
401
+ inventory == o.inventory
385
402
  end
386
403
 
387
404
  # @see the `==` method
@@ -393,7 +410,7 @@ module Patch
393
410
  # Calculates hash code according to all attributes.
394
411
  # @return [Integer] Hash code
395
412
  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
413
+ [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
414
  end
398
415
 
399
416
  # Builds the object from hash
@@ -11,5 +11,5 @@ OpenAPI Generator version: 5.3.1
11
11
  =end
12
12
 
13
13
  module Patch
14
- VERSION = '1.20.0'
14
+ VERSION = '1.21.0'
15
15
  end
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 eq 1_000_622
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 eq 5_500
64
- expect(vehicle_estimate.data.order.mass_g).to eq 5_500
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
@@ -116,4 +116,32 @@ RSpec.describe 'Orders Integration' do
116
116
  expect(create_order_response.data.id).not_to be_nil
117
117
  expect(create_order_response.data.mass_g).to eq(100)
118
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
119
147
  end
@@ -63,6 +63,15 @@ RSpec.describe 'Projects Integration' do
63
63
  expect(parent_type.slug).to be_an_instance_of(String)
64
64
 
65
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)
66
75
  end
67
76
  end
68
77
  end
@@ -31,7 +31,7 @@ describe 'CreateOrderRequest' 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
33
  let(:nullable_properties) do
34
- Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year])
34
+ Set.new(%i[mass_g total_price_cents_usd project_id metadata state vintage_year total_price currency amount unit])
35
35
  end
36
36
  end
37
37
 
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.20.0
4
+ version: 1.21.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-04-18 00:00:00.000000000 Z
11
+ date: 2022-05-04 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
@@ -201,46 +204,46 @@ summary: Ruby wrapper for the Patch API
201
204
  test_files:
202
205
  - spec/api/technology_types_api_spec.rb
203
206
  - spec/api/orders_api_spec.rb
204
- - spec/api/estimates_api_spec.rb
205
207
  - spec/api/projects_api_spec.rb
208
+ - spec/api/estimates_api_spec.rb
206
209
  - spec/api_client_spec.rb
207
210
  - spec/configuration_spec.rb
208
211
  - spec/constants.rb
209
- - spec/factories/allocations.rb
210
- - spec/factories/create_mass_estimate_requests.rb
211
- - spec/factories/meta_index_objects.rb
212
- - spec/factories/estimate_list_responses.rb
213
- - spec/factories/order_list_responses.rb
214
- - spec/factories/parent_technology_type.rb
215
212
  - spec/factories/create_order_requests.rb
213
+ - spec/factories/estimate_list_responses.rb
216
214
  - spec/factories/sdgs.rb
217
- - spec/factories/order_responses.rb
218
- - spec/factories/orders.rb
219
- - spec/factories/technology_type.rb
215
+ - spec/factories/allocations.rb
216
+ - spec/factories/parent_technology_type.rb
220
217
  - spec/factories/project_responses.rb
221
- - spec/factories/estimate_responses.rb
218
+ - spec/factories/order_responses.rb
222
219
  - spec/factories/project_list_responses.rb
220
+ - spec/factories/estimates.rb
221
+ - spec/factories/technology_type.rb
223
222
  - spec/factories/error_responses.rb
223
+ - spec/factories/orders.rb
224
+ - spec/factories/meta_index_objects.rb
224
225
  - spec/factories/projects.rb
225
- - spec/factories/estimates.rb
226
- - spec/integration/estimates_spec.rb
227
- - spec/integration/projects/technology_types_spec.rb
226
+ - spec/factories/create_mass_estimate_requests.rb
227
+ - spec/factories/order_list_responses.rb
228
+ - spec/factories/estimate_responses.rb
228
229
  - spec/integration/projects_spec.rb
230
+ - spec/integration/projects/technology_types_spec.rb
231
+ - spec/integration/estimates_spec.rb
229
232
  - spec/integration/orders_spec.rb
230
- - spec/models/project_response_spec.rb
231
- - spec/models/project_list_response_spec.rb
232
- - spec/models/create_order_request_spec.rb
233
- - spec/models/estimate_list_response_spec.rb
234
233
  - spec/models/estimate_spec.rb
234
+ - spec/models/create_mass_estimate_request_spec.rb
235
+ - spec/models/estimate_list_response_spec.rb
236
+ - spec/models/meta_index_object_spec.rb
237
+ - spec/models/estimate_response_spec.rb
238
+ - spec/models/project_response_spec.rb
235
239
  - spec/models/project_spec.rb
236
- - spec/models/order_response_spec.rb
240
+ - spec/models/order_spec.rb
241
+ - spec/models/project_list_response_spec.rb
237
242
  - spec/models/allocation_spec.rb
238
- - spec/models/meta_index_object_spec.rb
239
243
  - spec/models/error_response_spec.rb
240
- - spec/models/estimate_response_spec.rb
241
- - spec/models/create_mass_estimate_request_spec.rb
244
+ - spec/models/order_response_spec.rb
245
+ - spec/models/create_order_request_spec.rb
242
246
  - spec/models/order_list_response_spec.rb
243
- - spec/models/order_spec.rb
244
247
  - spec/patch_ruby_spec.rb
245
248
  - spec/spec_helper.rb
246
249
  - spec/support/shared/generated_classes.rb