patch_ruby 1.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +52 -1
  3. data/Gemfile +1 -0
  4. data/Gemfile.lock +18 -2
  5. data/Makefile +10 -0
  6. data/README.md +48 -9
  7. data/lib/patch_ruby.rb +2 -0
  8. data/lib/patch_ruby/api/estimates_api.rb +195 -0
  9. data/lib/patch_ruby/models/allocation.rb +10 -0
  10. data/lib/patch_ruby/models/create_mass_estimate_request.rb +47 -1
  11. data/lib/patch_ruby/models/create_order_request.rb +54 -4
  12. data/lib/patch_ruby/models/create_preference_request.rb +7 -0
  13. data/lib/patch_ruby/models/error_response.rb +9 -0
  14. data/lib/patch_ruby/models/estimate.rb +24 -1
  15. data/lib/patch_ruby/models/estimate_list_response.rb +9 -0
  16. data/lib/patch_ruby/models/estimate_response.rb +9 -0
  17. data/lib/patch_ruby/models/meta_index_object.rb +11 -0
  18. data/lib/patch_ruby/models/order.rb +58 -1
  19. data/lib/patch_ruby/models/order_list_response.rb +9 -0
  20. data/lib/patch_ruby/models/order_response.rb +9 -0
  21. data/lib/patch_ruby/models/photo.rb +237 -0
  22. data/lib/patch_ruby/models/preference.rb +10 -0
  23. data/lib/patch_ruby/models/preference_list_response.rb +9 -0
  24. data/lib/patch_ruby/models/preference_response.rb +9 -0
  25. data/lib/patch_ruby/models/project.rb +74 -4
  26. data/lib/patch_ruby/models/project_list_response.rb +9 -0
  27. data/lib/patch_ruby/models/project_response.rb +9 -0
  28. data/lib/patch_ruby/models/standard.rb +254 -0
  29. data/lib/patch_ruby/version.rb +1 -1
  30. data/spec/constants.rb +3 -0
  31. data/spec/factories/allocations.rb +7 -0
  32. data/spec/factories/create_mass_estimate_requests.rb +6 -0
  33. data/spec/factories/create_order_requests.rb +8 -0
  34. data/spec/factories/create_preference_requests.rb +5 -0
  35. data/spec/factories/error_responses.rb +7 -0
  36. data/spec/factories/estimate_list_responses.rb +8 -0
  37. data/spec/factories/estimate_responses.rb +7 -0
  38. data/spec/factories/estimates.rb +8 -0
  39. data/spec/factories/meta_index_objects.rb +6 -0
  40. data/spec/factories/order_list_responses.rb +8 -0
  41. data/spec/factories/order_responses.rb +7 -0
  42. data/spec/factories/orders.rb +12 -0
  43. data/spec/factories/preference_list_responses.rb +8 -0
  44. data/spec/factories/preference_responses.rb +7 -0
  45. data/spec/factories/preferences.rb +7 -0
  46. data/spec/factories/project_list_responses.rb +8 -0
  47. data/spec/factories/project_responses.rb +7 -0
  48. data/spec/factories/projects.rb +15 -0
  49. data/spec/integration/estimates_spec.rb +41 -9
  50. data/spec/integration/orders_spec.rb +42 -5
  51. data/spec/integration/preferences_spec.rb +7 -3
  52. data/spec/integration/projects_spec.rb +19 -1
  53. data/spec/models/allocation_spec.rb +8 -1
  54. data/spec/models/create_mass_estimate_request_spec.rb +7 -1
  55. data/spec/models/create_order_request_spec.rb +7 -1
  56. data/spec/models/create_preference_request_spec.rb +8 -1
  57. data/spec/models/error_response_spec.rb +7 -1
  58. data/spec/models/estimate_list_response_spec.rb +7 -1
  59. data/spec/models/estimate_response_spec.rb +7 -1
  60. data/spec/models/estimate_spec.rb +8 -1
  61. data/spec/models/meta_index_object_spec.rb +7 -1
  62. data/spec/models/order_list_response_spec.rb +7 -1
  63. data/spec/models/order_response_spec.rb +7 -1
  64. data/spec/models/order_spec.rb +18 -1
  65. data/spec/models/preference_list_response_spec.rb +7 -1
  66. data/spec/models/preference_response_spec.rb +7 -1
  67. data/spec/models/preference_spec.rb +7 -1
  68. data/spec/models/project_list_response_spec.rb +7 -1
  69. data/spec/models/project_response_spec.rb +7 -1
  70. data/spec/models/project_spec.rb +21 -1
  71. data/spec/spec_helper.rb +11 -0
  72. data/spec/support/shared/generated_classes.rb +13 -0
  73. metadata +60 -17
