tremendous_ruby 5.6.0 → 5.8.0

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 (30) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tremendous/api/tremendous_api.rb +148 -10
  3. data/lib/tremendous/models/balance_transaction.rb +13 -4
  4. data/lib/tremendous/models/balance_transaction_order.rb +256 -0
  5. data/lib/tremendous/models/balance_transaction_order_payment.rb +358 -0
  6. data/lib/tremendous/models/create_report201_response.rb +231 -0
  7. data/lib/tremendous/models/create_report201_response_report.rb +291 -0
  8. data/lib/tremendous/models/create_report_request.rb +295 -0
  9. data/lib/tremendous/models/create_report_request_filters.rb +216 -0
  10. data/lib/tremendous/models/create_report_request_filters_digital_rewards.rb +340 -0
  11. data/lib/tremendous/models/create_report_request_filters_digital_rewards_amount.rb +226 -0
  12. data/lib/tremendous/models/create_report_request_filters_digital_rewards_created_at.rb +226 -0
  13. data/lib/tremendous/models/fraud_review.rb +23 -1
  14. data/lib/tremendous/models/fraud_review_risk.rb +41 -0
  15. data/lib/tremendous/models/get_fraud_review200_response_fraud_review.rb +23 -1
  16. data/lib/tremendous/models/get_order200_response.rb +221 -0
  17. data/lib/tremendous/models/list_balance_transactions200_response_transactions_inner.rb +13 -4
  18. data/lib/tremendous/models/list_balance_transactions200_response_transactions_inner_order.rb +256 -0
  19. data/lib/tremendous/models/list_balance_transactions200_response_transactions_inner_order_payment.rb +358 -0
  20. data/lib/tremendous/models/list_funding_sources200_response_funding_sources_inner_meta.rb +37 -7
  21. data/lib/tremendous/models/list_funding_sources200_response_funding_sources_inner_meta_failure_details.rb +225 -0
  22. data/lib/tremendous/models/list_orders200_response_orders_inner_payment.rb +64 -7
  23. data/lib/tremendous/models/order_base_payment.rb +64 -7
  24. data/lib/tremendous/models/payment_details.rb +64 -7
  25. data/lib/tremendous/models/payout.rb +16 -4
  26. data/lib/tremendous/models/report.rb +291 -0
  27. data/lib/tremendous/models/resend_reward_request.rb +225 -0
  28. data/lib/tremendous/version.rb +1 -1
  29. data/lib/tremendous.rb +16 -1
  30. metadata +19 -3
