patch_ruby 1.7.0 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/Gemfile +1 -2
  4. data/Gemfile.lock +20 -25
  5. data/bin/rspec +29 -0
  6. data/lib/patch_ruby/api/estimates_api.rb +97 -24
  7. data/lib/patch_ruby/api/orders_api.rb +30 -16
  8. data/lib/patch_ruby/api/preferences_api.rb +17 -13
  9. data/lib/patch_ruby/api/projects_api.rb +9 -7
  10. data/lib/patch_ruby/api_client.rb +51 -49
  11. data/lib/patch_ruby/api_error.rb +1 -1
  12. data/lib/patch_ruby/configuration.rb +38 -9
  13. data/lib/patch_ruby/models/allocation.rb +21 -11
  14. data/lib/patch_ruby/models/create_bitcoin_estimate_request.rb +25 -19
  15. data/lib/patch_ruby/models/create_ethereum_estimate_request.rb +269 -0
  16. data/lib/patch_ruby/models/create_flight_estimate_request.rb +281 -0
  17. data/lib/patch_ruby/models/create_mass_estimate_request.rb +22 -13
  18. data/lib/patch_ruby/models/create_order_request.rb +21 -11
  19. data/lib/patch_ruby/models/create_preference_request.rb +21 -11
  20. data/lib/patch_ruby/models/create_shipping_estimate_request.rb +371 -0
  21. data/lib/patch_ruby/models/create_success_response.rb +247 -0
  22. data/lib/patch_ruby/models/create_vehicle_estimate_request.rb +326 -0
  23. data/lib/patch_ruby/models/error_response.rb +22 -13
  24. data/lib/patch_ruby/models/estimate.rb +23 -14
  25. data/lib/patch_ruby/models/estimate_list_response.rb +22 -13
  26. data/lib/patch_ruby/models/estimate_response.rb +22 -13
  27. data/lib/patch_ruby/models/meta_index_object.rb +23 -15
  28. data/lib/patch_ruby/models/order.rb +23 -15
  29. data/lib/patch_ruby/models/order_list_response.rb +22 -13
  30. data/lib/patch_ruby/models/order_response.rb +22 -13
  31. data/lib/patch_ruby/models/photo.rb +21 -11
  32. data/lib/patch_ruby/models/preference.rb +21 -11
  33. data/lib/patch_ruby/models/preference_list_response.rb +22 -13
  34. data/lib/patch_ruby/models/preference_response.rb +22 -13
  35. data/lib/patch_ruby/models/project.rb +24 -17
  36. data/lib/patch_ruby/models/project_list_response.rb +22 -13
  37. data/lib/patch_ruby/models/project_response.rb +22 -13
  38. data/lib/patch_ruby/models/sdg.rb +21 -11
  39. data/lib/patch_ruby/models/standard.rb +21 -11
  40. data/lib/patch_ruby/version.rb +2 -2
  41. data/lib/patch_ruby.rb +6 -1
  42. data/patch_ruby.gemspec +7 -3
  43. data/spec/api_client_spec.rb +34 -13
  44. data/spec/configuration_spec.rb +1 -1
  45. data/spec/integration/estimates_spec.rb +34 -7
  46. data/spec/integration/orders_spec.rb +11 -8
  47. data/spec/integration/preferences_spec.rb +1 -7
  48. data/spec/integration/projects_spec.rb +5 -17
  49. data/spec/models/create_mass_estimate_request_spec.rb +1 -1
  50. data/spec/models/error_response_spec.rb +1 -1
  51. data/spec/models/estimate_list_response_spec.rb +1 -1
  52. data/spec/models/estimate_response_spec.rb +1 -1
  53. data/spec/models/estimate_spec.rb +1 -1
  54. data/spec/models/meta_index_object_spec.rb +1 -1
  55. data/spec/models/order_list_response_spec.rb +1 -1
  56. data/spec/models/order_response_spec.rb +1 -1
  57. data/spec/models/order_spec.rb +1 -1
  58. data/spec/models/preference_list_response_spec.rb +1 -1
  59. data/spec/models/preference_response_spec.rb +1 -1
  60. data/spec/models/project_list_response_spec.rb +1 -1
  61. data/spec/models/project_response_spec.rb +1 -1
  62. data/spec/models/project_spec.rb +1 -1
  63. data/spec/spec_helper.rb +70 -54
  64. metadata +41 -41
@@ -6,11 +6,12 @@
6
6
  The version of the OpenAPI document: v1
7
7
  Contact: developers@usepatch.com
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 4.3.1
9
+ OpenAPI Generator version: 5.2.1
10
10
 