@@ -42,6 +42,15 @@ module Patch
42
42
  }
43
43
  end
44
44
 
45
+ # Set with nullable attributes.
46
+ def self.openapi_nullable
47
+ nullable_properties = Set.new
48
+
49
+ nullable_properties.add("error")
50
+
51
+ nullable_properties
52
+ end
53
+
45
54
  # Allows models with corresponding API classes to delegate API operations to those API classes
46
55
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
47
56
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -38,6 +38,15 @@ module Patch
38
38
  }
39
39
  end
40
40
 
41
+ # Set with nullable attributes.
42
+ def self.openapi_nullable
43
+ nullable_properties = Set.new
44
+
45
+ nullable_properties.add("error")
46
+
47
+ nullable_properties
48
+ end
49
+
41
50
  # Allows models with corresponding API classes to delegate API operations to those API classes
42
51
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43
52
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -0,0 +1,237 @@
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: developers@usepatch.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module Patch
16
+ class Photo
17
+ attr_accessor :url
18
+
19
+ attr_accessor :id
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'url' => :'url',
25
+ :'id' => :'id'
26
+ }
27
+ end
28
+
29
+ # Attribute type mapping.
30
+ def self.openapi_types
31
+ {
32
+ :'url' => :'String',
33
+ :'id' => :'String'
34
+ }
35
+ end
36
+
37
+ # Set with nullable attributes.
38
+ def self.openapi_nullable
39
+ nullable_properties = Set.new
40
+
41
+ nullable_properties
42
+ end
43
+
44
+ # Allows models with corresponding API classes to delegate API operations to those API classes
45
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
46
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
47
+ def self.method_missing(message, *args, &block)
48
+ if Object.const_defined?('Patch::PhotosApi::OPERATIONS') && Patch::PhotosApi::OPERATIONS.include?(message)
49
+ Patch::PhotosApi.new.send(message, *args)
50
+ else
51
+ super
52
+ end
53
+ end
54
+
55
+ # Initializes the object
56
+ # @param [Hash] attributes Model attributes in the form of hash
57
+ def initialize(attributes = {})
58
+ if (!attributes.is_a?(Hash))
59
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::Photo` initialize method"
60
+ end
61
+
62
+ # check to see if the attribute exists and convert string to symbol for hash key
63
+ attributes = attributes.each_with_object({}) { |(k, v), h|
64
+ if (!self.class.attribute_map.key?(k.to_sym))
65
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::Photo`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
66
+ end
67
+ h[k.to_sym] = v
68
+ }
69
+
70
+ if attributes.key?(:'url')
71
+ self.url = attributes[:'url']
72
+ end
73
+
74
+ if attributes.key?(:'id')
75
+ self.id = attributes[:'id']
76
+ end
77
+ end
78
+
79
+ # Show invalid properties with the reasons. Usually used together with valid?
80
+ # @return Array for valid properties with the reasons
81
+ def list_invalid_properties
82
+ invalid_properties = Array.new
83
+ if @url.nil?
84
+ invalid_properties.push('invalid value for "url", url cannot be nil.')
85
+ end
86
+
87
+ if @id.nil?
88
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
89
+ end
90
+
91
+ invalid_properties
92
+ end
93
+
94
+ # Check to see if the all the properties in the model are valid
95
+ # @return true if the model is valid
96
+ def valid?
97
+ return false if @url.nil?
98
+ return false if @id.nil?
99
+ true
100
+ end
101
+
102
+ # Checks equality by comparing each attribute.
103
+ # @param [Object] Object to be compared
104
+ def ==(o)
105
+ return true if self.equal?(o)
106
+ self.class == o.class &&
107
+ url == o.url &&
108
+ id == o.id
109
+ end
110
+
111
+ # @see the `==` method
112
+ # @param [Object] Object to be compared
113
+ def eql?(o)
114
+ self == o
115
+ end
116
+
117
+ # Calculates hash code according to all attributes.
118
+ # @return [Integer] Hash code
119
+ def hash
120
+ [url, id].hash
121
+ end
122
+
123
+ # Builds the object from hash
124
+ # @param [Hash] attributes Model attributes in the form of hash
125
+ # @return [Object] Returns the model itself
126
+ def self.build_from_hash(attributes)
127
+ new.build_from_hash(attributes)
128
+ end
129
+
130
+ # Builds the object from hash
131
+ # @param [Hash] attributes Model attributes in the form of hash
132
+ # @return [Object] Returns the model itself
133
+ def build_from_hash(attributes)
134
+ return nil unless attributes.is_a?(Hash)
135
+ self.class.openapi_types.each_pair do |key, type|
136
+ if type =~ /\AArray<(.*)>/i
137
+ # check to ensure the input is an array given that the attribute
138
+ # is documented as an array but the input is not
139
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
140
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
141
+ end
142
+ elsif !attributes[self.class.attribute_map[key]].nil?
143
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
144
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
145
+ end
146
+
147
+ self
148
+ end
149
+
150
+ # Deserializes the data based on type
151
+ # @param string type Data type
152
+ # @param string value Value to be deserialized
153
+ # @return [Object] Deserialized data
154
+ def _deserialize(type, value)
155
+ case type.to_sym
156
+ when :DateTime
157
+ DateTime.parse(value)
158
+ when :Date
159
+ Date.parse(value)
160
+ when :String
161
+ value.to_s
162
+ when :Integer
163
+ value.to_i
164
+ when :Float
165
+ value.to_f
166
+ when :Boolean
167
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
168
+ true
169
+ else
170
+ false
171
+ end
172
+ when :Object
173
+ # generic object (usually a Hash), return directly
174
+ value
175
+ when /\AArray<(?<inner_type>.+)>\z/
176
+ inner_type = Regexp.last_match[:inner_type]
177
+ value.map { |v| _deserialize(inner_type, v) }
178
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
179
+ k_type = Regexp.last_match[:k_type]
180
+ v_type = Regexp.last_match[:v_type]
181
+ {}.tap do |hash|
182
+ value.each do |k, v|
183
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
184
+ end
185
+ end
186
+ else # model
187
+ Patch.const_get(type).build_from_hash(value)
188
+ end
189
+ end
190
+
191
+ # Returns the string representation of the object
192
+ # @return [String] String presentation of the object
193
+ def to_s
194
+ to_hash.to_s
195
+ end
196
+
197
+ # to_body is an alias to to_hash (backward compatibility)
198
+ # @return [Hash] Returns the object in the form of hash
199
+ def to_body
200
+ to_hash
201
+ end
202
+
203
+ # Returns the object in the form of hash
204
+ # @return [Hash] Returns the object in the form of hash
205
+ def to_hash
206
+ hash = {}
207
+ self.class.attribute_map.each_pair do |attr, param|
208
+ value = self.send(attr)
209
+ if value.nil?
210
+ is_nullable = self.class.openapi_nullable.include?(attr)
211
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
212
+ end
213
+
214
+ hash[param] = _to_hash(value)
215
+ end
216
+ hash
217
+ end
218
+
219
+ # Outputs non-array value in the form of hash
220
+ # For object, use to_hash. Otherwise, just return the value
221
+ # @param [Object] value Any valid value
222
+ # @return [Hash] Returns the value in the form of hash
223
+ def _to_hash(value)
224
+ if value.is_a?(Array)
225
+ value.compact.map { |v| _to_hash(v) }
226
+ elsif value.is_a?(Hash)
227
+ {}.tap do |hash|
228
+ value.each { |k, v| hash[k] = _to_hash(v) }
229
+ end
230
+ elsif value.respond_to? :to_hash
231
+ value.to_hash
232
+ else
233
+ value
234
+ end
235
+ end
236
+ end
237
+ end
@@ -14,10 +14,13 @@ require 'date'
14
14
 
