dear-inventory-ruby 0.1.16 → 0.2.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 +34 -10
  3. data/README.md +32 -7
  4. data/dear-inventory-ruby.gemspec +1 -1
  5. data/docs/Address.md +10 -12
  6. data/docs/Customer.md +1 -1
  7. data/docs/ExternalHeader.md +19 -0
  8. data/docs/InventoryApi.md +1021 -161
  9. data/docs/Me.md +1 -1
  10. data/docs/SaleAdditionalCharge.md +31 -0
  11. data/docs/SaleInvoice.md +1 -1
  12. data/docs/SaleInvoiceAdditionalCharge.md +3 -3
  13. data/docs/SaleInvoiceDelete.md +19 -0
  14. data/docs/SaleInvoiceLine.md +2 -2
  15. data/docs/SaleInvoicePost.md +41 -0
  16. data/docs/SaleOrder.md +35 -0
  17. data/docs/SaleOrderLine.md +41 -0
  18. data/docs/SalePayment.md +43 -0
  19. data/docs/SaleQuote.md +33 -0
  20. data/docs/SaleQuoteLine.md +37 -0
  21. data/docs/ShippingAddress.md +37 -0
  22. data/docs/SupplierCustomerAddress.md +33 -0
  23. data/docs/Webhook.md +35 -0
  24. data/docs/Webhooks.md +17 -0
  25. data/lib/dear-inventory-ruby/api/inventory_api.rb +988 -119
  26. data/lib/dear-inventory-ruby/models/account.rb +0 -34
  27. data/lib/dear-inventory-ruby/models/address.rb +28 -115
  28. data/lib/dear-inventory-ruby/models/customer.rb +1 -35
  29. data/lib/dear-inventory-ruby/models/external_header.rb +217 -0
  30. data/lib/dear-inventory-ruby/models/me.rb +2 -1
  31. data/lib/dear-inventory-ruby/models/payment_term.rb +0 -34
  32. data/lib/dear-inventory-ruby/models/sale_additional_charge.rb +302 -0
  33. data/lib/dear-inventory-ruby/models/sale_invoice.rb +1 -1
  34. data/lib/dear-inventory-ruby/models/sale_invoice_additional_charge.rb +3 -3
  35. data/lib/dear-inventory-ruby/models/sale_invoice_delete.rb +224 -0
  36. data/lib/dear-inventory-ruby/models/sale_invoice_line.rb +0 -10
  37. data/lib/dear-inventory-ruby/models/sale_invoice_post.rb +361 -0
  38. data/lib/dear-inventory-ruby/models/sale_order.rb +336 -0
  39. data/lib/dear-inventory-ruby/models/sale_order_line.rb +342 -0
  40. data/lib/dear-inventory-ruby/models/sale_payment.rb +337 -0
  41. data/lib/dear-inventory-ruby/models/sale_quote.rb +326 -0
  42. data/lib/dear-inventory-ruby/models/sale_quote_line.rb +322 -0
  43. data/lib/dear-inventory-ruby/models/shipping_address.rb +317 -0
  44. data/lib/dear-inventory-ruby/models/supplier_customer_address.rb +374 -0
  45. data/lib/dear-inventory-ruby/models/webhook.rb +319 -0
  46. data/lib/dear-inventory-ruby/models/webhooks.rb +209 -0
  47. data/lib/dear-inventory-ruby/version.rb +1 -1
  48. data/lib/dear-inventory-ruby.rb +13 -2
  49. data/spec/api/inventory_api_spec.rb +166 -0
  50. data/spec/models/account_spec.rb +0 -4
  51. data/spec/models/address_spec.rb +7 -13
  52. data/spec/models/customer_spec.rb +0 -4
  53. data/spec/models/external_header_spec.rb +47 -0
  54. data/spec/models/payment_term_spec.rb +0 -4
  55. data/spec/models/sale_additional_charge_spec.rb +83 -0
  56. data/spec/models/sale_invoice_delete_spec.rb +47 -0
  57. data/spec/models/sale_invoice_post_spec.rb +113 -0
  58. data/spec/models/sale_order_line_spec.rb +113 -0
  59. data/spec/models/sale_order_spec.rb +95 -0
  60. data/spec/models/sale_payment_spec.rb +119 -0
  61. data/spec/models/sale_quote_line_spec.rb +101 -0
  62. data/spec/models/sale_quote_spec.rb +89 -0
  63. data/spec/models/shipping_address_spec.rb +101 -0
  64. data/spec/models/supplier_customer_address_spec.rb +89 -0
  65. data/spec/models/webhook_spec.rb +95 -0
  66. data/spec/models/{currency_code_spec.rb → webhooks_spec.rb} +12 -6
  67. metadata +63 -14
  68. data/docs/CurrencyCode.md +0 -16
  69. data/docs/DimensionsUnit.md +0 -16
  70. data/lib/dear-inventory-ruby/models/currency_code.rb +0 -196
  71. data/lib/dear-inventory-ruby/models/dimensions_unit.rb +0 -42
  72. data/spec/.DS_Store +0 -0
  73. data/spec/models/dimensions_unit_spec.rb +0 -35