@@ -0,0 +1,358 @@
1
+ =begin
2
+ #API Endpoints
3
+
4
+ #Deliver monetary rewards and incentives to employees, customers, survey participants, and more through the Tremendous API. For organizational tasks, like managing your organization and it's members within Tremendous, please see the Tremendous Organizational API.
5
+
6
+ The version of the OpenAPI document: 2
7
+ Contact: developers@tremendous.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.8.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Tremendous
17
+ class ListBalanceTransactions200ResponseTransactionsInnerOrderPayment
18
+ # Total price of the order before fees (in USD)
19
+ attr_accessor :subtotal
20
+
21
+ # Total price of the order including fees (in USD)
22
+ attr_accessor :total
23
+
24
+ # Fees for the order (in USD)
25
+ attr_accessor :fees
26
+
27
+ # Discount for the order (in USD)
28
+ attr_accessor :discount
29
+
30
+ attr_accessor :refund
31
+
32
+ # Attribute mapping from ruby-style variable name to JSON key.
33
+ def self.attribute_map
34
+ {
35
+ :'subtotal' => :'subtotal',
36
+ :'total' => :'total',
37
+ :'fees' => :'fees',
38
+ :'discount' => :'discount',
39
+ :'refund' => :'refund'
40
+ }
41
+ end
42
+
43
+ # Returns all the JSON keys this model knows about
44
+ def self.acceptable_attributes
45
+ attribute_map.values
46
+ end
47
+
48
+ # Attribute type mapping.
49
+ def self.openapi_types
50
+ {
51
+ :'subtotal' => :'Float',
52
+ :'total' => :'Float',
53
+ :'fees' => :'Float',
54
+ :'discount' => :'Float',
55
+ :'refund' => :'ListOrders200ResponseOrdersInnerPaymentRefund'
56
+ }
57
+ end
58
+
59
+ # List of attributes with nullable: true
60
+ def self.openapi_nullable
61
+ Set.new([
62
+ ])
63
+ end
64
+
65
+ # Initializes the object
66
+ # @param [Hash] attributes Model attributes in the form of hash
67
+ def initialize(attributes = {})
68
+ if (!attributes.is_a?(Hash))
69
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Tremendous::ListBalanceTransactions200ResponseTransactionsInnerOrderPayment` initialize method"
70
+ end
71
+
72
+ # check to see if the attribute exists and convert string to symbol for hash key
73
+ attributes = attributes.each_with_object({}) { |(k, v), h|
74
+ if (!self.class.attribute_map.key?(k.to_sym))
75
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Tremendous::ListBalanceTransactions200ResponseTransactionsInnerOrderPayment`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
76
+ end
77
+ h[k.to_sym] = v
78
+ }
79
+
80
+ if attributes.key?(:'subtotal')
81
+ self.subtotal = attributes[:'subtotal']
82
+ else
83
+ self.subtotal = nil
84
+ end
85
+
86
+ if attributes.key?(:'total')
87
+ self.total = attributes[:'total']
88
+ else
89
+ self.total = nil
90
+ end
91
+
92
+ if attributes.key?(:'fees')
93
+ self.fees = attributes[:'fees']
94
+ else
95
+ self.fees = nil
96
+ end
97
+
98
+ if attributes.key?(:'discount')
99
+ self.discount = attributes[:'discount']
100
+ else
101
+ self.discount = nil
102
+ end
103
+
104
+ if attributes.key?(:'refund')
105
+ self.refund = attributes[:'refund']
106
+ end
107
+ end
108
+
109
+ # Show invalid properties with the reasons. Usually used together with valid?
110
+ # @return Array for valid properties with the reasons
111
+ def list_invalid_properties
112
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
113
+ invalid_properties = Array.new
114
+ if @subtotal.nil?
115
+ invalid_properties.push('invalid value for "subtotal", subtotal cannot be nil.')
116
+ end
117
+
118
+ if @subtotal < 0
119
+ invalid_properties.push('invalid value for "subtotal", must be greater than or equal to 0.')
120
+ end
121
+
122
+ if @total.nil?
123
+ invalid_properties.push('invalid value for "total", total cannot be nil.')
124
+ end
125
+
126
+ if @total < 0
127
+ invalid_properties.push('invalid value for "total", must be greater than or equal to 0.')
128
+ end
129
+
130
+ if @fees.nil?
131
+ invalid_properties.push('invalid value for "fees", fees cannot be nil.')
132
+ end
133
+
134
+ if @fees < 0
135
+ invalid_properties.push('invalid value for "fees", must be greater than or equal to 0.')
136
+ end
137
+
138
+ if @discount.nil?
139
+ invalid_properties.push('invalid value for "discount", discount cannot be nil.')
140
+ end
141
+
142
+ if @discount < 0
143
+ invalid_properties.push('invalid value for "discount", must be greater than or equal to 0.')
144
+ end
145
+
146
+ invalid_properties
147
+ end
148
+
149
+ # Check to see if the all the properties in the model are valid
150
+ # @return true if the model is valid
151
+ def valid?
152
+ warn '[DEPRECATED] the `valid?` method is obsolete'
153
+ return false if @subtotal.nil?
154
+ return false if @subtotal < 0
155
+ return false if @total.nil?
156
+ return false if @total < 0
157
+ return false if @fees.nil?
158
+ return false if @fees < 0
159
+ return false if @discount.nil?
160
+ return false if @discount < 0
161
+ true
162
+ end
163
+
164
+ # Custom attribute writer method with validation
165
+ # @param [Object] subtotal Value to be assigned
166
+ def subtotal=(subtotal)
167
+ if subtotal.nil?
168
+ fail ArgumentError, 'subtotal cannot be nil'
169
+ end
170
+
171
+ if subtotal < 0
172
+ fail ArgumentError, 'invalid value for "subtotal", must be greater than or equal to 0.'
173
+ end
174
+
175
+ @subtotal = subtotal
176
+ end
177
+
178
+ # Custom attribute writer method with validation
179
+ # @param [Object] total Value to be assigned
180
+ def total=(total)
181
+ if total.nil?
182
+ fail ArgumentError, 'total cannot be nil'
183
+ end
184
+
185
+ if total < 0
186
+ fail ArgumentError, 'invalid value for "total", must be greater than or equal to 0.'
187
+ end
188
+
189
+ @total = total
190
+ end
191
+
192
+ # Custom attribute writer method with validation
193
+ # @param [Object] fees Value to be assigned
194
+ def fees=(fees)
195
+ if fees.nil?
196
+ fail ArgumentError, 'fees cannot be nil'
197
+ end
198
+
199
+ if fees < 0
200
+ fail ArgumentError, 'invalid value for "fees", must be greater than or equal to 0.'
201
+ end
202
+
203
+ @fees = fees
204
+ end
205
+
206
+ # Custom attribute writer method with validation
207
+ # @param [Object] discount Value to be assigned
208
+ def discount=(discount)
209
+ if discount.nil?
210
+ fail ArgumentError, 'discount cannot be nil'
211
+ end
212
+
213
+ if discount < 0
214
+ fail ArgumentError, 'invalid value for "discount", must be greater than or equal to 0.'
215
+ end
216
+
217
+ @discount = discount
218
+ end
219
+
220
+ # Checks equality by comparing each attribute.
221
+ # @param [Object] Object to be compared
222
+ def ==(o)
223
+ return true if self.equal?(o)
224
+ self.class == o.class &&
225
+ subtotal == o.subtotal &&
226
+ total == o.total &&
227
+ fees == o.fees &&
228
+ discount == o.discount &&
229
+ refund == o.refund
230
+ end
231
+
232
+ # @see the `==` method
233
+ # @param [Object] Object to be compared
234
+ def eql?(o)
235
+ self == o
236
+ end
237
+
238
+ # Calculates hash code according to all attributes.
239
+ # @return [Integer] Hash code
240
+ def hash
241
+ [subtotal, total, fees, discount, refund].hash
242
+ end
243
+
244
+ # Builds the object from hash
245
+ # @param [Hash] attributes Model attributes in the form of hash
246
+ # @return [Object] Returns the model itself
247
+ def self.build_from_hash(attributes)
248
+ return nil unless attributes.is_a?(Hash)
249
+ attributes = attributes.transform_keys(&:to_sym)
250
+ transformed_hash = {}
251
+ openapi_types.each_pair do |key, type|
252
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
253
+ transformed_hash["#{key}"] = nil
254
+ elsif type =~ /\AArray<(.*)>/i
255
+ # check to ensure the input is an array given that the attribute
256
+ # is documented as an array but the input is not
257
+ if attributes[attribute_map[key]].is_a?(Array)
258
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
259
+ end
260
+ elsif !attributes[attribute_map[key]].nil?
261
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
262
+ end
263
+ end
264
+ new(transformed_hash)
265
+ end
266
+
267
+ # Deserializes the data based on type
268
+ # @param string type Data type
269
+ # @param string value Value to be deserialized
270
+ # @return [Object] Deserialized data
271
+ def self._deserialize(type, value)
272
+ case type.to_sym
273
+ when :Time
274
+ Time.parse(value)
275
+ when :Date
276
+ Date.parse(value)
277
+ when :String
278
+ value.to_s
279
+ when :Integer
280
+ value.to_i
281
+ when :Float
282
+ value.to_f
283
+ when :Boolean
284
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
285
+ true
286
+ else
287
+ false
288
+ end
289
+ when :Object
290
+ # generic object (usually a Hash), return directly
291
+ value
292
+ when /\AArray<(?<inner_type>.+)>\z/
293
+ inner_type = Regexp.last_match[:inner_type]
294
+ value.map { |v| _deserialize(inner_type, v) }
295
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
296
+ k_type = Regexp.last_match[:k_type]
297
+ v_type = Regexp.last_match[:v_type]
298
+ {}.tap do |hash|
299
+ value.each do |k, v|
300
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
301
+ end
302
+ end
303
+ else # model
304
+ # models (e.g. Pet) or oneOf
305
+ klass = Tremendous.const_get(type)
306
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.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
+
356
+ end
357
+
358
+ end
@@ -48,9 +48,17 @@ module Tremendous
48
48
  # **Only available when `method` is set to `credit_card`.** Is this credit card expired
