tremendous_ruby 5.1.0 → 5.3.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 (29) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tremendous/api/tremendous_api.rb +538 -13
  3. data/lib/tremendous/models/campaign_base.rb +287 -0
  4. data/lib/tremendous/models/create_member.rb +1 -35
  5. data/lib/tremendous/models/create_member_request.rb +1 -35
  6. data/lib/tremendous/models/create_organization_request_copy_settings.rb +14 -2
  7. data/lib/tremendous/models/create_public_key.rb +222 -0
  8. data/lib/tremendous/models/create_public_key200_response.rb +221 -0
  9. data/lib/tremendous/models/create_public_key_request.rb +222 -0
  10. data/lib/tremendous/models/get_member200_response_member.rb +2 -20
  11. data/lib/tremendous/models/list_forex_response.rb +223 -0
  12. data/lib/tremendous/models/list_members200_response_members_inner.rb +2 -20
  13. data/lib/tremendous/models/list_roles200_response.rb +223 -0
  14. data/lib/tremendous/models/list_roles200_response_roles_inner.rb +275 -0
  15. data/lib/tremendous/models/member.rb +2 -20
  16. data/lib/tremendous/models/member_base.rb +2 -20
  17. data/lib/tremendous/models/member_with_events.rb +2 -20
  18. data/lib/tremendous/models/member_without_events.rb +2 -20
  19. data/lib/tremendous/models/public_key.rb +257 -0
  20. data/lib/tremendous/models/public_keys_response.rb +223 -0
  21. data/lib/tremendous/models/public_keys_response_public_keys_inner.rb +257 -0
  22. data/lib/tremendous/models/role.rb +275 -0
  23. data/lib/tremendous/models/test_public_key.rb +222 -0
  24. data/lib/tremendous/models/test_public_key_request.rb +222 -0
  25. data/lib/tremendous/models/update_campaign.rb +287 -0
  26. data/lib/tremendous/models/update_campaign_request.rb +257 -0
  27. data/lib/tremendous/version.rb +1 -1
  28. data/lib/tremendous.rb +15 -0
  29. metadata +18 -3
