tremendous_ruby 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tremendous/api/tremendous_api.rb +2365 -0
- data/lib/tremendous/api_client.rb +431 -0
- data/lib/tremendous/api_error.rb +58 -0
- data/lib/tremendous/configuration.rb +389 -0
- data/lib/tremendous/models/balance_transaction.rb +256 -0
- data/lib/tremendous/models/campaign.rb +292 -0
- data/lib/tremendous/models/create_api_key200_response.rb +215 -0
- data/lib/tremendous/models/create_invoice.rb +244 -0
- data/lib/tremendous/models/create_invoice200_response.rb +221 -0
- data/lib/tremendous/models/create_invoice_request.rb +244 -0
- data/lib/tremendous/models/create_member.rb +290 -0
- data/lib/tremendous/models/create_member200_response.rb +221 -0
- data/lib/tremendous/models/create_member_request.rb +290 -0
- data/lib/tremendous/models/create_order200_response.rb +221 -0
- data/lib/tremendous/models/create_order200_response_order.rb +400 -0
- data/lib/tremendous/models/create_order200_response_order_rewards_inner.rb +347 -0
- data/lib/tremendous/models/create_order200_response_order_rewards_inner_delivery.rb +296 -0
- data/lib/tremendous/models/create_order201_response.rb +221 -0
- data/lib/tremendous/models/create_order_request.rb +248 -0
- data/lib/tremendous/models/create_order_request_payment.rb +222 -0
- data/lib/tremendous/models/create_order_request_reward.rb +344 -0
- data/lib/tremendous/models/create_order_request_reward_delivery.rb +250 -0
- data/lib/tremendous/models/create_organization.rb +268 -0
- data/lib/tremendous/models/create_organization200_response.rb +214 -0
- data/lib/tremendous/models/create_organization200_response_organization.rb +334 -0
- data/lib/tremendous/models/create_organization_request.rb +268 -0
- data/lib/tremendous/models/create_organization_request_copy_settings.rb +278 -0
- data/lib/tremendous/models/create_webhook200_response.rb +214 -0
- data/lib/tremendous/models/create_webhook_request.rb +222 -0
- data/lib/tremendous/models/currency_codes.rb +154 -0
- data/lib/tremendous/models/custom_field.rb +248 -0
- data/lib/tremendous/models/delivery_details.rb +286 -0
- data/lib/tremendous/models/delivery_details_with_link.rb +296 -0
- data/lib/tremendous/models/delivery_method.rb +41 -0
- data/lib/tremendous/models/delivery_status.rb +42 -0
- data/lib/tremendous/models/error_model.rb +221 -0
- data/lib/tremendous/models/field.rb +286 -0
- data/lib/tremendous/models/funding_source.rb +332 -0
- data/lib/tremendous/models/generate_reward_link200_response.rb +221 -0
- data/lib/tremendous/models/generate_reward_link200_response_reward.rb +247 -0
- data/lib/tremendous/models/generate_reward_link403_response.rb +221 -0
- data/lib/tremendous/models/generate_reward_token200_response.rb +221 -0
- data/lib/tremendous/models/generate_reward_token200_response_reward.rb +257 -0
- data/lib/tremendous/models/get_campaign200_response.rb +221 -0
- data/lib/tremendous/models/get_funding_source200_response.rb +221 -0
- data/lib/tremendous/models/get_member200_response.rb +221 -0
- data/lib/tremendous/models/get_member200_response_member.rb +365 -0
- data/lib/tremendous/models/get_member200_response_member_events_inner.rb +260 -0
- data/lib/tremendous/models/get_organization200_response.rb +214 -0
- data/lib/tremendous/models/get_product200_response.rb +221 -0
- data/lib/tremendous/models/get_product_response.rb +221 -0
- data/lib/tremendous/models/get_reward200_response.rb +221 -0
- data/lib/tremendous/models/invoice.rb +356 -0
- data/lib/tremendous/models/list_balance_transactions200_response.rb +216 -0
- data/lib/tremendous/models/list_balance_transactions200_response_invoices_inner.rb +256 -0
- data/lib/tremendous/models/list_campaigns200_response.rb +223 -0
- data/lib/tremendous/models/list_campaigns200_response_campaigns_inner.rb +292 -0
- data/lib/tremendous/models/list_fields200_response.rb +216 -0
- data/lib/tremendous/models/list_fields200_response_fields_inner.rb +286 -0
- data/lib/tremendous/models/list_funding_sources200_response.rb +223 -0
- data/lib/tremendous/models/list_funding_sources200_response_funding_sources_inner.rb +332 -0
- data/lib/tremendous/models/list_funding_sources200_response_funding_sources_inner_meta.rb +436 -0
- data/lib/tremendous/models/list_invoices200_response.rb +240 -0
- data/lib/tremendous/models/list_invoices200_response_invoices_inner.rb +356 -0
- data/lib/tremendous/models/list_members200_response.rb +223 -0
- data/lib/tremendous/models/list_members200_response_members_inner.rb +374 -0
- data/lib/tremendous/models/list_orders200_response.rb +240 -0
- data/lib/tremendous/models/list_orders200_response_orders_inner.rb +379 -0
- data/lib/tremendous/models/list_orders200_response_orders_inner_payment.rb +346 -0
- data/lib/tremendous/models/list_orders200_response_orders_inner_payment_refund.rb +242 -0
- data/lib/tremendous/models/list_organizations200_response.rb +216 -0
- data/lib/tremendous/models/list_organizations200_response_organizations_inner.rb +324 -0
- data/lib/tremendous/models/list_products200_response.rb +223 -0
- data/lib/tremendous/models/list_products200_response_products_inner.rb +457 -0
- data/lib/tremendous/models/list_products200_response_products_inner_countries_inner.rb +222 -0
- data/lib/tremendous/models/list_products200_response_products_inner_images_inner.rb +273 -0
- data/lib/tremendous/models/list_products200_response_products_inner_skus_inner.rb +277 -0
- data/lib/tremendous/models/list_products_response.rb +223 -0
- data/lib/tremendous/models/list_products_response_products_inner.rb +457 -0
- data/lib/tremendous/models/list_products_response_products_inner_countries_inner.rb +222 -0
- data/lib/tremendous/models/list_products_response_products_inner_images_inner.rb +273 -0
- data/lib/tremendous/models/list_products_response_products_inner_skus_inner.rb +277 -0
- data/lib/tremendous/models/list_rewards200_response.rb +226 -0
- data/lib/tremendous/models/list_rewards200_response_rewards_inner.rb +347 -0
- data/lib/tremendous/models/list_rewards200_response_rewards_inner_custom_fields_inner.rb +248 -0
- data/lib/tremendous/models/list_rewards200_response_rewards_inner_delivery.rb +286 -0
- data/lib/tremendous/models/list_rewards200_response_rewards_inner_recipient.rb +236 -0
- data/lib/tremendous/models/list_rewards200_response_rewards_inner_value.rb +273 -0
- data/lib/tremendous/models/list_rewards401_response.rb +221 -0
- data/lib/tremendous/models/list_rewards401_response_errors.rb +225 -0
- data/lib/tremendous/models/list_rewards429_response.rb +221 -0
- data/lib/tremendous/models/list_webhook_events200_response.rb +216 -0
- data/lib/tremendous/models/list_webhooks200_response.rb +216 -0
- data/lib/tremendous/models/list_webhooks200_response_webhooks_inner.rb +258 -0
- data/lib/tremendous/models/member.rb +374 -0
- data/lib/tremendous/models/member_base.rb +353 -0
- data/lib/tremendous/models/member_with_events.rb +365 -0
- data/lib/tremendous/models/member_without_events.rb +374 -0
- data/lib/tremendous/models/order.rb +379 -0
- data/lib/tremendous/models/order_base.rb +370 -0
- data/lib/tremendous/models/order_base_payment.rb +346 -0
- data/lib/tremendous/models/order_for_create.rb +248 -0
- data/lib/tremendous/models/order_for_create_reward.rb +416 -0
- data/lib/tremendous/models/order_status.rb +44 -0
- data/lib/tremendous/models/order_with_link.rb +400 -0
- data/lib/tremendous/models/order_with_link_rewards_inner.rb +406 -0
- data/lib/tremendous/models/order_without_link.rb +379 -0
- data/lib/tremendous/models/order_without_link_reward.rb +406 -0
- data/lib/tremendous/models/organization.rb +324 -0
- data/lib/tremendous/models/payment_details.rb +345 -0
- data/lib/tremendous/models/payment_details_refund.rb +242 -0
- data/lib/tremendous/models/product.rb +457 -0
- data/lib/tremendous/models/recipient.rb +236 -0
- data/lib/tremendous/models/refund_details.rb +241 -0
- data/lib/tremendous/models/resend_reward422_response.rb +221 -0
- data/lib/tremendous/models/reward.rb +406 -0
- data/lib/tremendous/models/reward_base.rb +397 -0
- data/lib/tremendous/models/reward_base_custom_fields_inner.rb +248 -0
- data/lib/tremendous/models/reward_for_order_create.rb +416 -0
- data/lib/tremendous/models/reward_link.rb +247 -0
- data/lib/tremendous/models/reward_token.rb +257 -0
- data/lib/tremendous/models/reward_value.rb +273 -0
- data/lib/tremendous/models/reward_with_link.rb +406 -0
- data/lib/tremendous/models/reward_with_link_delivery.rb +296 -0
- data/lib/tremendous/models/reward_without_link.rb +406 -0
- data/lib/tremendous/models/reward_without_link_delivery.rb +286 -0
- data/lib/tremendous/models/simulate_webhook_request.rb +222 -0
- data/lib/tremendous/models/webhook.rb +258 -0
- data/lib/tremendous/models/webhook_post.rb +222 -0
- data/lib/tremendous/version.rb +3 -0
- data/lib/tremendous.rb +159 -0
- metadata +133 -10
- data/spec/integration/campaigns_spec.rb +0 -27
- data/spec/integration/funding_sources_spec.rb +0 -18
- data/spec/integration/invoices_spec.rb +0 -19
- data/spec/integration/members_spec.rb +0 -19
- data/spec/integration/orders_spec.rb +0 -53
- data/spec/integration/products_spec.rb +0 -26
- data/spec/spec_helper.rb +0 -111
- data/spec/support/setup.rb +0 -10
@@ -0,0 +1,406 @@
|
|
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
|
+
OpenAPI Generator version: 7.3.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'time'
|
15
|
+
|
16
|
+
module Tremendous
|
17
|
+
# A single reward, sent to a recipient. A reward is always part of an order. Either `products` or `campaign_id` must be specified.
|
18
|
+
class OrderWithoutLinkReward
|
19
|
+
# Tremendous ID of the reward
|
20
|
+
attr_accessor :id
|
21
|
+
|
22
|
+
# Tremendous ID of the order this reward is part of.
|
23
|
+
attr_accessor :order_id
|
24
|
+
|
25
|
+
# Date the reward was created
|
26
|
+
attr_accessor :created_at
|
27
|
+
|
28
|
+
# ID of the campaign in your account, that defines the available products (different gift cards, charity, etc.) that the recipient can choose from.
|
29
|
+
attr_accessor :campaign_id
|
30
|
+
|
31
|
+
# List of IDs of product (different gift cards, charity, etc.) that will be available to the recipient to choose from. Providing a `products` array will override the products made available by the campaign specified using the `campaign_id` property unless the `products` array is empty. It will _not_ override other campaign attributes, like the message and customization of the look and feel.
|
32
|
+
attr_accessor :products
|
33
|
+
|
34
|
+
attr_accessor :value
|
35
|
+
|
36
|
+
attr_accessor :recipient
|
37
|
+
|
38
|
+
# Timestamp of reward delivery within the next year. Note that if date-time is provided, the time values will be ignored.
|
39
|
+
attr_accessor :deliver_at
|
40
|
+
|
41
|
+
attr_accessor :custom_fields
|
42
|
+
|
43
|
+
attr_accessor :delivery
|
44
|
+
|
45
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
46
|
+
def self.attribute_map
|
47
|
+
{
|
48
|
+
:'id' => :'id',
|
49
|
+
:'order_id' => :'order_id',
|
50
|
+
:'created_at' => :'created_at',
|
51
|
+
:'campaign_id' => :'campaign_id',
|
52
|
+
:'products' => :'products',
|
53
|
+
:'value' => :'value',
|
54
|
+
:'recipient' => :'recipient',
|
55
|
+
:'deliver_at' => :'deliver_at',
|
56
|
+
:'custom_fields' => :'custom_fields',
|
57
|
+
:'delivery' => :'delivery'
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns all the JSON keys this model knows about
|
62
|
+
def self.acceptable_attributes
|
63
|
+
attribute_map.values
|
64
|
+
end
|
65
|
+
|
66
|
+
# Attribute type mapping.
|
67
|
+
def self.openapi_types
|
68
|
+
{
|
69
|
+
:'id' => :'String',
|
70
|
+
:'order_id' => :'String',
|
71
|
+
:'created_at' => :'Time',
|
72
|
+
:'campaign_id' => :'String',
|
73
|
+
:'products' => :'Array<String>',
|
74
|
+
:'value' => :'ListRewards200ResponseRewardsInnerValue',
|
75
|
+
:'recipient' => :'ListRewards200ResponseRewardsInnerRecipient',
|
76
|
+
:'deliver_at' => :'Date',
|
77
|
+
:'custom_fields' => :'Array<RewardBaseCustomFieldsInner>',
|
78
|
+
:'delivery' => :'RewardWithoutLinkDelivery'
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
# List of attributes with nullable: true
|
83
|
+
def self.openapi_nullable
|
84
|
+
Set.new([
|
85
|
+
:'campaign_id',
|
86
|
+
])
|
87
|
+
end
|
88
|
+
|
89
|
+
# Initializes the object
|
90
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
91
|
+
def initialize(attributes = {})
|
92
|
+
if (!attributes.is_a?(Hash))
|
93
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `Tremendous::OrderWithoutLinkReward` initialize method"
|
94
|
+
end
|
95
|
+
|
96
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
97
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
98
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
99
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `Tremendous::OrderWithoutLinkReward`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
100
|
+
end
|
101
|
+
h[k.to_sym] = v
|
102
|
+
}
|
103
|
+
|
104
|
+
if attributes.key?(:'id')
|
105
|
+
self.id = attributes[:'id']
|
106
|
+
end
|
107
|
+
|
108
|
+
if attributes.key?(:'order_id')
|
109
|
+
self.order_id = attributes[:'order_id']
|
110
|
+
end
|
111
|
+
|
112
|
+
if attributes.key?(:'created_at')
|
113
|
+
self.created_at = attributes[:'created_at']
|
114
|
+
end
|
115
|
+
|
116
|
+
if attributes.key?(:'campaign_id')
|
117
|
+
self.campaign_id = attributes[:'campaign_id']
|
118
|
+
end
|
119
|
+
|
120
|
+
if attributes.key?(:'products')
|
121
|
+
if (value = attributes[:'products']).is_a?(Array)
|
122
|
+
self.products = value
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
if attributes.key?(:'value')
|
127
|
+
self.value = attributes[:'value']
|
128
|
+
end
|
129
|
+
|
130
|
+
if attributes.key?(:'recipient')
|
131
|
+
self.recipient = attributes[:'recipient']
|
132
|
+
end
|
133
|
+
|
134
|
+
if attributes.key?(:'deliver_at')
|
135
|
+
self.deliver_at = attributes[:'deliver_at']
|
136
|
+
end
|
137
|
+
|
138
|
+
if attributes.key?(:'custom_fields')
|
139
|
+
if (value = attributes[:'custom_fields']).is_a?(Array)
|
140
|
+
self.custom_fields = value
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
if attributes.key?(:'delivery')
|
145
|
+
self.delivery = attributes[:'delivery']
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
150
|
+
# @return Array for valid properties with the reasons
|
151
|
+
def list_invalid_properties
|
152
|
+
warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
|
153
|
+
invalid_properties = Array.new
|
154
|
+
pattern = Regexp.new(/[A-Z0-9]{4,20}/)
|
155
|
+
if !@id.nil? && @id !~ pattern
|
156
|
+
invalid_properties.push("invalid value for \"id\", must conform to the pattern #{pattern}.")
|
157
|
+
end
|
158
|
+
|
159
|
+
pattern = Regexp.new(/[A-Z0-9]{4,20}/)
|
160
|
+
if !@order_id.nil? && @order_id !~ pattern
|
161
|
+
invalid_properties.push("invalid value for \"order_id\", must conform to the pattern #{pattern}.")
|
162
|
+
end
|
163
|
+
|
164
|
+
pattern = Regexp.new(/[A-Z0-9]{4,20}/)
|
165
|
+
if !@campaign_id.nil? && @campaign_id !~ pattern
|
166
|
+
invalid_properties.push("invalid value for \"campaign_id\", must conform to the pattern #{pattern}.")
|
167
|
+
end
|
168
|
+
|
169
|
+
if !@products.nil? && @products.length < 1
|
170
|
+
invalid_properties.push('invalid value for "products", number of items must be greater than or equal to 1.')
|
171
|
+
end
|
172
|
+
|
173
|
+
pattern = Regexp.new(/YYYY-MM-DD/)
|
174
|
+
if !@deliver_at.nil? && @deliver_at !~ pattern
|
175
|
+
invalid_properties.push("invalid value for \"deliver_at\", must conform to the pattern #{pattern}.")
|
176
|
+
end
|
177
|
+
|
178
|
+
invalid_properties
|
179
|
+
end
|
180
|
+
|
181
|
+
# Check to see if the all the properties in the model are valid
|
182
|
+
# @return true if the model is valid
|
183
|
+
def valid?
|
184
|
+
warn '[DEPRECATED] the `valid?` method is obsolete'
|
185
|
+
return false if !@id.nil? && @id !~ Regexp.new(/[A-Z0-9]{4,20}/)
|
186
|
+
return false if !@order_id.nil? && @order_id !~ Regexp.new(/[A-Z0-9]{4,20}/)
|
187
|
+
return false if !@campaign_id.nil? && @campaign_id !~ Regexp.new(/[A-Z0-9]{4,20}/)
|
188
|
+
return false if !@products.nil? && @products.length < 1
|
189
|
+
return false if !@deliver_at.nil? && @deliver_at !~ Regexp.new(/YYYY-MM-DD/)
|
190
|
+
true
|
191
|
+
end
|
192
|
+
|
193
|
+
# Custom attribute writer method with validation
|
194
|
+
# @param [Object] id Value to be assigned
|
195
|
+
def id=(id)
|
196
|
+
if id.nil?
|
197
|
+
fail ArgumentError, 'id cannot be nil'
|
198
|
+
end
|
199
|
+
|
200
|
+
pattern = Regexp.new(/[A-Z0-9]{4,20}/)
|
201
|
+
if id !~ pattern
|
202
|
+
fail ArgumentError, "invalid value for \"id\", must conform to the pattern #{pattern}."
|
203
|
+
end
|
204
|
+
|
205
|
+
@id = id
|
206
|
+
end
|
207
|
+
|
208
|
+
# Custom attribute writer method with validation
|
209
|
+
# @param [Object] order_id Value to be assigned
|
210
|
+
def order_id=(order_id)
|
211
|
+
if order_id.nil?
|
212
|
+
fail ArgumentError, 'order_id cannot be nil'
|
213
|
+
end
|
214
|
+
|
215
|
+
pattern = Regexp.new(/[A-Z0-9]{4,20}/)
|
216
|
+
if order_id !~ pattern
|
217
|
+
fail ArgumentError, "invalid value for \"order_id\", must conform to the pattern #{pattern}."
|
218
|
+
end
|
219
|
+
|
220
|
+
@order_id = order_id
|
221
|
+
end
|
222
|
+
|
223
|
+
# Custom attribute writer method with validation
|
224
|
+
# @param [Object] campaign_id Value to be assigned
|
225
|
+
def campaign_id=(campaign_id)
|
226
|
+
pattern = Regexp.new(/[A-Z0-9]{4,20}/)
|
227
|
+
if !campaign_id.nil? && campaign_id !~ pattern
|
228
|
+
fail ArgumentError, "invalid value for \"campaign_id\", must conform to the pattern #{pattern}."
|
229
|
+
end
|
230
|
+
|
231
|
+
@campaign_id = campaign_id
|
232
|
+
end
|
233
|
+
|
234
|
+
# Custom attribute writer method with validation
|
235
|
+
# @param [Object] products Value to be assigned
|
236
|
+
def products=(products)
|
237
|
+
if products.nil?
|
238
|
+
fail ArgumentError, 'products cannot be nil'
|
239
|
+
end
|
240
|
+
|
241
|
+
if products.length < 1
|
242
|
+
fail ArgumentError, 'invalid value for "products", number of items must be greater than or equal to 1.'
|
243
|
+
end
|
244
|
+
|
245
|
+
@products = products
|
246
|
+
end
|
247
|
+
|
248
|
+
# Custom attribute writer method with validation
|
249
|
+
# @param [Object] deliver_at Value to be assigned
|
250
|
+
def deliver_at=(deliver_at)
|
251
|
+
if deliver_at.nil?
|
252
|
+
fail ArgumentError, 'deliver_at cannot be nil'
|
253
|
+
end
|
254
|
+
|
255
|
+
pattern = Regexp.new(/YYYY-MM-DD/)
|
256
|
+
if deliver_at !~ pattern
|
257
|
+
fail ArgumentError, "invalid value for \"deliver_at\", must conform to the pattern #{pattern}."
|
258
|
+
end
|
259
|
+
|
260
|
+
@deliver_at = deliver_at
|
261
|
+
end
|
262
|
+
|
263
|
+
# Checks equality by comparing each attribute.
|
264
|
+
# @param [Object] Object to be compared
|
265
|
+
def ==(o)
|
266
|
+
return true if self.equal?(o)
|
267
|
+
self.class == o.class &&
|
268
|
+
id == o.id &&
|
269
|
+
order_id == o.order_id &&
|
270
|
+
created_at == o.created_at &&
|
271
|
+
campaign_id == o.campaign_id &&
|
272
|
+
products == o.products &&
|
273
|
+
value == o.value &&
|
274
|
+
recipient == o.recipient &&
|
275
|
+
deliver_at == o.deliver_at &&
|
276
|
+
custom_fields == o.custom_fields &&
|
277
|
+
delivery == o.delivery
|
278
|
+
end
|
279
|
+
|
280
|
+
# @see the `==` method
|
281
|
+
# @param [Object] Object to be compared
|
282
|
+
def eql?(o)
|
283
|
+
self == o
|
284
|
+
end
|
285
|
+
|
286
|
+
# Calculates hash code according to all attributes.
|
287
|
+
# @return [Integer] Hash code
|
288
|
+
def hash
|
289
|
+
[id, order_id, created_at, campaign_id, products, value, recipient, deliver_at, custom_fields, delivery].hash
|
290
|
+
end
|
291
|
+
|
292
|
+
# Builds the object from hash
|
293
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
294
|
+
# @return [Object] Returns the model itself
|
295
|
+
def self.build_from_hash(attributes)
|
296
|
+
return nil unless attributes.is_a?(Hash)
|
297
|
+
attributes = attributes.transform_keys(&:to_sym)
|
298
|
+
transformed_hash = {}
|
299
|
+
openapi_types.each_pair do |key, type|
|
300
|
+
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
|
301
|
+
transformed_hash["#{key}"] = nil
|
302
|
+
elsif type =~ /\AArray<(.*)>/i
|
303
|
+
# check to ensure the input is an array given that the attribute
|
304
|
+
# is documented as an array but the input is not
|
305
|
+
if attributes[attribute_map[key]].is_a?(Array)
|
306
|
+
transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
|
307
|
+
end
|
308
|
+
elsif !attributes[attribute_map[key]].nil?
|
309
|
+
transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
|
310
|
+
end
|
311
|
+
end
|
312
|
+
new(transformed_hash)
|
313
|
+
end
|
314
|
+
|
315
|
+
# Deserializes the data based on type
|
316
|
+
# @param string type Data type
|
317
|
+
# @param string value Value to be deserialized
|
318
|
+
# @return [Object] Deserialized data
|
319
|
+
def self._deserialize(type, value)
|
320
|
+
case type.to_sym
|
321
|
+
when :Time
|
322
|
+
Time.parse(value)
|
323
|
+
when :Date
|
324
|
+
Date.parse(value)
|
325
|
+
when :String
|
326
|
+
value.to_s
|
327
|
+
when :Integer
|
328
|
+
value.to_i
|
329
|
+
when :Float
|
330
|
+
value.to_f
|
331
|
+
when :Boolean
|
332
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
333
|
+
true
|
334
|
+
else
|
335
|
+
false
|
336
|
+
end
|
337
|
+
when :Object
|
338
|
+
# generic object (usually a Hash), return directly
|
339
|
+
value
|
340
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
341
|
+
inner_type = Regexp.last_match[:inner_type]
|
342
|
+
value.map { |v| _deserialize(inner_type, v) }
|
343
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
344
|
+
k_type = Regexp.last_match[:k_type]
|
345
|
+
v_type = Regexp.last_match[:v_type]
|
346
|
+
{}.tap do |hash|
|
347
|
+
value.each do |k, v|
|
348
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
else # model
|
352
|
+
# models (e.g. Pet) or oneOf
|
353
|
+
klass = Tremendous.const_get(type)
|
354
|
+
klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
# Returns the string representation of the object
|
359
|
+
# @return [String] String presentation of the object
|
360
|
+
def to_s
|
361
|
+
to_hash.to_s
|
362
|
+
end
|
363
|
+
|
364
|
+
# to_body is an alias to to_hash (backward compatibility)
|
365
|
+
# @return [Hash] Returns the object in the form of hash
|
366
|
+
def to_body
|
367
|
+
to_hash
|
368
|
+
end
|
369
|
+
|
370
|
+
# Returns the object in the form of hash
|
371
|
+
# @return [Hash] Returns the object in the form of hash
|
372
|
+
def to_hash
|
373
|
+
hash = {}
|
374
|
+
self.class.attribute_map.each_pair do |attr, param|
|
375
|
+
value = self.send(attr)
|
376
|
+
if value.nil?
|
377
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
378
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
379
|
+
end
|
380
|
+
|
381
|
+
hash[param] = _to_hash(value)
|
382
|
+
end
|
383
|
+
hash
|
384
|
+
end
|
385
|
+
|
386
|
+
# Outputs non-array value in the form of hash
|
387
|
+
# For object, use to_hash. Otherwise, just return the value
|
388
|
+
# @param [Object] value Any valid value
|
389
|
+
# @return [Hash] Returns the value in the form of hash
|
390
|
+
def _to_hash(value)
|
391
|
+
if value.is_a?(Array)
|
392
|
+
value.compact.map { |v| _to_hash(v) }
|
393
|
+
elsif value.is_a?(Hash)
|
394
|
+
{}.tap do |hash|
|
395
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
396
|
+
end
|
397
|
+
elsif value.respond_to? :to_hash
|
398
|
+
value.to_hash
|
399
|
+
else
|
400
|
+
value
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
405
|
+
|
406
|
+
end
|