patch_ruby 1.20.0 → 1.23.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
@@ -0,0 +1,229 @@
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 PlaceOrderRequest
18
+ attr_accessor :issued_to
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :'issued_to' => :'issued_to'
24
+ }
25
+ end
26
+
27
+ # Returns all the JSON keys this model knows about
28
+ def self.acceptable_attributes
29
+ attribute_map.values
30
+ end
31
+
32
+ # Attribute type mapping.
33
+ def self.openapi_types
34
+ {
35
+ :'issued_to' => :'V1OrdersIssuedTo'
36
+ }
37
+ end
38
+
39
+ # List of attributes with nullable: true
40
+ def self.openapi_nullable
41
+ Set.new([
42
+ :'issued_to'
43
+ ])
44
+ end
45
+
46
+
47
+ # Allows models with corresponding API classes to delegate API operations to those API classes
48
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
49
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
50
+ def self.method_missing(message, *args, &block)
51
+ if Object.const_defined?('Patch::PlaceOrderRequestsApi::OPERATIONS') && Patch::PlaceOrderRequestsApi::OPERATIONS.include?(message)
52
+ Patch::PlaceOrderRequestsApi.new.send(message, *args)
53
+ else
54
+ super
55
+ end
56
+ end
57
+
58
+ # Initializes the object
59
+ # @param [Hash] attributes Model attributes in the form of hash
60
+ def initialize(attributes = {})
61
+ if (!attributes.is_a?(Hash))
62
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::PlaceOrderRequest` initialize method"
63
+ end
64
+
65
+ # check to see if the attribute exists and convert string to symbol for hash key
66
+ attributes = attributes.each_with_object({}) { |(k, v), h|
67
+ if (!self.class.attribute_map.key?(k.to_sym))
68
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::PlaceOrderRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
69
+ end
70
+ h[k.to_sym] = v
71
+ }
72
+
73
+ if attributes.key?(:'issued_to')
74
+ self.issued_to = attributes[:'issued_to']
75
+ end
76
+ end
77
+
78
+ # Show invalid properties with the reasons. Usually used together with valid?
79
+ # @return Array for valid properties with the reasons
80
+ def list_invalid_properties
81
+ invalid_properties = Array.new
82
+ invalid_properties
83
+ end
84
+
85
+ # Check to see if the all the properties in the model are valid
86
+ # @return true if the model is valid
87
+ def valid?
88
+ true
89
+ end
90
+
91
+ # Checks equality by comparing each attribute.
92
+ # @param [Object] Object to be compared
93
+ def ==(o)
94
+ return true if self.equal?(o)
95
+ self.class == o.class &&
96
+ issued_to == o.issued_to
97
+ end
98
+
99
+ # @see the `==` method
100
+ # @param [Object] Object to be compared
101
+ def eql?(o)
102
+ self == o
103
+ end
104
+
105
+ # Calculates hash code according to all attributes.
106
+ # @return [Integer] Hash code
107
+ def hash
108
+ [issued_to].hash
109
+ end
110
+
111
+ # Builds the object from hash
112
+ # @param [Hash] attributes Model attributes in the form of hash
113
+ # @return [Object] Returns the model itself
114
+ def self.build_from_hash(attributes)
115
+ new.build_from_hash(attributes)
116
+ end
117
+
118
+ # Builds the object from hash
119
+ # @param [Hash] attributes Model attributes in the form of hash
120
+ # @return [Object] Returns the model itself
121
+ def build_from_hash(attributes)
122
+ return nil unless attributes.is_a?(Hash)
123
+ self.class.openapi_types.each_pair do |key, type|
124
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
125
+ self.send("#{key}=", nil)
126
+ elsif type =~ /\AArray<(.*)>/i
127
+ # check to ensure the input is an array given that the attribute
128
+ # is documented as an array but the input is not
129
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
130
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
131
+ end
132
+ elsif !attributes[self.class.attribute_map[key]].nil?
133
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
134
+ end
135
+ end
136
+
137
+ self
138
+ end
139
+
140
+ # Deserializes the data based on type
141
+ # @param string type Data type
142
+ # @param string value Value to be deserialized
143
+ # @return [Object] Deserialized data
144
+ def _deserialize(type, value)
145
+ case type.to_sym
146
+ when :Time
147
+ Time.parse(value)
148
+ when :Date
149
+ Date.parse(value)
150
+ when :String
151
+ value.to_s
152
+ when :Integer
153
+ value.to_i
154
+ when :Float
155
+ value.to_f
156
+ when :Boolean
157
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
158
+ true
159
+ else
160
+ false
161
+ end
162
+ when :Object
163
+ # generic object (usually a Hash), return directly
164
+ value
165
+ when /\AArray<(?<inner_type>.+)>\z/
166
+ inner_type = Regexp.last_match[:inner_type]
167
+ value.map { |v| _deserialize(inner_type, v) }
168
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
169
+ k_type = Regexp.last_match[:k_type]
170
+ v_type = Regexp.last_match[:v_type]
171
+ {}.tap do |hash|
172
+ value.each do |k, v|
173
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
174
+ end
175
+ end
176
+ else # model
177
+ # models (e.g. Pet) or oneOf
178
+ klass = Patch.const_get(type)
179
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
180
+ end
181
+ end
182
+
183
+ # Returns the string representation of the object
184
+ # @return [String] String presentation of the object
185
+ def to_s
186
+ to_hash.to_s
187
+ end
188
+
189
+ # to_body is an alias to to_hash (backward compatibility)
190
+ # @return [Hash] Returns the object in the form of hash
191
+ def to_body
192
+ to_hash
193
+ end
194
+
195
+ # Returns the object in the form of hash
196
+ # @return [Hash] Returns the object in the form of hash
197
+ def to_hash
198
+ hash = {}
199
+ self.class.attribute_map.each_pair do |attr, param|
200
+ value = self.send(attr)
201
+ if value.nil?
202
+ is_nullable = self.class.openapi_nullable.include?(attr)
203
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
204
+ end
205
+
206
+ hash[param] = _to_hash(value)
207
+ end
208
+ hash
209
+ end
210
+
211
+ # Outputs non-array value in the form of hash
212
+ # For object, use to_hash. Otherwise, just return the value
213
+ # @param [Object] value Any valid value
214
+ # @return [Hash] Returns the value in the form of hash
215
+ def _to_hash(value)
216
+ if value.is_a?(Array)
217
+ value.compact.map { |v| _to_hash(v) }
218
+ elsif value.is_a?(Hash)
219
+ {}.tap do |hash|
220
+ value.each { |k, v| hash[k] = _to_hash(v) }
221
+ end
222
+ elsif value.respond_to? :to_hash
223
+ value.to_hash
224
+ else
225
+ value
226
+ end
227
+ end
228
+ end
229
+ end
@@ -18,7 +18,7 @@ module Patch
18
18
  # A unique uid for the record. UIDs will be prepended by pro_prod or pro_test depending on the mode it was created in.
19
19
  attr_accessor :id
20
20
 
21
- # A boolean indicating if this project is a production or test mode project.
21
+ # A boolean indicating if this project is a production or demo mode project.
22
22
  attr_accessor :production
23
23
 
24
24
  # The name of the project.
@@ -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. 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
- class EnumAttributeValidator
78
- attr_reader :datatype
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