@@ -0,0 +1,287 @@
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
+ # With a campaign you can define the look & feel of how rewards are sent out. It also lets you set the available products (different gift cards, charity, etc.) recipients can choose from.
18
+ class CampaignBase
19
+ attr_accessor :id
20
+
21
+ # Name of the campaign
22
+ attr_accessor :name
23
+
24
+ # Description of the campaign
25
+ attr_accessor :description
26
+
27
+ # List of IDs of products (different gift cards, charity, etc.) that are available in this campaign.
28
+ attr_accessor :products
29
+
30
+ attr_accessor :webpage_style
31
+
32
+ attr_accessor :email_style
33
+
34
+ # Attribute mapping from ruby-style variable name to JSON key.
35
+ def self.attribute_map
36
+ {
37
+ :'id' => :'id',
38
+ :'name' => :'name',
39
+ :'description' => :'description',
40
+ :'products' => :'products',
41
+ :'webpage_style' => :'webpage_style',
42
+ :'email_style' => :'email_style'
43
+ }
44
+ end
45
+
46
+ # Returns all the JSON keys this model knows about
47
+ def self.acceptable_attributes
48
+ attribute_map.values
49
+ end
50
+
51
+ # Attribute type mapping.
52
+ def self.openapi_types
53
+ {
54
+ :'id' => :'String',
55
+ :'name' => :'String',
56
+ :'description' => :'String',
57
+ :'products' => :'Array<String>',
58
+ :'webpage_style' => :'ListCampaigns200ResponseCampaignsInnerWebpageStyle',
59
+ :'email_style' => :'ListCampaigns200ResponseCampaignsInnerEmailStyle'
60
+ }
61
+ end
62
+
63
+ # List of attributes with nullable: true
64
+ def self.openapi_nullable
65
+ Set.new([
66
+ :'description',
67
+ ])
68
+ end
69
+
70
+ # Initializes the object
71
+ # @param [Hash] attributes Model attributes in the form of hash
72
+ def initialize(attributes = {})
73
+ if (!attributes.is_a?(Hash))
74
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Tremendous::CampaignBase` initialize method"
75
+ end
76
+
77
+ # check to see if the attribute exists and convert string to symbol for hash key
78
+ attributes = attributes.each_with_object({}) { |(k, v), h|
79
+ if (!self.class.attribute_map.key?(k.to_sym))
80
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Tremendous::CampaignBase`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
81
+ end
82
+ h[k.to_sym] = v
83
+ }
84
+
85
+ if attributes.key?(:'id')
86
+ self.id = attributes[:'id']
87
+ end
88
+
89
+ if attributes.key?(:'name')
90
+ self.name = attributes[:'name']
91
+ end
92
+
93
+ if attributes.key?(:'description')
94
+ self.description = attributes[:'description']
95
+ end
96
+
97
+ if attributes.key?(:'products')
98
+ if (value = attributes[:'products']).is_a?(Array)
99
+ self.products = value
100
+ end
101
+ end
102
+
103
+ if attributes.key?(:'webpage_style')
104
+ self.webpage_style = attributes[:'webpage_style']
105
+ end
106
+
107
+ if attributes.key?(:'email_style')
108
+ self.email_style = attributes[:'email_style']
109
+ end
110
+ end
111
+
112
+ # Show invalid properties with the reasons. Usually used together with valid?
113
+ # @return Array for valid properties with the reasons
114
+ def list_invalid_properties
115
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
116
+ invalid_properties = Array.new
117
+ pattern = Regexp.new(/[A-Z0-9]{4,20}/)
118
+ if !@id.nil? && @id !~ pattern
119
+ invalid_properties.push("invalid value for \"id\", must conform to the pattern #{pattern}.")
120
+ end
121
+
122
+ invalid_properties
123
+ end
124
+
125
+ # Check to see if the all the properties in the model are valid
126
+ # @return true if the model is valid
127
+ def valid?
128
+ warn '[DEPRECATED] the `valid?` method is obsolete'
129
+ return false if !@id.nil? && @id !~ Regexp.new(/[A-Z0-9]{4,20}/)
130
+ true
131
+ end
132
+
133
+ # Custom attribute writer method with validation
134
+ # @param [Object] id Value to be assigned
135
+ def id=(id)
136
+ if id.nil?
137
+ fail ArgumentError, 'id cannot be nil'
138
+ end
139
+
140
+ pattern = Regexp.new(/[A-Z0-9]{4,20}/)
141
+ if id !~ pattern
142
+ fail ArgumentError, "invalid value for \"id\", must conform to the pattern #{pattern}."
143
+ end
144
+
145
+ @id = id
146
+ end
147
+
148
+ # Checks equality by comparing each attribute.
149
+ # @param [Object] Object to be compared
150
+ def ==(o)
151
+ return true if self.equal?(o)
152
+ self.class == o.class &&
153
+ id == o.id &&
154
+ name == o.name &&
155
+ description == o.description &&
156
+ products == o.products &&
157
+ webpage_style == o.webpage_style &&
158
+ email_style == o.email_style
159
+ end
160
+
161
+ # @see the `==` method
162
+ # @param [Object] Object to be compared
163
+ def eql?(o)
164
+ self == o
165
+ end
166
+
167
+ # Calculates hash code according to all attributes.
168
+ # @return [Integer] Hash code
169
+ def hash
170
+ [id, name, description, products, webpage_style, email_style].hash
171
+ end
172
+
173
+ # Builds the object from hash
174
+ # @param [Hash] attributes Model attributes in the form of hash
175
+ # @return [Object] Returns the model itself
176
+ def self.build_from_hash(attributes)
177
+ return nil unless attributes.is_a?(Hash)
178
+ attributes = attributes.transform_keys(&:to_sym)
179
+ transformed_hash = {}
180
+ openapi_types.each_pair do |key, type|
181
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
182
+ transformed_hash["#{key}"] = nil
183
+ elsif type =~ /\AArray<(.*)>/i
184
+ # check to ensure the input is an array given that the attribute
185
+ # is documented as an array but the input is not
186
+ if attributes[attribute_map[key]].is_a?(Array)
187
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
188
+ end
189
+ elsif !attributes[attribute_map[key]].nil?
190
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
191
+ end
192
+ end
193
+ new(transformed_hash)
194
+ end
195
+
196
+ # Deserializes the data based on type
197
+ # @param string type Data type
198
+ # @param string value Value to be deserialized
199
+ # @return [Object] Deserialized data
200
+ def self._deserialize(type, value)
201
+ case type.to_sym
202
+ when :Time
203
+ Time.parse(value)
204
+ when :Date
205
+ Date.parse(value)
206
+ when :String
207
+ value.to_s
208
+ when :Integer
209
+ value.to_i
210
+ when :Float
211
+ value.to_f
212
+ when :Boolean
213
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
214
+ true
215
+ else
216
+ false
217
+ end
218
+ when :Object
219
+ # generic object (usually a Hash), return directly
220
+ value
221
+ when /\AArray<(?<inner_type>.+)>\z/
222
+ inner_type = Regexp.last_match[:inner_type]
223
+ value.map { |v| _deserialize(inner_type, v) }
224
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
225
+ k_type = Regexp.last_match[:k_type]
226
+ v_type = Regexp.last_match[:v_type]
227
+ {}.tap do |hash|
228
+ value.each do |k, v|
229
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
230
+ end
231
+ end
232
+ else # model
233
+ # models (e.g. Pet) or oneOf
234
+ klass = Tremendous.const_get(type)
235
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
236
+ end
237
+ end
238
+
239
+ # Returns the string representation of the object
240
+ # @return [String] String presentation of the object
241
+ def to_s
242
+ to_hash.to_s
243
+ end
244
+
245
+ # to_body is an alias to to_hash (backward compatibility)
246
+ # @return [Hash] Returns the object in the form of hash
247
+ def to_body
248
+ to_hash
249
+ end
250
+
251
+ # Returns the object in the form of hash
252
+ # @return [Hash] Returns the object in the form of hash
253
+ def to_hash
254
+ hash = {}
255
+ self.class.attribute_map.each_pair do |attr, param|
256
+ value = self.send(attr)
257
+ if value.nil?
258
+ is_nullable = self.class.openapi_nullable.include?(attr)
259
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
260
+ end
261
+
262
+ hash[param] = _to_hash(value)
263
+ end
264
+ hash
265
+ end
266
+
267
+ # Outputs non-array value in the form of hash
268
+ # For object, use to_hash. Otherwise, just return the value
269
+ # @param [Object] value Any valid value
270
+ # @return [Hash] Returns the value in the form of hash
271
+ def _to_hash(value)
272
+ if value.is_a?(Array)
273
+ value.compact.map { |v| _to_hash(v) }
274
+ elsif value.is_a?(Hash)
275
+ {}.tap do |hash|
276
+ value.each { |k, v| hash[k] = _to_hash(v) }
277
+ end
278
+ elsif value.respond_to? :to_hash
279
+ value.to_hash
280
+ else
281
+ value
282
+ end
283
+ end
284
+
285
+ end
286
+
287
+ end
@@ -18,31 +18,9 @@ module Tremendous
18
18
  # Email address of the member
