patch_ruby 1.2.4 → 1.5.1

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