dear-inventory-ruby 0.1.13 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -1
- data/README.md +9 -7
- data/dear-inventory-ruby.gemspec +1 -1
- data/docs/Customer.md +1 -1
- data/docs/InventoryApi.md +64 -0
- data/docs/Me.md +3 -3
- data/docs/SaleInvoice.md +41 -0
- data/docs/SaleInvoiceAdditionalCharge.md +33 -0
- data/docs/SaleInvoiceLine.md +39 -0
- data/docs/SaleInvoices.md +19 -0
- data/lib/dear-inventory-ruby.rb +4 -3
- data/lib/dear-inventory-ruby/api/inventory_api.rb +63 -0
- data/lib/dear-inventory-ruby/models/account.rb +0 -34
- data/lib/dear-inventory-ruby/models/customer.rb +2 -35
- data/lib/dear-inventory-ruby/models/me.rb +6 -3
- data/lib/dear-inventory-ruby/models/payment_term.rb +0 -34
- data/lib/dear-inventory-ruby/models/sale_invoice.rb +356 -0
- data/lib/dear-inventory-ruby/models/sale_invoice_additional_charge.rb +317 -0
- data/lib/dear-inventory-ruby/models/sale_invoice_line.rb +342 -0
- data/lib/dear-inventory-ruby/models/sale_invoices.rb +224 -0
- data/lib/dear-inventory-ruby/version.rb +1 -1
- data/spec/.DS_Store +0 -0
- data/spec/api/inventory_api_spec.rb +13 -0
- data/spec/models/account_spec.rb +0 -4
- data/spec/models/customer_spec.rb +0 -4
- data/spec/models/payment_term_spec.rb +0 -4
- data/spec/models/sale_invoice_additional_charge_spec.rb +89 -0
- data/spec/models/sale_invoice_line_spec.rb +107 -0
- data/spec/models/sale_invoice_spec.rb +113 -0
- data/spec/models/sale_invoices_spec.rb +47 -0
- metadata +31 -21
- data/docs/CurrencyCode.md +0 -16
- data/docs/DimensionsUnit.md +0 -16
- data/docs/WeightUnit.md +0 -16
- data/lib/dear-inventory-ruby/models/currency_code.rb +0 -196
- data/lib/dear-inventory-ruby/models/dimensions_unit.rb +0 -42
- data/lib/dear-inventory-ruby/models/weight_unit.rb +0 -39
- data/pkg/dear-inventory-ruby-0.1.13.gem +0 -0
- data/spec/models/currency_code_spec.rb +0 -35
- data/spec/models/dimensions_unit_spec.rb +0 -35
- data/spec/models/weight_unit_spec.rb +0 -35
@@ -59,28 +59,6 @@ module DearInventoryRuby
|
|
59
59
|
# Currency. Read-only.
|
60
60
|
attr_accessor :currency
|
61
61
|
|
62
|
-
class EnumAttributeValidator
|
63
|
-
attr_reader :datatype
|
64
|
-
attr_reader :allowable_values
|
65
|
-
|
66
|
-
def initialize(datatype, allowable_values)
|
67
|
-
@allowable_values = allowable_values.map do |value|
|
68
|
-
case datatype.to_s
|
69
|
-
when /Integer/i
|
70
|
-
value.to_i
|
71
|
-
when /Float/i
|
72
|
-
value.to_f
|
73
|
-
else
|
74
|
-
value
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def valid?(value)
|
80
|
-
!value || allowable_values.include?(value)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
62
|
# Attribute mapping from ruby-style variable name to JSON key.
|
85
63
|
def self.attribute_map
|
86
64
|
{
|
@@ -255,8 +233,6 @@ module DearInventoryRuby
|
|
255
233
|
return false if @type.to_s.length > 50
|
256
234
|
return false if @status.nil?
|
257
235
|
return false if @status.to_s.length > 50
|
258
|
-
_class_validator = EnumAttributeValidator.new('String', ["ASSET", "LIABILITY", "EXPENSE", "EQUITY", "REVENUE"])
|
259
|
-
return false unless _class_validator.valid?(@_class)
|
260
236
|
true
|
261
237
|
end
|
262
238
|
|
@@ -316,16 +292,6 @@ module DearInventoryRuby
|
|
316
292
|
@status = status
|
317
293
|
end
|
318
294
|
|
319
|
-
# Custom attribute writer method checking allowed values (enum).
|
320
|
-
# @param [Object] _class Object to be assigned
|
321
|
-
def _class=(_class)
|
322
|
-
validator = EnumAttributeValidator.new('String', ["ASSET", "LIABILITY", "EXPENSE", "EQUITY", "REVENUE"])
|
323
|
-
unless validator.valid?(_class)
|
324
|
-
fail ArgumentError, "invalid value for \"_class\", must be one of #{validator.allowable_values}."
|
325
|
-
end
|
326
|
-
@_class = _class
|
327
|
-
end
|
328
|
-
|
329
295
|
# Checks equality by comparing each attribute.
|
330
296
|
# @param [Object] Object to be compared
|
331
297
|
def ==(o)
|
@@ -23,6 +23,7 @@ module DearInventoryRuby
|
|
23
23
|
# Points that Customer is Active. Available values are Active and Deprecated. Required for POST
|
24
24
|
attr_accessor :status
|
25
25
|
|
26
|
+
# Currency code of Customer
|
26
27
|
attr_accessor :currency
|
27
28
|
|
28
29
|
# Payment term
|
@@ -109,28 +110,6 @@ module DearInventoryRuby
|
|
109
110
|
# List of contacts
|
110
111
|
attr_accessor :contacts
|
111
112
|
|
112
|
-
class EnumAttributeValidator
|
113
|
-
attr_reader :datatype
|
114
|
-
attr_reader :allowable_values
|
115
|
-
|
116
|
-
def initialize(datatype, allowable_values)
|
117
|
-
@allowable_values = allowable_values.map do |value|
|
118
|
-
case datatype.to_s
|
119
|
-
when /Integer/i
|
120
|
-
value.to_i
|
121
|
-
when /Float/i
|
122
|
-
value.to_f
|
123
|
-
else
|
124
|
-
value
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def valid?(value)
|
130
|
-
!value || allowable_values.include?(value)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
113
|
# Attribute mapping from ruby-style variable name to JSON key.
|
135
114
|
def self.attribute_map
|
136
115
|
{
|
@@ -175,7 +154,7 @@ module DearInventoryRuby
|
|
175
154
|
:'id' => :'String',
|
176
155
|
:'name' => :'String',
|
177
156
|
:'status' => :'String',
|
178
|
-
:'currency' => :'
|
157
|
+
:'currency' => :'String',
|
179
158
|
:'payment_term' => :'String',
|
180
159
|
:'account_receivable' => :'String',
|
181
160
|
:'revenue_account' => :'String',
|
@@ -412,8 +391,6 @@ module DearInventoryRuby
|
|
412
391
|
return false if @name.nil?
|
413
392
|
return false if @name.to_s.length > 256
|
414
393
|
return false if @status.nil?
|
415
|
-
status_validator = EnumAttributeValidator.new('String', ["Active", "Deprecated"])
|
416
|
-
return false unless status_validator.valid?(@status)
|
417
394
|
return false if @currency.nil?
|
418
395
|
return false if @payment_term.nil?
|
419
396
|
return false if @account_receivable.nil?
|
@@ -437,16 +414,6 @@ module DearInventoryRuby
|
|
437
414
|
@name = name
|
438
415
|
end
|
439
416
|
|
440
|
-
# Custom attribute writer method checking allowed values (enum).
|
441
|
-
# @param [Object] status Object to be assigned
|
442
|
-
def status=(status)
|
443
|
-
validator = EnumAttributeValidator.new('String', ["Active", "Deprecated"])
|
444
|
-
unless validator.valid?(status)
|
445
|
-
fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
|
446
|
-
end
|
447
|
-
@status = status
|
448
|
-
end
|
449
|
-
|
450
417
|
# Custom attribute writer method with validation
|
451
418
|
# @param [Object] comments Value to be assigned
|
452
419
|
def comments=(comments)
|
@@ -17,13 +17,16 @@ module DearInventoryRuby
|
|
17
17
|
# Your company name
|
18
18
|
attr_accessor :company
|
19
19
|
|
20
|
+
# Your company base currency
|
20
21
|
attr_accessor :currency
|
21
22
|
|
22
23
|
# Time Zone where your company located
|
23
24
|
attr_accessor :time_zone
|
24
25
|
|
26
|
+
# Unit of measure for unit weight
|
25
27
|
attr_accessor :default_weight_units
|
26
28
|
|
29
|
+
# Unit of measure for unit length/width/height
|
27
30
|
attr_accessor :default_dimensions_units
|
28
31
|
|
29
32
|
# Financial settings option. Indicates date period start from what you can change transactional data. Formatted in Tenant date format
|
@@ -49,10 +52,10 @@ module DearInventoryRuby
|
|
49
52
|
def self.openapi_types
|
50
53
|
{
|
51
54
|
:'company' => :'String',
|
52
|
-
:'currency' => :'
|
55
|
+
:'currency' => :'String',
|
53
56
|
:'time_zone' => :'String',
|
54
|
-
:'default_weight_units' => :'
|
55
|
-
:'default_dimensions_units' => :'
|
57
|
+
:'default_weight_units' => :'String',
|
58
|
+
:'default_dimensions_units' => :'String',
|
56
59
|
:'lock_date' => :'Date',
|
57
60
|
:'opening_balance_date' => :'Date'
|
58
61
|
}
|
@@ -32,28 +32,6 @@ module DearInventoryRuby
|
|
32
32
|
# Points that Payment Term is Default. `False` as default for POST.
|
33
33
|
attr_accessor :is_default
|
34
34
|
|
35
|
-
class EnumAttributeValidator
|
36
|
-
attr_reader :datatype
|
37
|
-
attr_reader :allowable_values
|
38
|
-
|
39
|
-
def initialize(datatype, allowable_values)
|
40
|
-
@allowable_values = allowable_values.map do |value|
|
41
|
-
case datatype.to_s
|
42
|
-
when /Integer/i
|
43
|
-
value.to_i
|
44
|
-
when /Float/i
|
45
|
-
value.to_f
|
46
|
-
else
|
47
|
-
value
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def valid?(value)
|
53
|
-
!value || allowable_values.include?(value)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
35
|
# Attribute mapping from ruby-style variable name to JSON key.
|
58
36
|
def self.attribute_map
|
59
37
|
{
|
@@ -148,8 +126,6 @@ module DearInventoryRuby
|
|
148
126
|
def valid?
|
149
127
|
return false if @name.nil?
|
150
128
|
return false if @name.to_s.length > 256
|
151
|
-
method_validator = EnumAttributeValidator.new('String', ["number of days", "day of next month", "last day of next month", "days since the end of the month"])
|
152
|
-
return false unless method_validator.valid?(@method)
|
153
129
|
true
|
154
130
|
end
|
155
131
|
|
@@ -167,16 +143,6 @@ module DearInventoryRuby
|
|
167
143
|
@name = name
|
168
144
|
end
|
169
145
|
|
170
|
-
# Custom attribute writer method checking allowed values (enum).
|
171
|
-
# @param [Object] method Object to be assigned
|
172
|
-
def method=(method)
|
173
|
-
validator = EnumAttributeValidator.new('String', ["number of days", "day of next month", "last day of next month", "days since the end of the month"])
|
174
|
-
unless validator.valid?(method)
|
175
|
-
fail ArgumentError, "invalid value for \"method\", must be one of #{validator.allowable_values}."
|
176
|
-
end
|
177
|
-
@method = method
|
178
|
-
end
|
179
|
-
|
180
146
|
# Checks equality by comparing each attribute.
|
181
147
|
# @param [Object] Object to be compared
|
182
148
|
def ==(o)
|
@@ -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
|