19
19
  attr_accessor :email
20
20
 
21
- # Role of the member within the organization. <table> <thead> <tr> <th>Role</th> <th>Description</th> </tr> </thead> <tr> <td><code>MEMBER</code></td> <td>Limited permissions. Can view their own reward and order histories only.</td> </tr> <tr> <td><code>ADMIN</code></td> <td>Update organization settings, invite other members to the organization, and view all member order and reward histories within their organization.</td> </tr> <tbody> </table>
21
+ # The role ID of the member within the organization.
22
22
  attr_accessor :role
23
23
 
24
- class EnumAttributeValidator
25
- attr_reader :datatype
26
- attr_reader :allowable_values
27
-
28
- def initialize(datatype, allowable_values)
29
- @allowable_values = allowable_values.map do |value|
30
- case datatype.to_s
31
- when /Integer/i
32
- value.to_i
33
- when /Float/i
34
- value.to_f
35
- else
36
- value
37
- end
38
- end
39
- end
40
-
41
- def valid?(value)
42
- !value || allowable_values.include?(value)
43
- end
44
- end
45
-
46
24
  # Attribute mapping from ruby-style variable name to JSON key.
47
25
  def self.attribute_map
48
26
  {
@@ -120,21 +98,9 @@ module Tremendous
120
98
  warn '[DEPRECATED] the `valid?` method is obsolete'
121
99
  return false if @email.nil?
122
100
  return false if @role.nil?
123
- role_validator = EnumAttributeValidator.new('String', ["MEMBER", "ADMIN"])
124
- return false unless role_validator.valid?(@role)
125
101
  true
126
102
  end
127
103
 
128
- # Custom attribute writer method checking allowed values (enum).
129
- # @param [Object] role Object to be assigned
130
- def role=(role)
131
- validator = EnumAttributeValidator.new('String', ["MEMBER", "ADMIN"])
132
- unless validator.valid?(role)
133
- fail ArgumentError, "invalid value for \"role\", must be one of #{validator.allowable_values}."
134
- end
135
- @role = role
136
- end
137
-
138
104
  # Checks equality by comparing each attribute.
139
105
  # @param [Object] Object to be compared
140
106
  def ==(o)
@@ -18,31 +18,9 @@ module Tremendous
18
18
  # Email address of the member
19
19
  attr_accessor :email
20
20
 
21
- # Role of the member within the organization. <table> <thead> <tr> <th>Role</th> <th>Description</th> </tr> </thead> <tr> <td><code>MEMBER</code></td> <td>Limited permissions. Can view their own reward and order histories only.</td> </tr> <tr> <td><code>ADMIN</code></td> <td>Update organization settings, invite other members to the organization, and view all member order and reward histories within their organization.</td> </tr> <tbody> </table>
21
+ # The role ID of the member within the organization.
22
22
  attr_accessor :role
23
23
 
24
- class EnumAttributeValidator
25
- attr_reader :datatype
26
- attr_reader :allowable_values
27
-
28
- def initialize(datatype, allowable_values)
29
- @allowable_values = allowable_values.map do |value|
30
- case datatype.to_s
31
- when /Integer/i
32
- value.to_i
33
- when /Float/i
34
- value.to_f
35
- else
36
- value
37
- end
38
- end
39
- end
40
-
41
- def valid?(value)
42
- !value || allowable_values.include?(value)
43
- end
44
- end
45
-
46
24
  # Attribute mapping from ruby-style variable name to JSON key.
47
25
  def self.attribute_map
48
26
  {
@@ -120,21 +98,9 @@ module Tremendous
120
98
  warn '[DEPRECATED] the `valid?` method is obsolete'
121
99
  return false if @email.nil?
122
100
  return false if @role.nil?
123
- role_validator = EnumAttributeValidator.new('String', ["MEMBER", "ADMIN"])
124
- return false unless role_validator.valid?(@role)
125
101
  true
126
102
  end
127
103
 
128
- # Custom attribute writer method checking allowed values (enum).
129
- # @param [Object] role Object to be assigned
130
- def role=(role)
131
- validator = EnumAttributeValidator.new('String', ["MEMBER", "ADMIN"])
132
- unless validator.valid?(role)
133
- fail ArgumentError, "invalid value for \"role\", must be one of #{validator.allowable_values}."
134
- end
135
- @role = role
136
- end
137
-
138
104
  # Checks equality by comparing each attribute.
139
105
  # @param [Object] Object to be compared
140
106
  def ==(o)
@@ -31,9 +31,12 @@ module Tremendous
31
31
  # Copy over the security settings from the current organization to the new organization. Defaults to `true`.
32
32
  attr_accessor :security_settings
33
33
 
34
- # Copy over the users from the current organization to the new organization. Defaults to `false`.
34
+ # Copy over the users and custom roles from the current organization to the new organization. Defaults to `false`.
35
35
  attr_accessor :users
36
36
 
37
+ # Copy over the custom roles from the current organization to the new organization. Custom roles are always copied if `users` is `true`. Defaults to `false`.
38
+ attr_accessor :custom_roles
39
+
37
40
  # Copy over the fraud prevention settings and rules from the current organization to the new organization. Defaults to `false`.
38
41
  attr_accessor :fraud_prevention
39
42
 
@@ -46,6 +49,7 @@ module Tremendous
46
49
  :'payment_methods' => :'payment_methods',
47
50
  :'security_settings' => :'security_settings',
48
51
  :'users' => :'users',
52
+ :'custom_roles' => :'custom_roles',
49
53
  :'fraud_prevention' => :'fraud_prevention'
50
54
  }
51
55
  end
@@ -64,6 +68,7 @@ module Tremendous
64
68
  :'payment_methods' => :'Boolean',
65
69
  :'security_settings' => :'Boolean',
66
70
  :'users' => :'Boolean',
71
+ :'custom_roles' => :'Boolean',
67
72
  :'fraud_prevention' => :'Boolean'
68
73
  }