49
49
  attr_accessor :expired
50
50
 
51
+ # **Only available when `method` is set to `credit_card`.** Year part of card's expiration date
52
+ attr_accessor :year
53
+
54
+ # **Only available when `method` is set to `credit_card`.** Month part of card's expiration date
55
+ attr_accessor :month
56
+
51
57
  # **Only available when `method` is set to `bank_account` or `credit_card`.** Point in time when the last order failed using this bank account or credit card as a funding source.
52
58
  attr_accessor :last_payment_failed_at
53
59
 
60
+ attr_accessor :failure_details
61
+
54
62
  class EnumAttributeValidator
55
63
  attr_reader :datatype
56
64
  attr_reader :allowable_values
@@ -87,7 +95,10 @@ module Tremendous
87
95
  :'network' => :'network',
88
96
  :'last4' => :'last4',
89
97
  :'expired' => :'expired',
90
- :'last_payment_failed_at' => :'last_payment_failed_at'
98
+ :'year' => :'year',
99
+ :'month' => :'month',
100
+ :'last_payment_failed_at' => :'last_payment_failed_at',
101
+ :'failure_details' => :'failure_details'
91
102
  }
92
103
  end
93
104
 
@@ -110,7 +121,10 @@ module Tremendous
110
121
  :'network' => :'String',
