dear-inventory-ruby 0.1.11 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/README.md +12 -5
  4. data/docs/Customer.md +1 -1
  5. data/docs/InventoryApi.md +118 -0
  6. data/docs/Me.md +2 -2
  7. data/docs/PriceTier.md +19 -0
  8. data/docs/PriceTiers.md +17 -0
  9. data/docs/SaleInvoice.md +41 -0
  10. data/docs/SaleInvoiceAdditionalCharge.md +33 -0
  11. data/docs/SaleInvoiceLine.md +39 -0
  12. data/docs/SaleInvoices.md +19 -0
  13. data/lib/dear-inventory-ruby.rb +6 -1
  14. data/lib/dear-inventory-ruby/api/inventory_api.rb +117 -0
  15. data/lib/dear-inventory-ruby/models/customer.rb +2 -1
  16. data/lib/dear-inventory-ruby/models/me.rb +4 -2
  17. data/lib/dear-inventory-ruby/models/price_tier.rb +217 -0
  18. data/lib/dear-inventory-ruby/models/price_tiers.rb +209 -0
  19. data/lib/dear-inventory-ruby/models/sale_invoice.rb +356 -0
  20. data/lib/dear-inventory-ruby/models/sale_invoice_additional_charge.rb +317 -0
  21. data/lib/dear-inventory-ruby/models/sale_invoice_line.rb +342 -0
  22. data/lib/dear-inventory-ruby/models/sale_invoices.rb +224 -0
  23. data/lib/dear-inventory-ruby/version.rb +1 -1
  24. data/spec/.DS_Store +0 -0
  25. data/spec/api/inventory_api_spec.rb +23 -0
  26. data/spec/models/price_tier_spec.rb +47 -0
  27. data/spec/models/{weight_unit_spec.rb → price_tiers_spec.rb} +12 -6
  28. data/spec/models/sale_invoice_additional_charge_spec.rb +89 -0
  29. data/spec/models/sale_invoice_line_spec.rb +107 -0
  30. data/spec/models/sale_invoice_spec.rb +113 -0
  31. data/spec/models/sale_invoices_spec.rb +47 -0
  32. metadata +31 -10
  33. data/docs/WeightUnit.md +0 -16
  34. data/lib/dear-inventory-ruby/models/weight_unit.rb +0 -39