11
11
  =end
12
12
 
13
13
  require 'date'
14
+ require 'time'
14
15
 
15
16
  module Patch
16
17
  class CreateBitcoinEstimateRequest
@@ -32,6 +33,11 @@ module Patch
32
33
  }
33
34
  end
34
35
 
36
+ # Returns all the JSON keys this model knows about
37
+ def self.acceptable_attributes
38
+ attribute_map.values
39
+ end
40
+
35
41
  # Attribute type mapping.
36
42
  def self.openapi_types
37
43
  {
@@ -42,21 +48,17 @@ module Patch
42
48
  }
43
49
  end
44
50
 
45
- # Set with nullable attributes.
51
+ # List of attributes with nullable: true
46
52
  def self.openapi_nullable
47
- nullable_properties = Set.new
48
-
49
- nullable_properties.add("timestamp")
50
-
51
- nullable_properties.add("transaction_value_btc_sats")
52
-
53
- nullable_properties.add("project_id")
54
-
55
- nullable_properties.add("create_order")
56
-
57
- nullable_properties
53
+ Set.new([
54
+ :'timestamp',
55
+ :'transaction_value_btc_sats',
56
+ :'project_id',
57
+ :'create_order'
58
+ ])
58
59
  end
59
60
 
61
+
60
62
  # Allows models with corresponding API classes to delegate API operations to those API classes
61
63
  # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
62
64
  # Eg. Order.create_order delegates to OrdersApi.new.create_order
@@ -149,7 +151,9 @@ module Patch
149
151
  def build_from_hash(attributes)
150
152
  return nil unless attributes.is_a?(Hash)
151
153
  self.class.openapi_types.each_pair do |key, type|
152
- if type =~ /\AArray<(.*)>/i
154
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
155
+ self.send("#{key}=", nil)
156
+ elsif type =~ /\AArray<(.*)>/i
153
157
  # check to ensure the input is an array given that the attribute
154
158
  # is documented as an array but the input is not
155
159
  if attributes[self.class.attribute_map[key]].is_a?(Array)
@@ -157,7 +161,7 @@ module Patch
157
161
  end
158
162
  elsif !attributes[self.class.attribute_map[key]].nil?
159
163
  self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
160
- end # or else data not found in attributes(hash), not an issue as the data can be optional
164
+ end
161
165
  end
162
166
 
163
167
  self
@@ -169,8 +173,8 @@ module Patch
169
173
  # @return [Object] Deserialized data
170
174
  def _deserialize(type, value)
171
175
  case type.to_sym
172
- when :DateTime
173
- DateTime.parse(value)
176
+ when :Time
177
+ Time.parse(value)
174
178
  when :Date
175
179
  Date.parse(value)
176
180
  when :String
@@ -200,7 +204,9 @@ module Patch
200
204
  end
201
205
  end
202
206
  else # model
203
- Patch.const_get(type).build_from_hash(value)
207
+ # models (e.g. Pet) or oneOf
208
+ klass = Patch.const_get(type)
209
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
204
210
  end
205
211
  end
206
212
 
@@ -226,7 +232,7 @@ module Patch
226
232
  is_nullable = self.class.openapi_nullable.include?(attr)
227
233
  next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
228
234
  end
229
-
235
+
230
236
  hash[param] = _to_hash(value)
231
237
  end
232
238
  hash