69
74
  end
@@ -125,6 +130,12 @@ module Tremendous
125
130
  self.users = false
126
131
  end
127
132
 
133
+ if attributes.key?(:'custom_roles')
134
+ self.custom_roles = attributes[:'custom_roles']
135
+ else
136
+ self.custom_roles = false
137
+ end
138
+
128
139
  if attributes.key?(:'fraud_prevention')
129
140
  self.fraud_prevention = attributes[:'fraud_prevention']
130
141
  else
@@ -158,6 +169,7 @@ module Tremendous
158
169
  payment_methods == o.payment_methods &&
159
170
  security_settings == o.security_settings &&
160
171
  users == o.users &&
172
+ custom_roles == o.custom_roles &&
161
173
  fraud_prevention == o.fraud_prevention
162
174
  end
163
175
 
@@ -170,7 +182,7 @@ module Tremendous
170
182
  # Calculates hash code according to all attributes.
171
183
  # @return [Integer] Hash code
172
184
  def hash
173
- [campaigns, custom_fields, order_approvals, payment_methods, security_settings, users, fraud_prevention].hash
185
+ [campaigns, custom_fields, order_approvals, payment_methods, security_settings, users, custom_roles, fraud_prevention].hash
174
186
  end
175
187
 
176
188
  # Builds the object from hash