@@ -0,0 +1,326 @@
1
+ =begin
2
+ #DEAR Inventory API
3
+
4
+ #This specifing endpoints for DEAR Inventory API
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+ Contact: nnhansg@gmail.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 DearInventoryRuby
16
+ class SaleQuote
17
+ # Unique DEAR Sale ID
18
+ attr_accessor :sale_id
19
+
20
+ # If `true` then `additional charges` lines displayed in `Lines` array
21
+ attr_accessor :combine_additional_charges
22
+
23
+ # Additional information for Quote.
24
+ attr_accessor :memo
25
+
26
+ # Quote Status. Possible Values are values. For POST only `DRAFT` and `AUTHORISED` values accepted
27
+ attr_accessor :status
28
+
29
+ attr_accessor :lines
30
+
31
+ attr_accessor :additional_charges
32
+
33
+ # Decimal with up to 4 decimal places. Sum of quote lines and additional charges without taxes. Not required for POST.
34
+ attr_accessor :total_before_tax
35
+
36
+ # Decimal with up to 4 decimal places. Sum of quote lines and additional charges taxes. Not required for POST.
37
+ attr_accessor :tax
38
+
39
+ # Decimal with up to 4 decimal places. Sum of quote lines and additional charges with taxes. Not required for POST.
40
+ attr_accessor :total
41
+
42
+ # Attribute mapping from ruby-style variable name to JSON key.
43
+ def self.attribute_map
44
+ {
45
+ :'sale_id' => :'SaleID',
46
+ :'combine_additional_charges' => :'CombineAdditionalCharges',
47
+ :'memo' => :'Memo',
48
+ :'status' => :'Status',
49
+ :'lines' => :'Lines',
50
+ :'additional_charges' => :'AdditionalCharges',
51
+ :'total_before_tax' => :'TotalBeforeTax',
52
+ :'tax' => :'Tax',
53
+ :'total' => :'Total'
54
+ }
55
+ end
56
+
57
+ # Attribute type mapping.
58
+ def self.openapi_types
59
+ {
60
+ :'sale_id' => :'String',
61
+ :'combine_additional_charges' => :'Boolean',
62
+ :'memo' => :'String',
63
+ :'status' => :'String',
64
+ :'lines' => :'Array<SaleQuoteLine>',
65
+ :'additional_charges' => :'Array<SaleAdditionalCharge>',
66
+ :'total_before_tax' => :'Float',
67
+ :'tax' => :'Float',
68
+ :'total' => :'Float'
69
+ }
70
+ end
71
+
72
+ # List of attributes with nullable: true
73
+ def self.openapi_nullable
74
+ Set.new([
75
+ ])
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 `DearInventoryRuby::SaleQuote` 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 `DearInventoryRuby::SaleQuote`. 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?(:'sale_id')
94
+ self.sale_id = attributes[:'sale_id']
95
+ end
96
+
97
+ if attributes.key?(:'combine_additional_charges')
98
+ self.combine_additional_charges = attributes[:'combine_additional_charges']
99
+ else
100
+ self.combine_additional_charges = false
101
+ end
102
+
103
+ if attributes.key?(:'memo')
104
+ self.memo = attributes[:'memo']
105
+ end
106
+
107
+ if attributes.key?(:'status')
108
+ self.status = attributes[:'status']
109
+ end
110
+
111
+ if attributes.key?(:'lines')
112
+ if (value = attributes[:'lines']).is_a?(Array)
113
+ self.lines = value
114
+ end
115
+ end
116
+
117
+ if attributes.key?(:'additional_charges')
118
+ if (value = attributes[:'additional_charges']).is_a?(Array)
119
+ self.additional_charges = value
120
+ end
121
+ end
122
+
123
+ if attributes.key?(:'total_before_tax')
124
+ self.total_before_tax = attributes[:'total_before_tax']
125
+ end
126
+
127
+ if attributes.key?(:'tax')
128
+ self.tax = attributes[:'tax']
129
+ end
130
+
131
+ if attributes.key?(:'total')
132
+ self.total = attributes[:'total']
133
+ end
134
+ end
135
+
136
+ # Show invalid properties with the reasons. Usually used together with valid?
137
+ # @return Array for valid properties with the reasons
138
+ def list_invalid_properties
139
+ invalid_properties = Array.new
140
+ if @sale_id.nil?
141
+ invalid_properties.push('invalid value for "sale_id", sale_id cannot be nil.')
142
+ end
143
+
144
+ if @combine_additional_charges.nil?
145
+ invalid_properties.push('invalid value for "combine_additional_charges", combine_additional_charges cannot be nil.')
146
+ end
147
+
148
+ if @memo.nil?
149
+ invalid_properties.push('invalid value for "memo", memo cannot be nil.')
150
+ end
151
+
152
+ if @status.nil?
153
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
154
+ end
155
+
156
+ if @total_before_tax.nil?
157
+ invalid_properties.push('invalid value for "total_before_tax", total_before_tax cannot be nil.')
158
+ end
159
+
160
+ if @tax.nil?
161
+ invalid_properties.push('invalid value for "tax", tax cannot be nil.')
162
+ end
163
+
164
+ if @total.nil?
165
+ invalid_properties.push('invalid value for "total", total cannot be nil.')
166
+ end
167
+
168
+ invalid_properties
169
+ end
170
+
171
+ # Check to see if the all the properties in the model are valid
172
+ # @return true if the model is valid
173
+ def valid?
174
+ return false if @sale_id.nil?
175
+ return false if @combine_additional_charges.nil?
176
+ return false if @memo.nil?
177
+ return false if @status.nil?
178
+ return false if @total_before_tax.nil?
179
+ return false if @tax.nil?
180
+ return false if @total.nil?
181
+ true
182
+ end
183
+
184
+ # Checks equality by comparing each attribute.
185
+ # @param [Object] Object to be compared
186
+ def ==(o)
187
+ return true if self.equal?(o)
188
+ self.class == o.class &&
189
+ sale_id == o.sale_id &&
190
+ combine_additional_charges == o.combine_additional_charges &&
191
+ memo == o.memo &&
192
+ status == o.status &&
193
+ lines == o.lines &&
194
+ additional_charges == o.additional_charges &&
195
+ total_before_tax == o.total_before_tax &&
196
+ tax == o.tax &&
197
+ total == o.total
198
+ end
199
+
200
+ # @see the `==` method
201
+ # @param [Object] Object to be compared
202
+ def eql?(o)
203
+ self == o
204
+ end
205
+
206
+ # Calculates hash code according to all attributes.
207
+ # @return [Integer] Hash code
208
+ def hash
209
+ [sale_id, combine_additional_charges, memo, status, lines, additional_charges, total_before_tax, tax, total].hash
210
+ end
211
+
212
+ # Builds the object from hash
213
+ # @param [Hash] attributes Model attributes in the form of hash
214
+ # @return [Object] Returns the model itself
215
+ def self.build_from_hash(attributes)
216
+ new.build_from_hash(attributes)
217
+ end
218
+
219
+ # Builds the object from hash
220
+ # @param [Hash] attributes Model attributes in the form of hash
221
+ # @return [Object] Returns the model itself
222
+ def build_from_hash(attributes)
223
+ return nil unless attributes.is_a?(Hash)
224
+ self.class.openapi_types.each_pair do |key, type|
225
+ if type =~ /\AArray<(.*)>/i
226
+ # check to ensure the input is an array given that the attribute
227
+ # is documented as an array but the input is not
228
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
229
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
230
+ end
231
+ elsif !attributes[self.class.attribute_map[key]].nil?
232
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
233
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
234
+ end
235
+
236
+ self
237
+ end
238
+
239
+ # Deserializes the data based on type
240
+ # @param string type Data type
241
+ # @param string value Value to be deserialized
242
+ # @return [Object] Deserialized data
243
+ def _deserialize(type, value)
244
+ case type.to_sym
245
+ when :DateTime
246
+ DateTime.parse(value)
247
+ when :Date
248
+ Date.parse(value)
249
+ when :String
250
+ value.to_s
251
+ when :Integer
252
+ value.to_i
253
+ when :Float
254
+ value.to_f
255
+ when :Boolean
256
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
257
+ true
258
+ else
259
+ false
260
+ end
261
+ when :Object
262
+ # generic object (usually a Hash), return directly
263
+ value
264
+ when /\AArray<(?<inner_type>.+)>\z/
265
+ inner_type = Regexp.last_match[:inner_type]
266
+ value.map { |v| _deserialize(inner_type, v) }
267
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
268
+ k_type = Regexp.last_match[:k_type]
269
+ v_type = Regexp.last_match[:v_type]
270
+ {}.tap do |hash|
271
+ value.each do |k, v|
272
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
273
+ end
274
+ end
275
+ else # model
276
+ DearInventoryRuby.const_get(type).build_from_hash(value)
277
+ end
278
+ end
279
+
280
+ # Returns the string representation of the object
281
+ # @return [String] String presentation of the object
282
+ def to_s
283
+ to_hash.to_s
284
+ end
285
+
286
+ # to_body is an alias to to_hash (backward compatibility)
287
+ # @return [Hash] Returns the object in the form of hash
288
+ def to_body
289
+ to_hash
290
+ end
291
+
292
+ # Returns the object in the form of hash
293
+ # @return [Hash] Returns the object in the form of hash
294
+ def to_hash
295
+ hash = {}
296
+ self.class.attribute_map.each_pair do |attr, param|
297
+ value = self.send(attr)
298
+ if value.nil?
299
+ is_nullable = self.class.openapi_nullable.include?(attr)
300
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
301
+ end
302
+
303
+ hash[param] = _to_hash(value)
304
+ end
305
+ hash
306
+ end
307
+
308
+ # Outputs non-array value in the form of hash
309
+ # For object, use to_hash. Otherwise, just return the value
310
+ # @param [Object] value Any valid value
311
+ # @return [Hash] Returns the value in the form of hash
312
+ def _to_hash(value)
313
+ if value.is_a?(Array)
314
+ value.compact.map { |v| _to_hash(v) }
315
+ elsif value.is_a?(Hash)
316
+ {}.tap do |hash|
317
+ value.each { |k, v| hash[k] = _to_hash(v) }
318
+ end
319
+ elsif value.respond_to? :to_hash
320
+ value.to_hash
321
+ else
322
+ value
323
+ end
324
+ end
325
+ end
326
+ end
@@ -0,0 +1,322 @@
1
+ =begin
2
+ #DEAR Inventory API
3
+
4
+ #This specifing endpoints for DEAR Inventory API
5
+
6
+ The version of the OpenAPI document: 2.0.0
7
+ Contact: nnhansg@gmail.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 DearInventoryRuby
16
+ class SaleQuoteLine
17
+ # Product identifier referenced by this Line. Required If CombineAdditionalCharges param exist for this endpoint and it have values = false
18
+ attr_accessor :product_id
19
+
20
+ # Product SKU referenced by this Line. Required If CombineAdditionalCharges param exist for this endpoint and it have values = false
21
+ attr_accessor :sku
22
+
23
+ # Product Name referenced by this Line
24
+ attr_accessor :name
25
+
26
+ # Product or service quantity. Minimal value is 1.
27
+ attr_accessor :quantity
28
+
29
+ # Price per unit in Customer currency
30
+ attr_accessor :price
31
+
32
+ # Discount. Value between 0 and 100. For free items discount is 100. Default value is 0
33
+ attr_accessor :discount
34
+
35
+ # Tax
36
+ attr_accessor :tax
37
+
38
+ # Average product cost
39
+ attr_accessor :average_cost
40
+
41
+ # Line Tax Rule name.
42
+ attr_accessor :tax_rule
43
+
44
+ # Comment for this line
45
+ attr_accessor :comment
46
+
47
+ # Line Total. For validation
48
+ attr_accessor :total
49
+
50
+ # Attribute mapping from ruby-style variable name to JSON key.
51
+ def self.attribute_map
52
+ {
53
+ :'product_id' => :'ProductID',
54
+ :'sku' => :'SKU',
55
+ :'name' => :'Name',
56
+ :'quantity' => :'Quantity',
57
+ :'price' => :'Price',
58
+ :'discount' => :'Discount',
59
+ :'tax' => :'Tax',
60
+ :'average_cost' => :'AverageCost',
61
+ :'tax_rule' => :'TaxRule',
62
+ :'comment' => :'Comment',
63
+ :'total' => :'Total'
64
+ }
65
+ end
66
+
67
+ # Attribute type mapping.
68
+ def self.openapi_types
69
+ {
70
+ :'product_id' => :'String',
71
+ :'sku' => :'String',
72
+ :'name' => :'String',
73
+ :'quantity' => :'Float',
74
+ :'price' => :'Float',
75
+ :'discount' => :'Float',
76
+ :'tax' => :'Float',
77
+ :'average_cost' => :'Float',
78
+ :'tax_rule' => :'String',
79
+ :'comment' => :'String',
80
+ :'total' => :'Float'
81
+ }
82
+ end
83
+
84
+ # List of attributes with nullable: true
85
+ def self.openapi_nullable
86
+ Set.new([
87
+ ])
88
+ end
89
+
90
+ # Initializes the object
91
+ # @param [Hash] attributes Model attributes in the form of hash
92
+ def initialize(attributes = {})
93
+ if (!attributes.is_a?(Hash))
94
+ fail ArgumentError, "The input argument (attributes) must be a hash in `DearInventoryRuby::SaleQuoteLine` initialize method"
95
+ end
96
+
97
+ # check to see if the attribute exists and convert string to symbol for hash key
98
+ attributes = attributes.each_with_object({}) { |(k, v), h|
99
+ if (!self.class.attribute_map.key?(k.to_sym))
100
+ fail ArgumentError, "`#{k}` is not a valid attribute in `DearInventoryRuby::SaleQuoteLine`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
101
+ end
102
+ h[k.to_sym] = v
103
+ }
104
+
105
+ if attributes.key?(:'product_id')
106
+ self.product_id = attributes[:'product_id']
107
+ end
108
+
109
+ if attributes.key?(:'sku')
110
+ self.sku = attributes[:'sku']
111
+ end
112
+
113
+ if attributes.key?(:'name')
114
+ self.name = attributes[:'name']
115
+ end
116
+
117
+ if attributes.key?(:'quantity')
118
+ self.quantity = attributes[:'quantity']
119
+ end
120
+
121
+ if attributes.key?(:'price')
122
+ self.price = attributes[:'price']
123
+ end
124
+
125
+ if attributes.key?(:'discount')
126
+ self.discount = attributes[:'discount']
127
+ end
128
+
129
+ if attributes.key?(:'tax')
130
+ self.tax = attributes[:'tax']
131
+ end
132
+
133
+ if attributes.key?(:'average_cost')
134
+ self.average_cost = attributes[:'average_cost']
135
+ end
136
+
137
+ if attributes.key?(:'tax_rule')
138
+ self.tax_rule = attributes[:'tax_rule']
139
+ end
140
+
141
+ if attributes.key?(:'comment')
142
+ self.comment = attributes[:'comment']
143
+ end
144
+
145
+ if attributes.key?(:'total')
146
+ self.total = attributes[:'total']
147
+ end
148
+ end
149
+
150
+ # Show invalid properties with the reasons. Usually used together with valid?
151
+ # @return Array for valid properties with the reasons
152
+ def list_invalid_properties
153
+ invalid_properties = Array.new
154
+ if @name.nil?
155
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
156
+ end
157
+
158
+ if @quantity.nil?
159
+ invalid_properties.push('invalid value for "quantity", quantity cannot be nil.')
160
+ end
161
+
162
+ if @price.nil?
163
+ invalid_properties.push('invalid value for "price", price cannot be nil.')
164
+ end
165
+
166
+ invalid_properties
167
+ end
168
+
169
+ # Check to see if the all the properties in the model are valid
170
+ # @return true if the model is valid
171
+ def valid?
172
+ return false if @name.nil?
173
+ return false if @quantity.nil?
174
+ return false if @price.nil?
175
+ true
176
+ end
177
+
178
+ # Checks equality by comparing each attribute.
179
+ # @param [Object] Object to be compared
180
+ def ==(o)
181
+ return true if self.equal?(o)
182
+ self.class == o.class &&
183
+ product_id == o.product_id &&
184
+ sku == o.sku &&
185
+ name == o.name &&
186
+ quantity == o.quantity &&
187
+ price == o.price &&
188
+ discount == o.discount &&
189
+ tax == o.tax &&
190
+ average_cost == o.average_cost &&
191
+ tax_rule == o.tax_rule &&
192
+ comment == o.comment &&
193
+ total == o.total
194
+ end
195
+
196
+ # @see the `==` method
197
+ # @param [Object] Object to be compared
198
+ def eql?(o)
199
+ self == o
200
+ end
201
+
202
+ # Calculates hash code according to all attributes.
203
+ # @return [Integer] Hash code
204
+ def hash
205
+ [product_id, sku, name, quantity, price, discount, tax, average_cost, tax_rule, comment, total].hash
206
+ end
207
+
208
+ # Builds the object from hash
209
+ # @param [Hash] attributes Model attributes in the form of hash
210
+ # @return [Object] Returns the model itself
211
+ def self.build_from_hash(attributes)
212
+ new.build_from_hash(attributes)
213
+ end
214
+
215
+ # Builds the object from hash
216
+ # @param [Hash] attributes Model attributes in the form of hash
217
+ # @return [Object] Returns the model itself
218
+ def build_from_hash(attributes)
219
+ return nil unless attributes.is_a?(Hash)
220
+ self.class.openapi_types.each_pair do |key, type|
221
+ if type =~ /\AArray<(.*)>/i
222
+ # check to ensure the input is an array given that the attribute
223
+ # is documented as an array but the input is not
224
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
225
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
226
+ end
227
+ elsif !attributes[self.class.attribute_map[key]].nil?
228
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
229
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
230
+ end
231
+
232
+ self
233
+ end
234
+
235
+ # Deserializes the data based on type
236
+ # @param string type Data type
237
+ # @param string value Value to be deserialized
238
+ # @return [Object] Deserialized data
239
+ def _deserialize(type, value)
240
+ case type.to_sym
241
+ when :DateTime
242
+ DateTime.parse(value)
243
+ when :Date
244
+ Date.parse(value)
245
+ when :String
246
+ value.to_s
247
+ when :Integer
248
+ value.to_i
249
+ when :Float
250
+ value.to_f
251
+ when :Boolean
252
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
253
+ true
254
+ else
255
+ false
256
+ end
257
+ when :Object
258
+ # generic object (usually a Hash), return directly
259
+ value
260
+ when /\AArray<(?<inner_type>.+)>\z/
261
+ inner_type = Regexp.last_match[:inner_type]
262
+ value.map { |v| _deserialize(inner_type, v) }
263
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
264
+ k_type = Regexp.last_match[:k_type]
265
+ v_type = Regexp.last_match[:v_type]
266
+ {}.tap do |hash|
267
+ value.each do |k, v|
268
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
269
+ end
270
+ end
271
+ else # model
272
+ DearInventoryRuby.const_get(type).build_from_hash(value)
273
+ end
274
+ end
275
+
276
+ # Returns the string representation of the object
277
+ # @return [String] String presentation of the object
278
+ def to_s
279
+ to_hash.to_s
280
+ end
281
+
282
+ # to_body is an alias to to_hash (backward compatibility)
283
+ # @return [Hash] Returns the object in the form of hash
284
+ def to_body
285
+ to_hash
286
+ end
287
+
288
+ # Returns the object in the form of hash
289
+ # @return [Hash] Returns the object in the form of hash
290
+ def to_hash
291
+ hash = {}
292
+ self.class.attribute_map.each_pair do |attr, param|
293
+ value = self.send(attr)
294
+ if value.nil?
295
+ is_nullable = self.class.openapi_nullable.include?(attr)
296
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
297
+ end
298
+
299
+ hash[param] = _to_hash(value)
300
+ end
301
+ hash
302
+ end
303
+
304
+ # Outputs non-array value in the form of hash
305
+ # For object, use to_hash. Otherwise, just return the value
306
+ # @param [Object] value Any valid value
307
+ # @return [Hash] Returns the value in the form of hash
308
+ def _to_hash(value)
309
+ if value.is_a?(Array)
310
+ value.compact.map { |v| _to_hash(v) }
311
+ elsif value.is_a?(Hash)
312
+ {}.tap do |hash|
313
+ value.each { |k, v| hash[k] = _to_hash(v) }
314
+ end
315
+ elsif value.respond_to? :to_hash
316
+ value.to_hash
317
+ else
318
+ value
319
+ end
320
+ end
321
+ end
322
+ end