111
122
  :'last4' => :'String',
112
123
  :'expired' => :'Boolean',
113
- :'last_payment_failed_at' => :'Time'
124
+ :'year' => :'String',
125
+ :'month' => :'String',
126
+ :'last_payment_failed_at' => :'Time',
127
+ :'failure_details' => :'ListFundingSources200ResponseFundingSourcesInnerMetaFailureDetails'
114
128
  }
115
129
  end
116
130
 
@@ -118,7 +132,8 @@ module Tremendous
118
132
  def self.openapi_nullable
119
133
  Set.new([
120
134
  :'bank_name',
121
- :'last_payment_failed_at'
135
+ :'last_payment_failed_at',
136
+ :'failure_details'
122
137
  ])
123
138
  end
124
139
 
@@ -181,9 +196,21 @@ module Tremendous
181
196
  self.expired = attributes[:'expired']
182
197
  end
183
198
 
199
+ if attributes.key?(:'year')
200
+ self.year = attributes[:'year']
201
+ end
202
+
203
+ if attributes.key?(:'month')
204
+ self.month = attributes[:'month']
205
+ end
206
+
184
207
  if attributes.key?(:'last_payment_failed_at')
185
208
  self.last_payment_failed_at = attributes[:'last_payment_failed_at']
186
209
  end
210
+
211
+ if attributes.key?(:'failure_details')
212
+ self.failure_details = attributes[:'failure_details']
213
+ end
187
214
  end
188
215
 
189
216
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -217,7 +244,7 @@ module Tremendous
217
244
  return false unless account_type_validator.valid?(@account_type)
218
245
  return false if !@account_number_mask.nil? && @account_number_mask !~ Regexp.new(/[0-9]{4}/)
219
246
  return false if !@account_routing_mask.nil? && @account_routing_mask !~ Regexp.new(/[0-9]{4}/)
220
- network_validator = EnumAttributeValidator.new('String', ["MasterCard", "Amex", "JCB", "Diner's Club", "visa", "discover", "laser", "elo", "maestro", "solo"])
247
+ network_validator = EnumAttributeValidator.new('String', ["MasterCard", "Amex", "JCB", "Diner's Club", "Visa", "Discover", "Laser", "Elo", "Maestro", "Solo"])
221
248
  return false unless network_validator.valid?(@network)
222
249
  return false if !@last4.nil? && @last4 !~ Regexp.new(/[0-9]{4}/)
223
250
  true
@@ -266,7 +293,7 @@ module Tremendous
266
293
  # Custom attribute writer method checking allowed values (enum).
267
294
  # @param [Object] network Object to be assigned
268
295
  def network=(network)
269
- validator = EnumAttributeValidator.new('String', ["MasterCard", "Amex", "JCB", "Diner's Club", "visa", "discover", "laser", "elo", "maestro", "solo"])
296
+ validator = EnumAttributeValidator.new('String', ["MasterCard", "Amex", "JCB", "Diner's Club", "Visa", "Discover", "Laser", "Elo", "Maestro", "Solo"])
270
297
  unless validator.valid?(network)