@@ -0,0 +1,222 @@
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
+ class CreatePublicKey
18
+ # Base64 encoded (public) PEM file
19
+ attr_accessor :public_key
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'public_key' => :'public_key'
25
+ }
26
+ end
27
+
28
+ # Returns all the JSON keys this model knows about
29
+ def self.acceptable_attributes
30
+ attribute_map.values
31
+ end
32
+
33
+ # Attribute type mapping.
34
+ def self.openapi_types
35
+ {
36
+ :'public_key' => :'String'
37
+ }
38
+ end
39
+
40
+ # List of attributes with nullable: true
41
+ def self.openapi_nullable
42
+ Set.new([
43
+ ])
44
+ end
45
+
46
+ # Initializes the object
47
+ # @param [Hash] attributes Model attributes in the form of hash
48
+ def initialize(attributes = {})
49
+ if (!attributes.is_a?(Hash))
50
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Tremendous::CreatePublicKey` initialize method"
51
+ end
52
+
53
+ # check to see if the attribute exists and convert string to symbol for hash key
54
+ attributes = attributes.each_with_object({}) { |(k, v), h|
55
+ if (!self.class.attribute_map.key?(k.to_sym))
56
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Tremendous::CreatePublicKey`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
57
+ end
58
+ h[k.to_sym] = v
59
+ }
60
+
61
+ if attributes.key?(:'public_key')
62
+ self.public_key = attributes[:'public_key']
63
+ else
64
+ self.public_key = nil
65
+ end
66
+ end
67
+
68
+ # Show invalid properties with the reasons. Usually used together with valid?
69
+ # @return Array for valid properties with the reasons
70
+ def list_invalid_properties
71
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
72
+ invalid_properties = Array.new
73
+ if @public_key.nil?
74
+ invalid_properties.push('invalid value for "public_key", public_key cannot be nil.')
75
+ end
76
+
77
+ invalid_properties
78
+ end
79
+
80
+ # Check to see if the all the properties in the model are valid
81
+ # @return true if the model is valid
82
+ def valid?
83
+ warn '[DEPRECATED] the `valid?` method is obsolete'
84
+ return false if @public_key.nil?
85
+ true
86
+ end
87
+
88
+ # Checks equality by comparing each attribute.
89
+ # @param [Object] Object to be compared
90
+ def ==(o)
91
+ return true if self.equal?(o)
92
+ self.class == o.class &&
93
+ public_key == o.public_key
94
+ end
95
+
96
+ # @see the `==` method
97
+ # @param [Object] Object to be compared
98
+ def eql?(o)
99
+ self == o
100
+ end
101
+
102
+ # Calculates hash code according to all attributes.
103
+ # @return [Integer] Hash code
104
+ def hash
105
+ [public_key].hash
106
+ end
107
+
108
+ # Builds the object from hash
109
+ # @param [Hash] attributes Model attributes in the form of hash
110
+ # @return [Object] Returns the model itself
111
+ def self.build_from_hash(attributes)
112
+ return nil unless attributes.is_a?(Hash)
113
+ attributes = attributes.transform_keys(&:to_sym)
114
+ transformed_hash = {}
115
+ openapi_types.each_pair do |key, type|
116
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
117
+ transformed_hash["#{key}"] = nil
118
+ elsif type =~ /\AArray<(.*)>/i
119
+ # check to ensure the input is an array given that the attribute
120
+ # is documented as an array but the input is not
121
+ if attributes[attribute_map[key]].is_a?(Array)
122
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
123
+ end
124
+ elsif !attributes[attribute_map[key]].nil?
125
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
126
+ end
127
+ end
128
+ new(transformed_hash)
129
+ end
130
+
131
+ # Deserializes the data based on type
132
+ # @param string type Data type
133
+ # @param string value Value to be deserialized
134
+ # @return [Object] Deserialized data
135
+ def self._deserialize(type, value)
136
+ case type.to_sym
137
+ when :Time
138
+ Time.parse(value)
139
+ when :Date
140
+ Date.parse(value)
141
+ when :String
142
+ value.to_s
143
+ when :Integer
144
+ value.to_i
145
+ when :Float
146
+ value.to_f
147
+ when :Boolean
148
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
149
+ true
150
+ else
151
+ false
152
+ end
153
+ when :Object
154
+ # generic object (usually a Hash), return directly
155
+ value
156
+ when /\AArray<(?<inner_type>.+)>\z/
157
+ inner_type = Regexp.last_match[:inner_type]
158
+ value.map { |v| _deserialize(inner_type, v) }
159
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
160
+ k_type = Regexp.last_match[:k_type]
161
+ v_type = Regexp.last_match[:v_type]
162
+ {}.tap do |hash|
163
+ value.each do |k, v|
164
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
165
+ end
166
+ end
167
+ else # model
168
+ # models (e.g. Pet) or oneOf
169
+ klass = Tremendous.const_get(type)
170
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
171
+ end
172
+ end
173
+
174
+ # Returns the string representation of the object
175
+ # @return [String] String presentation of the object
176
+ def to_s
177
+ to_hash.to_s
178
+ end
179
+
180
+ # to_body is an alias to to_hash (backward compatibility)
181
+ # @return [Hash] Returns the object in the form of hash
182
+ def to_body
183
+ to_hash
184
+ end
185
+
186
+ # Returns the object in the form of hash
187
+ # @return [Hash] Returns the object in the form of hash
188
+ def to_hash
189
+ hash = {}
190
+ self.class.attribute_map.each_pair do |attr, param|
191
+ value = self.send(attr)
192
+ if value.nil?
193
+ is_nullable = self.class.openapi_nullable.include?(attr)
194
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
195
+ end
196
+
197
+ hash[param] = _to_hash(value)
198
+ end
199
+ hash
200
+ end
201
+
202
+ # Outputs non-array value in the form of hash
203
+ # For object, use to_hash. Otherwise, just return the value
204
+ # @param [Object] value Any valid value
205
+ # @return [Hash] Returns the value in the form of hash
206
+ def _to_hash(value)
207
+ if value.is_a?(Array)
208
+ value.compact.map { |v| _to_hash(v) }
209
+ elsif value.is_a?(Hash)
210
+ {}.tap do |hash|
211
+ value.each { |k, v| hash[k] = _to_hash(v) }
212
+ end
213
+ elsif value.respond_to? :to_hash
214
+ value.to_hash
215
+ else
216
+ value
217
+ end
218
+ end
219
+
220
+ end
221
+
222
+ end