15
15
  module Patch
16
16
  class Preference
17
+ # A unique uid for the record. UIDs will be prepended by pre_prod or pre_test depending on the mode it was created in.
17
18
  attr_accessor :id
18
19
 
20
+ # Percentage of total purchased offsets that should go to a project. Default is 100%.
19
21
  attr_accessor :allocation_percentage
20
22
 
23
+ # An object returning the Project record this Preference is associated with. See the [Project section](/?id=projects) for the full schema.
21
24
  attr_accessor :project
22
25
 
23
26
  # Attribute mapping from ruby-style variable name to JSON key.
@@ -38,6 +41,13 @@ module Patch
38
41
  }
39
42
  end
40
43
 
44
+ # Set with nullable attributes.
45
+ def self.openapi_nullable
46
+ nullable_properties = Set.new
47
+
48
+ nullable_properties
49
+ end
50
+
41
51
  # Allows models with corresponding API classes to delegate API operations to those API classes
42
52
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43
53
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -42,6 +42,15 @@ module Patch
42
42
  }
43
43
  end
44
44
 
45
+ # Set with nullable attributes.
46
+ def self.openapi_nullable
47
+ nullable_properties = Set.new
48
+
49
+ nullable_properties.add("error")
50
+
51
+ nullable_properties
52
+ end
53
+
45
54
  # Allows models with corresponding API classes to delegate API operations to those API classes