@@ -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: 5.2.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Patch
17
+ class CreateEthereumEstimateRequest
18
+ attr_accessor :timestamp
19
+
20
+ attr_accessor :gas_used
21
+
22
+ attr_accessor :transaction_value_eth_gwei
23
+
24
+ attr_accessor :project_id
25
+
26
+ attr_accessor :create_order
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :'timestamp' => :'timestamp',
32
+ :'gas_used' => :'gas_used',
33
+ :'transaction_value_eth_gwei' => :'transaction_value_eth_gwei',
34
+ :'project_id' => :'project_id',
35
+ :'create_order' => :'create_order'
36
+ }
37
+ end
38
+
39
+ # Returns all the JSON keys this model knows about
40
+ def self.acceptable_attributes
41
+ attribute_map.values
42
+ end
43
+
44
+ # Attribute type mapping.
45
+ def self.openapi_types
46
+ {
47
+ :'timestamp' => :'String',
48
+ :'gas_used' => :'Integer',
49
+ :'transaction_value_eth_gwei' => :'Integer',
50
+ :'project_id' => :'String',
51
+ :'create_order' => :'Boolean'
52
+ }
53
+ end
54
+
55
+ # List of attributes with nullable: true
56
+ def self.openapi_nullable
57
+ Set.new([
58
+ :'timestamp',
59
+ :'gas_used',
60
+ :'transaction_value_eth_gwei',
61
+ :'project_id',
62
+ :'create_order'
63
+ ])
64
+ end
65
+
66
+
67
+ # Allows models with corresponding API classes to delegate API operations to those API classes
68
+ # Exposes Model.operation_id which delegates to ModelsApi.new.operation_id
69
+ # Eg. Order.create_order delegates to OrdersApi.new.create_order
70
+ def self.method_missing(message, *args, &block)
71
+ if Object.const_defined?('Patch::CreateEthereumEstimateRequestsApi::OPERATIONS') && Patch::CreateEthereumEstimateRequestsApi::OPERATIONS.include?(message)
72
+ Patch::CreateEthereumEstimateRequestsApi.new.send(message, *args)
73
+ else
74
+ super
75
+ end
76
+ end
77
+
78
+ # Initializes the object
79
+ # @param [Hash] attributes Model attributes in the form of hash
80
+ def initialize(attributes = {})
81
+ if (!attributes.is_a?(Hash))
82
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Patch::CreateEthereumEstimateRequest` initialize method"
83
+ end
84
+
85
+ # check to see if the attribute exists and convert string to symbol for hash key
86
+ attributes = attributes.each_with_object({}) { |(k, v), h|
87
+ if (!self.class.attribute_map.key?(k.to_sym))
88
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Patch::CreateEthereumEstimateRequest`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
89
+ end
90
+ h[k.to_sym] = v
91
+ }
92
+
93
+ if attributes.key?(:'timestamp')
94
+ self.timestamp = attributes[:'timestamp']
95
+ end
96
+
97
+ if attributes.key?(:'gas_used')
98
+ self.gas_used = attributes[:'gas_used']
99
+ end
100
+
101
+ if attributes.key?(:'transaction_value_eth_gwei')
102
+ self.transaction_value_eth_gwei = attributes[:'transaction_value_eth_gwei']
103
+ end
104
+
105
+ if attributes.key?(:'project_id')
106
+ self.project_id = attributes[:'project_id']
107
+ end
108
+
109
+ if attributes.key?(:'create_order')
110
+ self.create_order = attributes[:'create_order']
111
+ end
112
+ end
113
+
114
+ # Show invalid properties with the reasons. Usually used together with valid?
115
+ # @return Array for valid properties with the reasons
116
+ def list_invalid_properties
117
+ invalid_properties = Array.new
118
+ invalid_properties
119
+ end
120
+
121
+ # Check to see if the all the properties in the model are valid
122
+ # @return true if the model is valid
123
+ def valid?
124
+ true
125
+ end
126
+
127
+ # Checks equality by comparing each attribute.
128
+ # @param [Object] Object to be compared
129
+ def ==(o)
130
+ return true if self.equal?(o)
131
+ self.class == o.class &&
132
+ timestamp == o.timestamp &&
133
+ gas_used == o.gas_used &&
134
+ transaction_value_eth_gwei == o.transaction_value_eth_gwei &&
135
+ project_id == o.project_id &&
136
+ create_order == o.create_order
137
+ end
138
+
139
+ # @see the `==` method
140
+ # @param [Object] Object to be compared
141
+ def eql?(o)
142
+ self == o
143
+ end
144
+
145
+ # Calculates hash code according to all attributes.
146
+ # @return [Integer] Hash code
147
+ def hash
148
+ [timestamp, gas_used, transaction_value_eth_gwei, project_id, create_order].hash
149
+ end
150
+
151
+ # Builds the object from hash
152
+ # @param [Hash] attributes Model attributes in the form of hash
153
+ # @return [Object] Returns the model itself
154
+ def self.build_from_hash(attributes)
155
+ new.build_from_hash(attributes)
156
+ end
157
+
158
+ # Builds the object from hash
159
+ # @param [Hash] attributes Model attributes in the form of hash
160
+ # @return [Object] Returns the model itself
161
+ def build_from_hash(attributes)
162
+ return nil unless attributes.is_a?(Hash)
163
+ self.class.openapi_types.each_pair do |key, type|
164
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
165
+ self.send("#{key}=", nil)
166
+ elsif type =~ /\AArray<(.*)>/i
167
+ # check to ensure the input is an array given that the attribute
168
+ # is documented as an array but the input is not
169
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
170
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
171
+ end
172
+ elsif !attributes[self.class.attribute_map[key]].nil?
173
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
174
+ end
175
+ end
176
+
177
+ self
178
+ end
179
+
180
+ # Deserializes the data based on type
181
+ # @param string type Data type
182
+ # @param string value Value to be deserialized
183
+ # @return [Object] Deserialized data
184
+ def _deserialize(type, value)
185
+ case type.to_sym
186
+ when :Time
187
+ Time.parse(value)
188
+ when :Date
189
+ Date.parse(value)
190
+ when :String
191
+ value.to_s
192
+ when :Integer
193
+ value.to_i
194
+ when :Float
195
+ value.to_f
196
+ when :Boolean
197
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
198
+ true
199
+ else
200
+ false
201
+ end
202
+ when :Object
203
+ # generic object (usually a Hash), return directly
204
+ value
205
+ when /\AArray<(?<inner_type>.+)>\z/
206
+ inner_type = Regexp.last_match[:inner_type]
207
+ value.map { |v| _deserialize(inner_type, v) }
208
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
209
+ k_type = Regexp.last_match[:k_type]
210
+ v_type = Regexp.last_match[:v_type]
211
+ {}.tap do |hash|
212
+ value.each do |k, v|
213
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
214
+ end
215
+ end
216
+ else # model
217
+ # models (e.g. Pet) or oneOf
218
+ klass = Patch.const_get(type)
219
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.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
@@ -0,0 +1,281 @@
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: 5.2.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Patch
17
+ class CreateFlightEstimateRequest
18
+ attr_accessor :distance_m
19
+
20
+ attr_accessor :project_id
21
+
22
+ attr_accessor :create_order
23
+
24
+ # Attribute mapping from ruby-style variable name to JSON key.
25
+ def self.attribute_map
26
+ {
27
+ :'distance_m' => :'distance_m',
28
+ :'project_id' => :'project_id',
29
+ :'create_order' => :'create_order'
30
+ }
31
+ end
32
+
33
+ # Returns all the JSON keys this model knows about
34
+ def self.acceptable_attributes
35
+ attribute_map.values
36
+ end
37
+
38
+ # Attribute type mapping.
39
+ def self.openapi_types
40
+ {
41
+ :'distance_m' => :'Integer',
42
+ :'project_id' => :'String',
43
+ :'create_order' => :'Boolean'
44
+ }
45
+ end
46
+
47
+ # List of attributes with nullable: true
48
+ def self.openapi_nullable
49
+ Set.new([
50
+ :'project_id',
51
+ :'create_order'
52
+ ])
53
+ end
54
+
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::CreateFlightEstimateRequestsApi::OPERATIONS') && Patch::CreateFlightEstimateRequestsApi::OPERATIONS.include?(message)
61
+ Patch::CreateFlightEstimateRequestsApi.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::CreateFlightEstimateRequest` 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::CreateFlightEstimateRequest`. 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?(:'distance_m')
83
+ self.distance_m = attributes[:'distance_m']
84
+ end
85
+
86
+ if attributes.key?(:'project_id')
87
+ self.project_id = attributes[:'project_id']
88
+ end
89
+
90
+ if attributes.key?(:'create_order')
91
+ self.create_order = attributes[:'create_order']
92
+ end
93
+ end
94
+
95
+ # Show invalid properties with the reasons. Usually used together with valid?
96
+ # @return Array for valid properties with the reasons
97
+ def list_invalid_properties
98
+ invalid_properties = Array.new
99
+ if @distance_m.nil?
100
+ invalid_properties.push('invalid value for "distance_m", distance_m cannot be nil.')
101
+ end
102
+
103
+ if @distance_m > 400000000
104
+ invalid_properties.push('invalid value for "distance_m", must be smaller than or equal to 400000000.')
105
+ end
106
+
107
+ if @distance_m < 0
108
+ invalid_properties.push('invalid value for "distance_m", must be greater than or equal to 0.')
109
+ end
110
+
111
+ invalid_properties
112
+ end
113
+
114
+ # Check to see if the all the properties in the model are valid
115
+ # @return true if the model is valid
116
+ def valid?
117
+ return false if @distance_m.nil?
118
+ return false if @distance_m > 400000000
119
+ return false if @distance_m < 0
120
+ true
121
+ end
122
+
123
+ # Custom attribute writer method with validation
124
+ # @param [Object] distance_m Value to be assigned
125
+ def distance_m=(distance_m)
126
+ if distance_m.nil?
127
+ fail ArgumentError, 'distance_m cannot be nil'
128
+ end
129
+
130
+ if distance_m > 400000000
131
+ fail ArgumentError, 'invalid value for "distance_m", must be smaller than or equal to 400000000.'
132
+ end
133
+
134
+ if distance_m < 0
135
+ fail ArgumentError, 'invalid value for "distance_m", must be greater than or equal to 0.'
136
+ end
137
+
138
+ @distance_m = distance_m
139
+ end
140
+
141
+ # Checks equality by comparing each attribute.
142
+ # @param [Object] Object to be compared
143
+ def ==(o)
144
+ return true if self.equal?(o)
145
+ self.class == o.class &&
146
+ distance_m == o.distance_m &&
147
+ project_id == o.project_id &&
148
+ create_order == o.create_order
149
+ end
150
+
151
+ # @see the `==` method
152
+ # @param [Object] Object to be compared
153
+ def eql?(o)
154
+ self == o
155
+ end
156
+
157
+ # Calculates hash code according to all attributes.
158
+ # @return [Integer] Hash code
159
+ def hash
160
+ [distance_m, project_id, create_order].hash
161
+ end
162
+
163
+ # Builds the object from hash
164
+ # @param [Hash] attributes Model attributes in the form of hash
165
+ # @return [Object] Returns the model itself
166
+ def self.build_from_hash(attributes)
167
+ new.build_from_hash(attributes)
168
+ end
169
+
170
+ # Builds the object from hash
171
+ # @param [Hash] attributes Model attributes in the form of hash
172
+ # @return [Object] Returns the model itself
173
+ def build_from_hash(attributes)
174
+ return nil unless attributes.is_a?(Hash)
175
+ self.class.openapi_types.each_pair do |key, type|
176
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
177
+ self.send("#{key}=", nil)
178
+ elsif type =~ /\AArray<(.*)>/i
179
+ # check to ensure the input is an array given that the attribute
180
+ # is documented as an array but the input is not
181
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
182
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
183
+ end
184
+ elsif !attributes[self.class.attribute_map[key]].nil?
185
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
186
+ end
187
+ end
188
+
189
+ self
190
+ end
191
+
192
+ # Deserializes the data based on type
193
+ # @param string type Data type
194
+ # @param string value Value to be deserialized
195
+ # @return [Object] Deserialized data
196
+ def _deserialize(type, value)
197
+ case type.to_sym
198
+ when :Time
199
+ Time.parse(value)
200
+ when :Date
201
+ Date.parse(value)
202
+ when :String
203
+ value.to_s
204
+ when :Integer
205
+ value.to_i
206
+ when :Float
207
+ value.to_f
208
+ when :Boolean
209
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
210
+ true
211
+ else
212
+ false
213
+ end
214
+ when :Object
215
+ # generic object (usually a Hash), return directly
216
+ value
217
+ when /\AArray<(?<inner_type>.+)>\z/
218
+ inner_type = Regexp.last_match[:inner_type]
219
+ value.map { |v| _deserialize(inner_type, v) }
220
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
221
+ k_type = Regexp.last_match[:k_type]
222
+ v_type = Regexp.last_match[:v_type]
223
+ {}.tap do |hash|
224
+ value.each do |k, v|
225
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
226
+ end
227
+ end
228
+ else # model
229
+ # models (e.g. Pet) or oneOf
230
+ klass = Patch.const_get(type)
231
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
232
+ end
233
+ end
234
+
235
+ # Returns the string representation of the object
236
+ # @return [String] String presentation of the object
237
+ def to_s
238
+ to_hash.to_s
239
+ end
240
+
241
+ # to_body is an alias to to_hash (backward compatibility)
242
+ # @return [Hash] Returns the object in the form of hash
243
+ def to_body
244
+ to_hash
245
+ end
246
+
247
+ # Returns the object in the form of hash
248
+ # @return [Hash] Returns the object in the form of hash
249
+ def to_hash
250
+ hash = {}
251
+ self.class.attribute_map.each_pair do |attr, param|
252
+ value = self.send(attr)
253
+ if value.nil?
254
+ is_nullable = self.class.openapi_nullable.include?(attr)
255
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
256
+ end
257
+
258
+ hash[param] = _to_hash(value)
259
+ end
260
+ hash
261
+ end
262
+
263
+ # Outputs non-array value in the form of hash
264
+ # For object, use to_hash. Otherwise, just return the value
265
+ # @param [Object] value Any valid value
266
+ # @return [Hash] Returns the value in the form of hash
267
+ def _to_hash(value)
268
+ if value.is_a?(Array)
269
+ value.compact.map { |v| _to_hash(v) }
270
+ elsif value.is_a?(Hash)
271
+ {}.tap do |hash|
272
+ value.each { |k, v| hash[k] = _to_hash(v) }
273
+ end
274
+ elsif value.respond_to? :to_hash
275
+ value.to_hash
276
+ else
277
+ value
278
+ end
279
+ end
280
+ end
281
+ end