patch_ruby 1.0.0.pre → 1.2.4

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