46
55
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
47
56
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -38,6 +38,15 @@ module Patch
38
38
  }
39
39
  end
40
40
 
41
+ # Set with nullable attributes.
42
+ def self.openapi_nullable
43
+ nullable_properties = Set.new
44
+
45
+ nullable_properties.add("error")
46
+
47
+ nullable_properties
48
+ end
49
+
41
50
  # Allows models with corresponding API classes to delegate API operations to those API classes
42
51
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
43
52
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -14,20 +14,39 @@ require 'date'
14
14
 
15
15
  module Patch
16
16
  class Project
17
+ # A unique uid for the record. UIDs will be prepended by pro_prod or pro_test depending on the mode it was created in.
17
18
  attr_accessor :id
18
19
 
20
+ # A boolean indicating if this project is a production or test mode project.
19
21
  attr_accessor :production
20
22
 
23
+ # The name of the project.
21
24
  attr_accessor :name
22
25
 
26
+ # The description of the project.
23
27
  attr_accessor :description
24
28
 
29
+ # The type of carbon removal project, currently available project types are Biomass, Dac, Forestry, Mineralization, Ocean, Soil.
25
30
  attr_accessor :type
26
31
 
32
+ # The country of origin of the project.
27
33
  attr_accessor :country
28
34
 
35
+ # The name of the project developer.
29
36
  attr_accessor :developer
30
37
 
38
+ # An array of URLs for photos of the project.
39
+ attr_accessor :photos
40
+
41
+ # The average price per tonne in USD cents for carbon offsets supplied by this project.
42
+ attr_accessor :average_price_per_tonne_cents_usd
43
+
44
+ # The remaining mass in grams available for purchase for this project.
45
+ attr_accessor :remaining_mass_g
46
+
47
+ # An object returning the Standard associated with this project.
48
+ attr_accessor :standard
49
+
31
50
  class EnumAttributeValidator
32
51
  attr_reader :datatype
33
52
  attr_reader :allowable_values
@@ -59,7 +78,11 @@ module Patch
59
78
  :'description' => :'description',
60
79
  :'type' => :'type',
61
80
  :'country' => :'country',