@@ -0,0 +1,356 @@
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 SaleInvoice
17
+ # Identifier of sale Invoice task
18
+ attr_accessor :task_id
19
+
20
+ # if true then additional charges lines displayed in Lines array
21
+ attr_accessor :combine_additional_charges
22
+
23
+ # Invoice Number (auto-generated)
24
+ attr_accessor :invoice_number
25
+
26
+ # Additional information for Invoice.
27
+ attr_accessor :memo
28
+
29
+ # Invoice status. Possible Values are values. For POST available values are DRAFT, AUTHORISED
30
+ attr_accessor :status
31
+
32
+ # Invoice Date.
33
+ attr_accessor :invoice_date
34
+
35
+ # Invoice Due Date.
36
+ attr_accessor :invoice_due_date
37
+
38
+ # Decimal with up to 4 decimal places
39
+ attr_accessor :currency_conversion_rate
40
+
41
+ # Billing Address Line 1
42
+ attr_accessor :billing_address_line1
43
+
44
+ # Billing Address Line 2
45
+ attr_accessor :billing_address_line2
46
+
47
+ # Number of Fulfilment linked to this invoice
48
+ attr_accessor :linked_fulfillment_number
49
+
50
+ attr_accessor :lines
51
+
52
+ attr_accessor :additional_charges
53
+
54
+ # Attribute mapping from ruby-style variable name to JSON key.
55
+ def self.attribute_map
56
+ {
57
+ :'task_id' => :'TaskID',
58
+ :'combine_additional_charges' => :'CombineAdditionalCharges',
59
+ :'invoice_number' => :'InvoiceNumber',
60
+ :'memo' => :'Memo',
61
+ :'status' => :'Status',
62
+ :'invoice_date' => :'InvoiceDate',
63
+ :'invoice_due_date' => :'InvoiceDueDate',
64
+ :'currency_conversion_rate' => :'CurrencyConversionRate',
65
+ :'billing_address_line1' => :'BillingAddressLine1',
66
+ :'billing_address_line2' => :'BillingAddressLine2',
67
+ :'linked_fulfillment_number' => :'LinkedFulfillmentNumber',
68
+ :'lines' => :'Lines',
69
+ :'additional_charges' => :'AdditionalCharges'
70
+ }
71
+ end
72
+
73
+ # Attribute type mapping.
74
+ def self.openapi_types
75
+ {
76
+ :'task_id' => :'String',
77
+ :'combine_additional_charges' => :'Boolean',
78
+ :'invoice_number' => :'String',
79
+ :'memo' => :'String',
80
+ :'status' => :'String',
81
+ :'invoice_date' => :'String',
82
+ :'invoice_due_date' => :'String',
83
+ :'currency_conversion_rate' => :'Float',
84
+ :'billing_address_line1' => :'String',
85
+ :'billing_address_line2' => :'String',
86
+ :'linked_fulfillment_number' => :'Integer',
87
+ :'lines' => :'Array<SaleInvoiceLine>',
88
+ :'additional_charges' => :'Array<SaleInvoiceAdditionalCharge>'
89
+ }
90
+ end
91
+
92
+ # List of attributes with nullable: true
93
+ def self.openapi_nullable
94
+ Set.new([
95
+ ])
96
+ end
97
+
98
+ # Initializes the object
99
+ # @param [Hash] attributes Model attributes in the form of hash
100
+ def initialize(attributes = {})
101
+ if (!attributes.is_a?(Hash))
102
+ fail ArgumentError, "The input argument (attributes) must be a hash in `DearInventoryRuby::SaleInvoice` initialize method"
103
+ end
104
+
105
+ # check to see if the attribute exists and convert string to symbol for hash key
106
+ attributes = attributes.each_with_object({}) { |(k, v), h|
107
+ if (!self.class.attribute_map.key?(k.to_sym))
108
+ fail ArgumentError, "`#{k}` is not a valid attribute in `DearInventoryRuby::SaleInvoice`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
109
+ end
110
+ h[k.to_sym] = v
111
+ }
112
+
113
+ if attributes.key?(:'task_id')
114
+ self.task_id = attributes[:'task_id']
115
+ end
116
+
117
+ if attributes.key?(:'combine_additional_charges')
118
+ self.combine_additional_charges = attributes[:'combine_additional_charges']
119
+ else
120
+ self.combine_additional_charges = false
121
+ end
122
+
123
+ if attributes.key?(:'invoice_number')
124
+ self.invoice_number = attributes[:'invoice_number']
125
+ end
126
+
127
+ if attributes.key?(:'memo')
128
+ self.memo = attributes[:'memo']
129
+ end
130
+
131
+ if attributes.key?(:'status')
132
+ self.status = attributes[:'status']
133
+ end
134
+
135
+ if attributes.key?(:'invoice_date')
136
+ self.invoice_date = attributes[:'invoice_date']
137
+ end
138
+
139
+ if attributes.key?(:'invoice_due_date')
140
+ self.invoice_due_date = attributes[:'invoice_due_date']
141
+ end
142
+
143
+ if attributes.key?(:'currency_conversion_rate')
144
+ self.currency_conversion_rate = attributes[:'currency_conversion_rate']
145
+ end
146
+
147
+ if attributes.key?(:'billing_address_line1')
148
+ self.billing_address_line1 = attributes[:'billing_address_line1']
149
+ end
150
+
151
+ if attributes.key?(:'billing_address_line2')
152
+ self.billing_address_line2 = attributes[:'billing_address_line2']
153
+ end
154
+
155
+ if attributes.key?(:'linked_fulfillment_number')
156
+ self.linked_fulfillment_number = attributes[:'linked_fulfillment_number']
157
+ end
158
+
159
+ if attributes.key?(:'lines')
160
+ if (value = attributes[:'lines']).is_a?(Array)
161
+ self.lines = value
162
+ end
163
+ end
164
+
165
+ if attributes.key?(:'additional_charges')
166
+ if (value = attributes[:'additional_charges']).is_a?(Array)
167
+ self.additional_charges = value
168
+ end
169
+ end
170
+ end
171
+
172
+ # Show invalid properties with the reasons. Usually used together with valid?
173
+ # @return Array for valid properties with the reasons
174
+ def list_invalid_properties
175
+ invalid_properties = Array.new
176
+ if @task_id.nil?
177
+ invalid_properties.push('invalid value for "task_id", task_id cannot be nil.')
178
+ end
179
+
180
+ if @combine_additional_charges.nil?
181
+ invalid_properties.push('invalid value for "combine_additional_charges", combine_additional_charges cannot be nil.')
182
+ end
183
+
184
+ if @status.nil?
185
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
186
+ end
187
+
188
+ if @invoice_date.nil?
189
+ invalid_properties.push('invalid value for "invoice_date", invoice_date cannot be nil.')
190
+ end
191
+
192
+ if @invoice_due_date.nil?
193
+ invalid_properties.push('invalid value for "invoice_due_date", invoice_due_date cannot be nil.')
194
+ end
195
+
196
+ invalid_properties
197
+ end
198
+
199
+ # Check to see if the all the properties in the model are valid
200
+ # @return true if the model is valid
201
+ def valid?
202
+ return false if @task_id.nil?
203
+ return false if @combine_additional_charges.nil?
204
+ return false if @status.nil?
205
+ return false if @invoice_date.nil?
206
+ return false if @invoice_due_date.nil?
207
+ true
208
+ end
209
+
210
+ # Checks equality by comparing each attribute.
211
+ # @param [Object] Object to be compared
212
+ def ==(o)
213
+ return true if self.equal?(o)
214
+ self.class == o.class &&
215
+ task_id == o.task_id &&
216
+ combine_additional_charges == o.combine_additional_charges &&
217
+ invoice_number == o.invoice_number &&
218
+ memo == o.memo &&
219
+ status == o.status &&
220
+ invoice_date == o.invoice_date &&
221
+ invoice_due_date == o.invoice_due_date &&
222
+ currency_conversion_rate == o.currency_conversion_rate &&
223
+ billing_address_line1 == o.billing_address_line1 &&
224
+ billing_address_line2 == o.billing_address_line2 &&
225
+ linked_fulfillment_number == o.linked_fulfillment_number &&
226
+ lines == o.lines &&
227
+ additional_charges == o.additional_charges
228
+ end
229
+
230
+ # @see the `==` method
231
+ # @param [Object] Object to be compared
232
+ def eql?(o)
233
+ self == o
234
+ end
235
+
236
+ # Calculates hash code according to all attributes.
237
+ # @return [Integer] Hash code
238
+ def hash
239
+ [task_id, combine_additional_charges, invoice_number, memo, status, invoice_date, invoice_due_date, currency_conversion_rate, billing_address_line1, billing_address_line2, linked_fulfillment_number, lines, additional_charges].hash
240
+ end
241
+
242
+ # Builds the object from hash
243
+ # @param [Hash] attributes Model attributes in the form of hash
244
+ # @return [Object] Returns the model itself
245
+ def self.build_from_hash(attributes)
246
+ new.build_from_hash(attributes)
247
+ end
248
+
249
+ # Builds the object from hash
250
+ # @param [Hash] attributes Model attributes in the form of hash
251
+ # @return [Object] Returns the model itself
252
+ def build_from_hash(attributes)
253
+ return nil unless attributes.is_a?(Hash)
254
+ self.class.openapi_types.each_pair do |key, type|
255
+ if type =~ /\AArray<(.*)>/i
256
+ # check to ensure the input is an array given that the attribute
257
+ # is documented as an array but the input is not
258
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
259
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
260
+ end
261
+ elsif !attributes[self.class.attribute_map[key]].nil?
262
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
263
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
264
+ end
265
+
266
+ self
267
+ end
268
+
269
+ # Deserializes the data based on type
270
+ # @param string type Data type
271
+ # @param string value Value to be deserialized
272
+ # @return [Object] Deserialized data
273
+ def _deserialize(type, value)
274
+ case type.to_sym
275
+ when :DateTime
276
+ DateTime.parse(value)
277
+ when :Date
278
+ Date.parse(value)
279
+ when :String
280
+ value.to_s
281
+ when :Integer
282
+ value.to_i
283
+ when :Float
284
+ value.to_f
285
+ when :Boolean
286
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
287
+ true
288
+ else
289
+ false
290
+ end
291
+ when :Object
292
+ # generic object (usually a Hash), return directly
293
+ value
294
+ when /\AArray<(?<inner_type>.+)>\z/
295
+ inner_type = Regexp.last_match[:inner_type]
296
+ value.map { |v| _deserialize(inner_type, v) }
297
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
298
+ k_type = Regexp.last_match[:k_type]
299
+ v_type = Regexp.last_match[:v_type]
300
+ {}.tap do |hash|
301
+ value.each do |k, v|
302
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
303
+ end
304
+ end
305
+ else # model
306
+ DearInventoryRuby.const_get(type).build_from_hash(value)
307
+ end
308
+ end
309
+
310
+ # Returns the string representation of the object
311
+ # @return [String] String presentation of the object
312
+ def to_s
313
+ to_hash.to_s
314
+ end
315
+
316
+ # to_body is an alias to to_hash (backward compatibility)
317
+ # @return [Hash] Returns the object in the form of hash
318
+ def to_body
319
+ to_hash
320
+ end
321
+
322
+ # Returns the object in the form of hash
323
+ # @return [Hash] Returns the object in the form of hash
324
+ def to_hash
325
+ hash = {}
326
+ self.class.attribute_map.each_pair do |attr, param|
327
+ value = self.send(attr)
328
+ if value.nil?
329
+ is_nullable = self.class.openapi_nullable.include?(attr)
330
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
331
+ end
332
+
333
+ hash[param] = _to_hash(value)
334
+ end
335
+ hash
336
+ end
337
+
338
+ # Outputs non-array value in the form of hash
339
+ # For object, use to_hash. Otherwise, just return the value
340
+ # @param [Object] value Any valid value
341
+ # @return [Hash] Returns the value in the form of hash
342
+ def _to_hash(value)
343
+ if value.is_a?(Array)
344
+ value.compact.map { |v| _to_hash(v) }
345
+ elsif value.is_a?(Hash)
346
+ {}.tap do |hash|
347
+ value.each { |k, v| hash[k] = _to_hash(v) }
348
+ end
349
+ elsif value.respond_to? :to_hash
350
+ value.to_hash
351
+ else
352
+ value
353
+ end
354
+ end
355
+ end
356
+ end
@@ -0,0 +1,317 @@
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 SaleInvoiceAdditionalCharge
17
+ # Name of Service Product referenced by this Line
18
+ attr_accessor :description
19
+
20
+ # Product or service quantity. Minimal value is 1.
21
+ attr_accessor :quantity
22
+
23
+ # Price per unit in Customer currency
24
+ attr_accessor :price
25
+
26
+ # Discount. Value between 0 and 100. For free items discount is 100. Default value is 0
27
+ attr_accessor :discount
28
+
29
+ # Tax
30
+ attr_accessor :tax
31
+
32
+ # Line Total.For validation
33
+ attr_accessor :total
34
+
35
+ # Line Tax Rule name.
36
+ attr_accessor :tax_rule
37
+
38
+ # Revenue account
39
+ attr_accessor :account
40
+
41
+ # Comment
42
+ attr_accessor :comment
43
+
44
+ # Attribute mapping from ruby-style variable name to JSON key.
45
+ def self.attribute_map
46
+ {
47
+ :'description' => :'Description',
48
+ :'quantity' => :'Quantity',
49
+ :'price' => :'Price',
50
+ :'discount' => :'Discount',
51
+ :'tax' => :'Tax',
52
+ :'total' => :'Total',
53
+ :'tax_rule' => :'TaxRule',
54
+ :'account' => :'Account',
55
+ :'comment' => :'Comment'
56
+ }
57
+ end
58
+
59
+ # Attribute type mapping.
60
+ def self.openapi_types
61
+ {
62
+ :'description' => :'String',
63
+ :'quantity' => :'Float',
64
+ :'price' => :'Float',
65
+ :'discount' => :'Float',
66
+ :'tax' => :'Float',
67
+ :'total' => :'Float',
68
+ :'tax_rule' => :'Float',
69
+ :'account' => :'Float',
70
+ :'comment' => :'Float'
71
+ }
72
+ end
73
+
74
+ # List of attributes with nullable: true
75
+ def self.openapi_nullable
76
+ Set.new([
77
+ ])
78
+ end
79
+
80
+ # Initializes the object
81
+ # @param [Hash] attributes Model attributes in the form of hash
82
+ def initialize(attributes = {})
83
+ if (!attributes.is_a?(Hash))
84
+ fail ArgumentError, "The input argument (attributes) must be a hash in `DearInventoryRuby::SaleInvoiceAdditionalCharge` initialize method"
85
+ end
86
+
87
+ # check to see if the attribute exists and convert string to symbol for hash key
88
+ attributes = attributes.each_with_object({}) { |(k, v), h|
89
+ if (!self.class.attribute_map.key?(k.to_sym))
90
+ fail ArgumentError, "`#{k}` is not a valid attribute in `DearInventoryRuby::SaleInvoiceAdditionalCharge`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
91
+ end
92
+ h[k.to_sym] = v
93
+ }
94
+
95
+ if attributes.key?(:'description')
96
+ self.description = attributes[:'description']
97
+ end
98
+
99
+ if attributes.key?(:'quantity')
100
+ self.quantity = attributes[:'quantity']
101
+ end
102
+
103
+ if attributes.key?(:'price')
104
+ self.price = attributes[:'price']
105
+ end
106
+
107
+ if attributes.key?(:'discount')
108
+ self.discount = attributes[:'discount']
109
+ end
110
+
111
+ if attributes.key?(:'tax')
112
+ self.tax = attributes[:'tax']
113
+ end
114
+
115
+ if attributes.key?(:'total')
116
+ self.total = attributes[:'total']
117
+ end
118
+
119
+ if attributes.key?(:'tax_rule')
120
+ self.tax_rule = attributes[:'tax_rule']
121
+ end
122
+
123
+ if attributes.key?(:'account')
124
+ self.account = attributes[:'account']
125
+ end
126
+
127
+ if attributes.key?(:'comment')
128
+ self.comment = attributes[:'comment']
129
+ end
130
+ end
131
+
132
+ # Show invalid properties with the reasons. Usually used together with valid?
133
+ # @return Array for valid properties with the reasons
134
+ def list_invalid_properties
135
+ invalid_properties = Array.new
136
+ if @description.nil?
137
+ invalid_properties.push('invalid value for "description", description cannot be nil.')
138
+ end
139
+
140
+ if @quantity.nil?
141
+ invalid_properties.push('invalid value for "quantity", quantity cannot be nil.')
142
+ end
143
+
144
+ if @price.nil?
145
+ invalid_properties.push('invalid value for "price", price cannot be nil.')
146
+ end
147
+
148
+ if @tax.nil?
149
+ invalid_properties.push('invalid value for "tax", tax cannot be nil.')
150
+ end
151
+
152
+ if @tax_rule.nil?
153
+ invalid_properties.push('invalid value for "tax_rule", tax_rule cannot be nil.')
154
+ end
155
+
156
+ if @account.nil?
157
+ invalid_properties.push('invalid value for "account", account cannot be nil.')
158
+ end
159
+
160
+ invalid_properties
161
+ end
162
+
163
+ # Check to see if the all the properties in the model are valid
164
+ # @return true if the model is valid
165
+ def valid?
166
+ return false if @description.nil?
167
+ return false if @quantity.nil?
168
+ return false if @price.nil?
169
+ return false if @tax.nil?
170
+ return false if @tax_rule.nil?
171
+ return false if @account.nil?
172
+ true
173
+ end
174
+
175
+ # Checks equality by comparing each attribute.
176
+ # @param [Object] Object to be compared
177
+ def ==(o)
178
+ return true if self.equal?(o)
179
+ self.class == o.class &&
180
+ description == o.description &&
181
+ quantity == o.quantity &&
182
+ price == o.price &&
183
+ discount == o.discount &&
184
+ tax == o.tax &&
185
+ total == o.total &&
186
+ tax_rule == o.tax_rule &&
187
+ account == o.account &&
188
+ comment == o.comment
189
+ end
190
+
191
+ # @see the `==` method
192
+ # @param [Object] Object to be compared
193
+ def eql?(o)
194
+ self == o
195
+ end
196
+
197
+ # Calculates hash code according to all attributes.
198
+ # @return [Integer] Hash code
199
+ def hash
200
+ [description, quantity, price, discount, tax, total, tax_rule, account, comment].hash
201
+ end
202
+
203
+ # Builds the object from hash
204
+ # @param [Hash] attributes Model attributes in the form of hash
205
+ # @return [Object] Returns the model itself
206
+ def self.build_from_hash(attributes)
207
+ new.build_from_hash(attributes)
208
+ end
209
+
210
+ # Builds the object from hash
211
+ # @param [Hash] attributes Model attributes in the form of hash
212
+ # @return [Object] Returns the model itself
213
+ def build_from_hash(attributes)
214
+ return nil unless attributes.is_a?(Hash)
215
+ self.class.openapi_types.each_pair do |key, type|
216
+ if type =~ /\AArray<(.*)>/i
217
+ # check to ensure the input is an array given that the attribute
218
+ # is documented as an array but the input is not
219
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
220
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
221
+ end
222
+ elsif !attributes[self.class.attribute_map[key]].nil?
223
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
224
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
225
+ end
226
+
227
+ self
228
+ end
229
+
230
+ # Deserializes the data based on type
231
+ # @param string type Data type
232
+ # @param string value Value to be deserialized
233
+ # @return [Object] Deserialized data
234
+ def _deserialize(type, value)
235
+ case type.to_sym
236
+ when :DateTime
237
+ DateTime.parse(value)
238
+ when :Date
239
+ Date.parse(value)
240
+ when :String
241
+ value.to_s
242
+ when :Integer
243
+ value.to_i
244
+ when :Float
245
+ value.to_f
246
+ when :Boolean
247
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
248
+ true
249
+ else
250
+ false
251
+ end
252
+ when :Object
253
+ # generic object (usually a Hash), return directly
254
+ value
255
+ when /\AArray<(?<inner_type>.+)>\z/
256
+ inner_type = Regexp.last_match[:inner_type]
257
+ value.map { |v| _deserialize(inner_type, v) }
258
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
259
+ k_type = Regexp.last_match[:k_type]
260
+ v_type = Regexp.last_match[:v_type]
261
+ {}.tap do |hash|
262
+ value.each do |k, v|
263
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
264
+ end
265
+ end
266
+ else # model
267
+ DearInventoryRuby.const_get(type).build_from_hash(value)
268
+ end
269
+ end
270
+
271
+ # Returns the string representation of the object
272
+ # @return [String] String presentation of the object
273
+ def to_s
274
+ to_hash.to_s
275
+ end
276
+
277
+ # to_body is an alias to to_hash (backward compatibility)
278
+ # @return [Hash] Returns the object in the form of hash
279
+ def to_body
280
+ to_hash
281
+ end
282
+
283
+ # Returns the object in the form of hash
284
+ # @return [Hash] Returns the object in the form of hash
285
+ def to_hash
286
+ hash = {}
287
+ self.class.attribute_map.each_pair do |attr, param|
288
+ value = self.send(attr)
289
+ if value.nil?
290
+ is_nullable = self.class.openapi_nullable.include?(attr)
291
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
292
+ end
293
+
294
+ hash[param] = _to_hash(value)
295
+ end
296
+ hash
297
+ end
298
+
299
+ # Outputs non-array value in the form of hash
300
+ # For object, use to_hash. Otherwise, just return the value
301
+ # @param [Object] value Any valid value
302
+ # @return [Hash] Returns the value in the form of hash
303
+ def _to_hash(value)
304
+ if value.is_a?(Array)
305
+ value.compact.map { |v| _to_hash(v) }
306
+ elsif value.is_a?(Hash)
307
+ {}.tap do |hash|
308
+ value.each { |k, v| hash[k] = _to_hash(v) }
309
+ end
310
+ elsif value.respond_to? :to_hash
311
+ value.to_hash
312
+ else
313
+ value
314
+ end
315
+ end
316
+ end
317
+ end