271
298
  fail ArgumentError, "invalid value for \"network\", must be one of #{validator.allowable_values}."
272
299
  end
@@ -304,7 +331,10 @@ module Tremendous
304
331
  network == o.network &&
305
332
  last4 == o.last4 &&
306
333
  expired == o.expired &&
307
- last_payment_failed_at == o.last_payment_failed_at
334
+ year == o.year &&
335
+ month == o.month &&
336
+ last_payment_failed_at == o.last_payment_failed_at &&
337
+ failure_details == o.failure_details
308
338
  end
309
339
 
310
340
  # @see the `==` method
@@ -316,7 +346,7 @@ module Tremendous
316
346
  # Calculates hash code according to all attributes.
317
347
  # @return [Integer] Hash code
318
348
  def hash
319
- [available_cents, pending_cents, accountholder_name, account_type, bank_name, account_number_mask, account_routing_mask, refundable, network, last4, expired, last_payment_failed_at].hash
349
+ [available_cents, pending_cents, accountholder_name, account_type, bank_name, account_number_mask, account_routing_mask, refundable, network, last4, expired, year, month, last_payment_failed_at, failure_details].hash
320
350
  end
321
351
 
322
352
  # Builds the object from hash
@@ -0,0 +1,225 @@
1
+ =begin
2
+ #API Endpoints
3
+
4
+ #Deliver monetary rewards and incentives to employees, customers, survey participants, and more through the Tremendous API. For organizational tasks, like managing your organization and it's members within Tremendous, please see the Tremendous Organizational API.
5
+
6
+ The version of the OpenAPI document: 2
7
+ Contact: developers@tremendous.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.8.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Tremendous
17
+ class ListFundingSources200ResponseFundingSourcesInnerMetaFailureDetails
18
+ # Payment error code
19
+ attr_accessor :return_code
20
+
21
+ # Explanation of the payment error
22
+ attr_accessor :description
23
+
24
+ # Attribute mapping from ruby-style variable name to JSON key.
25
+ def self.attribute_map
26
+ {
27
+ :'return_code' => :'return_code',
28
+ :'description' => :'description'
29
+ }
30
+ end
31
+
32
+ # Returns all the JSON keys this model knows about
33
+ def self.acceptable_attributes
34
+ attribute_map.values
35
+ end
36
+
37
+ # Attribute type mapping.
38
+ def self.openapi_types
39
+ {
40
+ :'return_code' => :'String',
41
+ :'description' => :'String'
42
+ }
43
+ end
44
+
45
+ # List of attributes with nullable: true
46
+ def self.openapi_nullable
47
+ Set.new([
48
+ ])
49
+ end
50
+
51
+ # Initializes the object
52
+ # @param [Hash] attributes Model attributes in the form of hash
53
+ def initialize(attributes = {})
54
+ if (!attributes.is_a?(Hash))
55
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Tremendous::ListFundingSources200ResponseFundingSourcesInnerMetaFailureDetails` initialize method"
56
+ end
57
+
58
+ # check to see if the attribute exists and convert string to symbol for hash key
59
+ attributes = attributes.each_with_object({}) { |(k, v), h|
60
+ if (!self.class.attribute_map.key?(k.to_sym))
61
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Tremendous::ListFundingSources200ResponseFundingSourcesInnerMetaFailureDetails`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
62
+ end
63
+ h[k.to_sym] = v
64
+ }
65
+
66
+ if attributes.key?(:'return_code')
67
+ self.return_code = attributes[:'return_code']
68
+ end
69
+
70
+ if attributes.key?(:'description')
71
+ self.description = attributes[:'description']
72
+ end
73
+ end
74
+
75
+ # Show invalid properties with the reasons. Usually used together with valid?
76
+ # @return Array for valid properties with the reasons
77
+ def list_invalid_properties
78
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
79
+ invalid_properties = Array.new
80
+ invalid_properties
81
+ end
82
+
83
+ # Check to see if the all the properties in the model are valid
84
+ # @return true if the model is valid
85
+ def valid?
86
+ warn '[DEPRECATED] the `valid?` method is obsolete'
87
+ true
88
+ end
89
+
90
+ # Checks equality by comparing each attribute.
91
+ # @param [Object] Object to be compared
92
+ def ==(o)
93
+ return true if self.equal?(o)
94
+ self.class == o.class &&
95
+ return_code == o.return_code &&
96
+ description == o.description
97
+ end
98
+
99
+ # @see the `==` method
100
+ # @param [Object] Object to be compared
101
+ def eql?(o)
102
+ self == o
103
+ end
104
+
105
+ # Calculates hash code according to all attributes.
106
+ # @return [Integer] Hash code
107
+ def hash
108
+ [return_code, description].hash
109
+ end
110
+
111
+ # Builds the object from hash
112
+ # @param [Hash] attributes Model attributes in the form of hash
113
+ # @return [Object] Returns the model itself
114
+ def self.build_from_hash(attributes)
115
+ return nil unless attributes.is_a?(Hash)
116
+ attributes = attributes.transform_keys(&:to_sym)
117
+ transformed_hash = {}
118
+ openapi_types.each_pair do |key, type|
119
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
120
+ transformed_hash["#{key}"] = nil
121
+ elsif type =~ /\AArray<(.*)>/i
122
+ # check to ensure the input is an array given that the attribute
123
+ # is documented as an array but the input is not
124
+ if attributes[attribute_map[key]].is_a?(Array)
125
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
126
+ end
127
+ elsif !attributes[attribute_map[key]].nil?
128
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
129
+ end
130
+ end
131
+ new(transformed_hash)
132
+ end
133
+
134
+ # Deserializes the data based on type
135
+ # @param string type Data type
136
+ # @param string value Value to be deserialized
137
+ # @return [Object] Deserialized data
138
+ def self._deserialize(type, value)
139
+ case type.to_sym
140
+ when :Time
141
+ Time.parse(value)
142
+ when :Date
143
+ Date.parse(value)
144
+ when :String
145
+ value.to_s
146
+ when :Integer
147
+ value.to_i
148
+ when :Float
149
+ value.to_f
150
+ when :Boolean
151
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
152
+ true
153
+ else
154
+ false
155
+ end
156
+ when :Object
157
+ # generic object (usually a Hash), return directly
158
+ value
159
+ when /\AArray<(?<inner_type>.+)>\z/
160
+ inner_type = Regexp.last_match[:inner_type]
161
+ value.map { |v| _deserialize(inner_type, v) }
162
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
163
+ k_type = Regexp.last_match[:k_type]
164
+ v_type = Regexp.last_match[:v_type]
165
+ {}.tap do |hash|
166
+ value.each do |k, v|
167
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
168
+ end
169
+ end
170
+ else # model
171
+ # models (e.g. Pet) or oneOf
172
+ klass = Tremendous.const_get(type)
173
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
174
+ end
175
+ end
176
+
177
+ # Returns the string representation of the object
178
+ # @return [String] String presentation of the object
179
+ def to_s
180
+ to_hash.to_s
181
+ end
182
+
183
+ # to_body is an alias to to_hash (backward compatibility)
184
+ # @return [Hash] Returns the object in the form of hash
185
+ def to_body
186
+ to_hash
187
+ end
188
+
189
+ # Returns the object in the form of hash
190
+ # @return [Hash] Returns the object in the form of hash
191
+ def to_hash
192
+ hash = {}
193
+ self.class.attribute_map.each_pair do |attr, param|
194
+ value = self.send(attr)
195
+ if value.nil?
196
+ is_nullable = self.class.openapi_nullable.include?(attr)
197
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
198
+ end
199
+
200
+ hash[param] = _to_hash(value)
201
+ end
202
+ hash
203
+ end
204
+
205
+ # Outputs non-array value in the form of hash
206
+ # For object, use to_hash. Otherwise, just return the value
207
+ # @param [Object] value Any valid value
208
+ # @return [Hash] Returns the value in the form of hash
209
+ def _to_hash(value)
210
+ if value.is_a?(Array)
211
+ value.compact.map { |v| _to_hash(v) }
212
+ elsif value.is_a?(Hash)
213
+ {}.tap do |hash|
214
+ value.each { |k, v| hash[k] = _to_hash(v) }
215
+ end
216
+ elsif value.respond_to? :to_hash
217
+ value.to_hash
218
+ else
219
+ value
220
+ end
221
+ end
222
+
223
+ end
224
+
225
+ end