62
- :'developer' => :'developer'
81
+ :'developer' => :'developer',
82
+ :'photos' => :'photos',
83
+ :'average_price_per_tonne_cents_usd' => :'average_price_per_tonne_cents_usd',
84
+ :'remaining_mass_g' => :'remaining_mass_g',
85
+ :'standard' => :'standard'
63
86
  }
64
87
  end
65
88
 
@@ -72,10 +95,25 @@ module Patch
72
95
  :'description' => :'String',
73
96
  :'type' => :'String',
74
97
  :'country' => :'String',
75
- :'developer' => :'String'
98
+ :'developer' => :'String',
99
+ :'photos' => :'Array<Photo>',
100
+ :'average_price_per_tonne_cents_usd' => :'Integer',
101
+ :'remaining_mass_g' => :'Integer',
102
+ :'standard' => :'Standard'
76
103
  }
77
104
  end
78
105
 
106
+ # Set with nullable attributes.
107
+ def self.openapi_nullable
108
+ nullable_properties = Set.new
109
+
110
+ nullable_properties.add("photos")
111
+
112
+ nullable_properties.add("standard")
113
+
114
+ nullable_properties
115
+ end
116
+
79
117
  # Allows models with corresponding API classes to delegate API operations to those API classes
80
118
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
81
119
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -129,6 +167,24 @@ module Patch
129
167
  if attributes.key?(:'developer')
130
168
  self.developer = attributes[:'developer']
131
169
  end
170
+
171
+ if attributes.key?(:'photos')
172
+ if (value = attributes[:'photos']).is_a?(Array)
173
+ self.photos = value
174
+ end
175
+ end
176
+
177
+ if attributes.key?(:'average_price_per_tonne_cents_usd')
178
+ self.average_price_per_tonne_cents_usd = attributes[:'average_price_per_tonne_cents_usd']
179
+ end
180
+
181
+ if attributes.key?(:'remaining_mass_g')
182
+ self.remaining_mass_g = attributes[:'remaining_mass_g']
183
+ end
184
+
185
+ if attributes.key?(:'standard')
186
+ self.standard = attributes[:'standard']
187
+ end
132
188
  end
133
189
 
134
190
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -159,6 +215,14 @@ module Patch
159
215
  invalid_properties.push('invalid value for "developer", developer cannot be nil.')
160
216
  end
161
217
 
218
+ if @average_price_per_tonne_cents_usd.nil?
219
+ invalid_properties.push('invalid value for "average_price_per_tonne_cents_usd", average_price_per_tonne_cents_usd cannot be nil.')
220
+ end
221
+
222
+ if @remaining_mass_g.nil?
223
+ invalid_properties.push('invalid value for "remaining_mass_g", remaining_mass_g cannot be nil.')
224
+ end
225
+
162
226
  invalid_properties
163
227
  end
164
228
 
@@ -173,6 +237,8 @@ module Patch
173
237
  return false unless type_validator.valid?(@type)
174
238
  return false if @country.nil?
175
239
  return false if @developer.nil?
240
+ return false if @average_price_per_tonne_cents_usd.nil?
241
+ return false if @remaining_mass_g.nil?
176
242
  true
177
243
  end
178
244
 
@@ -197,7 +263,11 @@ module Patch
197
263
  description == o.description &&
198
264
  type == o.type &&
199
265
  country == o.country &&
200
- developer == o.developer
266
+ developer == o.developer &&
267
+ photos == o.photos &&
268
+ average_price_per_tonne_cents_usd == o.average_price_per_tonne_cents_usd &&
269
+ remaining_mass_g == o.remaining_mass_g &&
270
+ standard == o.standard
201
271
  end
202
272
 
203
273
  # @see the `==` method
@@ -209,7 +279,7 @@ module Patch
209
279
  # Calculates hash code according to all attributes.
210
280
  # @return [Integer] Hash code
211
281
  def hash
212
- [id, production, name, description, type, country, developer].hash
282
+ [id, production, name, description, type, country, developer, photos, average_price_per_tonne_cents_usd, remaining_mass_g, standard].hash
213
283
  end
214
284
 
215
285
  # Builds the object from hash