smooch-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/README.md +181 -0
  4. data/Rakefile +8 -0
  5. data/docs/Action.md +16 -0
  6. data/docs/App.md +10 -0
  7. data/docs/AppApi.md +609 -0
  8. data/docs/AppCreate.md +8 -0
  9. data/docs/AppResponse.md +8 -0
  10. data/docs/AppUser.md +18 -0
  11. data/docs/AppUserApi.md +561 -0
  12. data/docs/AppUserLink.md +9 -0
  13. data/docs/AppUserPreCreate.md +14 -0
  14. data/docs/AppUserResponse.md +8 -0
  15. data/docs/AppUserUpdate.md +12 -0
  16. data/docs/Client.md +14 -0
  17. data/docs/ClientInfo.md +15 -0
  18. data/docs/Conversation.md +9 -0
  19. data/docs/ConversationApi.md +282 -0
  20. data/docs/Destination.md +9 -0
  21. data/docs/DeviceInit.md +12 -0
  22. data/docs/DeviceResponse.md +8 -0
  23. data/docs/DeviceUpdate.md +10 -0
  24. data/docs/DisplaySettings.md +8 -0
  25. data/docs/Event.md +8 -0
  26. data/docs/GetMessagesResponse.md +10 -0
  27. data/docs/Init.md +9 -0
  28. data/docs/InitApi.md +61 -0
  29. data/docs/InitResponse.md +9 -0
  30. data/docs/Integration.md +24 -0
  31. data/docs/IntegrationApi.md +121 -0
  32. data/docs/IntegrationCreate.md +23 -0
  33. data/docs/IntegrationResponse.md +8 -0
  34. data/docs/JwtResponse.md +8 -0
  35. data/docs/ListAppsResponse.md +10 -0
  36. data/docs/ListIntegrationsResponse.md +8 -0
  37. data/docs/ListSecretKeysResponse.md +8 -0
  38. data/docs/ListWebhooksResponse.md +8 -0
  39. data/docs/Menu.md +9 -0
  40. data/docs/MenuApi.md +155 -0
  41. data/docs/MenuItem.md +11 -0
  42. data/docs/MenuResponse.md +8 -0
  43. data/docs/Message.md +23 -0
  44. data/docs/MessageItem.md +13 -0
  45. data/docs/MessagePost.md +20 -0
  46. data/docs/MessageResponse.md +9 -0
  47. data/docs/PostMessagesResponse.md +9 -0
  48. data/docs/SecretKey.md +10 -0
  49. data/docs/SecretKeyCreate.md +8 -0
  50. data/docs/SecretKeyResponse.md +8 -0
  51. data/docs/TrackEventResponse.md +8 -0
  52. data/docs/TypingActivityTrigger.md +11 -0
  53. data/docs/Webhook.md +11 -0
  54. data/docs/WebhookApi.md +287 -0
  55. data/docs/WebhookCreate.md +9 -0
  56. data/docs/WebhookResponse.md +8 -0
  57. data/docs/WebhookUpdate.md +9 -0
  58. data/git_push.sh +55 -0
  59. data/lib/smooch-api.rb +91 -0
  60. data/lib/smooch-api/api/app_api.rb +628 -0
  61. data/lib/smooch-api/api/app_user_api.rb +585 -0
  62. data/lib/smooch-api/api/conversation_api.rb +298 -0
  63. data/lib/smooch-api/api/init_api.rb +75 -0
  64. data/lib/smooch-api/api/integration_api.rb +135 -0
  65. data/lib/smooch-api/api/menu_api.rb +173 -0
  66. data/lib/smooch-api/api/webhook_api.rb +306 -0
  67. data/lib/smooch-api/api_client.rb +376 -0
  68. data/lib/smooch-api/api_error.rb +37 -0
  69. data/lib/smooch-api/configuration.rb +202 -0
  70. data/lib/smooch-api/models/action.rb +311 -0
  71. data/lib/smooch-api/models/app.rb +223 -0
  72. data/lib/smooch-api/models/app_create.rb +193 -0
  73. data/lib/smooch-api/models/app_response.rb +188 -0
  74. data/lib/smooch-api/models/app_user.rb +307 -0
  75. data/lib/smooch-api/models/app_user_link.rb +236 -0
  76. data/lib/smooch-api/models/app_user_pre_create.rb +253 -0
  77. data/lib/smooch-api/models/app_user_response.rb +193 -0
  78. data/lib/smooch-api/models/app_user_update.rb +228 -0
  79. data/lib/smooch-api/models/client.rb +290 -0
  80. data/lib/smooch-api/models/client_info.rb +258 -0
  81. data/lib/smooch-api/models/conversation.rb +208 -0
  82. data/lib/smooch-api/models/destination.rb +208 -0
  83. data/lib/smooch-api/models/device_init.rb +270 -0
  84. data/lib/smooch-api/models/device_response.rb +188 -0
  85. data/lib/smooch-api/models/device_update.rb +207 -0
  86. data/lib/smooch-api/models/display_settings.rb +188 -0
  87. data/lib/smooch-api/models/event.rb +193 -0
  88. data/lib/smooch-api/models/get_messages_response.rb +210 -0
  89. data/lib/smooch-api/models/init.rb +202 -0
  90. data/lib/smooch-api/models/init_response.rb +208 -0
  91. data/lib/smooch-api/models/integration.rb +358 -0
  92. data/lib/smooch-api/models/integration_create.rb +343 -0
  93. data/lib/smooch-api/models/integration_response.rb +188 -0
  94. data/lib/smooch-api/models/jwt_response.rb +188 -0
  95. data/lib/smooch-api/models/list_apps_response.rb +210 -0
  96. data/lib/smooch-api/models/list_integrations_response.rb +190 -0
  97. data/lib/smooch-api/models/list_secret_keys_response.rb +190 -0
  98. data/lib/smooch-api/models/list_webhooks_response.rb +195 -0
  99. data/lib/smooch-api/models/menu.rb +205 -0
  100. data/lib/smooch-api/models/menu_item.rb +228 -0
  101. data/lib/smooch-api/models/menu_response.rb +193 -0
  102. data/lib/smooch-api/models/message.rb +415 -0
  103. data/lib/smooch-api/models/message_item.rb +250 -0
  104. data/lib/smooch-api/models/message_post.rb +355 -0
  105. data/lib/smooch-api/models/message_response.rb +208 -0
  106. data/lib/smooch-api/models/post_messages_response.rb +200 -0
  107. data/lib/smooch-api/models/secret_key.rb +223 -0
  108. data/lib/smooch-api/models/secret_key_create.rb +193 -0
  109. data/lib/smooch-api/models/secret_key_response.rb +188 -0
  110. data/lib/smooch-api/models/track_event_response.rb +188 -0
  111. data/lib/smooch-api/models/typing_activity_trigger.rb +228 -0
  112. data/lib/smooch-api/models/webhook.rb +261 -0
  113. data/lib/smooch-api/models/webhook_create.rb +226 -0
  114. data/lib/smooch-api/models/webhook_response.rb +193 -0
  115. data/lib/smooch-api/models/webhook_update.rb +221 -0
  116. data/lib/smooch-api/version.rb +14 -0
  117. data/smooch-api.gemspec +44 -0
  118. data/spec/api_client_spec.rb +225 -0
  119. data/spec/configuration_spec.rb +41 -0
  120. data/spec/spec_helper.rb +110 -0
  121. metadata +349 -0
@@ -0,0 +1,250 @@
1
+ =begin
2
+ #Smooch
3
+
4
+ #The Smooch API is a unified interface for powering messaging in your customer experiences across every channel. Our API speeds access to new markets, reduces time to ship, eliminates complexity, and helps you build the best experiences for your customers. For more information, visit our [official documentation](https://docs.smooch.io).
5
+
6
+ OpenAPI spec version: 1
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ =end
11
+
12
+ require 'date'
13
+
14
+ module SmoochApi
15
+
16
+ class MessageItem
17
+ # The title of the message item.
18
+ attr_accessor :title
19
+
20
+ # The text description, or subtitle.
21
+ attr_accessor :description
22
+
23
+ # The image URL to be shown in the carousel/list item.
24
+ attr_accessor :media_url
25
+
26
+ # The size of the image to be shown in the carousel/list item. Only top item of Facebook Messenger carousel supported. Choose from *compact* and *large*.
27
+ attr_accessor :size
28
+
29
+ # If a *mediaUrl* was specified, the media type is defined here, for example *image/jpeg*.
30
+ attr_accessor :media_type
31
+
32
+ # Array of [action buttons](https://docs.smooch.io/rest/#action-buttons). At least 1 is required, a maximum of 3 are allowed.
33
+ attr_accessor :actions
34
+
35
+
36
+ # Attribute mapping from ruby-style variable name to JSON key.
37
+ def self.attribute_map
38
+ {
39
+ :'title' => :'title',
40
+ :'description' => :'description',
41
+ :'media_url' => :'mediaUrl',
42
+ :'size' => :'size',
43
+ :'media_type' => :'mediaType',
44
+ :'actions' => :'actions'
45
+ }
46
+ end
47
+
48
+ # Attribute type mapping.
49
+ def self.swagger_types
50
+ {
51
+ :'title' => :'String',
52
+ :'description' => :'String',
53
+ :'media_url' => :'String',
54
+ :'size' => :'String',
55
+ :'media_type' => :'String',
56
+ :'actions' => :'Array<Action>'
57
+ }
58
+ end
59
+
60
+ # Initializes the object
61
+ # @param [Hash] attributes Model attributes in the form of hash
62
+ def initialize(attributes = {})
63
+ return unless attributes.is_a?(Hash)
64
+
65
+ # convert string to symbol for hash key
66
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
67
+
68
+ if attributes.has_key?(:'title')
69
+ self.title = attributes[:'title']
70
+ end
71
+
72
+ if attributes.has_key?(:'description')
73
+ self.description = attributes[:'description']
74
+ end
75
+
76
+ if attributes.has_key?(:'mediaUrl')
77
+ self.media_url = attributes[:'mediaUrl']
78
+ end
79
+
80
+ if attributes.has_key?(:'size')
81
+ self.size = attributes[:'size']
82
+ end
83
+
84
+ if attributes.has_key?(:'mediaType')
85
+ self.media_type = attributes[:'mediaType']
86
+ end
87
+
88
+ if attributes.has_key?(:'actions')
89
+ if (value = attributes[:'actions']).is_a?(Array)
90
+ self.actions = value
91
+ end
92
+ end
93
+
94
+ end
95
+
96
+ # Show invalid properties with the reasons. Usually used together with valid?
97
+ # @return Array for valid properies with the reasons
98
+ def list_invalid_properties
99
+ invalid_properties = Array.new
100
+ if @title.nil?
101
+ invalid_properties.push("invalid value for 'title', title cannot be nil.")
102
+ end
103
+
104
+ if @actions.nil?
105
+ invalid_properties.push("invalid value for 'actions', actions cannot be nil.")
106
+ end
107
+
108
+ return invalid_properties
109
+ end
110
+
111
+ # Check to see if the all the properties in the model are valid
112
+ # @return true if the model is valid
113
+ def valid?
114
+ return false if @title.nil?
115
+ return false if @actions.nil?
116
+ return true
117
+ end
118
+
119
+ # Checks equality by comparing each attribute.
120
+ # @param [Object] Object to be compared
121
+ def ==(o)
122
+ return true if self.equal?(o)
123
+ self.class == o.class &&
124
+ title == o.title &&
125
+ description == o.description &&
126
+ media_url == o.media_url &&
127
+ size == o.size &&
128
+ media_type == o.media_type &&
129
+ actions == o.actions
130
+ end
131
+
132
+ # @see the `==` method
133
+ # @param [Object] Object to be compared
134
+ def eql?(o)
135
+ self == o
136
+ end
137
+
138
+ # Calculates hash code according to all attributes.
139
+ # @return [Fixnum] Hash code
140
+ def hash
141
+ [title, description, media_url, size, media_type, actions].hash
142
+ end
143
+
144
+ # Builds the object from hash
145
+ # @param [Hash] attributes Model attributes in the form of hash
146
+ # @return [Object] Returns the model itself
147
+ def build_from_hash(attributes)
148
+ return nil unless attributes.is_a?(Hash)
149
+ self.class.swagger_types.each_pair do |key, type|
150
+ if type =~ /\AArray<(.*)>/i
151
+ # check to ensure the input is an array given that the the attribute
152
+ # is documented as an array but the input is not
153
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
154
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
155
+ end
156
+ elsif !attributes[self.class.attribute_map[key]].nil?
157
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
158
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
159
+ end
160
+
161
+ self
162
+ end
163
+
164
+ # Deserializes the data based on type
165
+ # @param string type Data type
166
+ # @param string value Value to be deserialized
167
+ # @return [Object] Deserialized data
168
+ def _deserialize(type, value)
169
+ case type.to_sym
170
+ when :DateTime
171
+ DateTime.parse(value)
172
+ when :Date
173
+ Date.parse(value)
174
+ when :String
175
+ value.to_s
176
+ when :Integer
177
+ value.to_i
178
+ when :Float
179
+ value.to_f
180
+ when :BOOLEAN
181
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
182
+ true
183
+ else
184
+ false
185
+ end
186
+ when :Object
187
+ # generic object (usually a Hash), return directly
188
+ value
189
+ when /\AArray<(?<inner_type>.+)>\z/
190
+ inner_type = Regexp.last_match[:inner_type]
191
+ value.map { |v| _deserialize(inner_type, v) }
192
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
193
+ k_type = Regexp.last_match[:k_type]
194
+ v_type = Regexp.last_match[:v_type]
195
+ {}.tap do |hash|
196
+ value.each do |k, v|
197
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
198
+ end
199
+ end
200
+ else # model
201
+ temp_model = SmoochApi.const_get(type).new
202
+ temp_model.build_from_hash(value)
203
+ end
204
+ end
205
+
206
+ # Returns the string representation of the object
207
+ # @return [String] String presentation of the object
208
+ def to_s
209
+ to_hash.to_s
210
+ end
211
+
212
+ # to_body is an alias to to_hash (backward compatibility)
213
+ # @return [Hash] Returns the object in the form of hash
214
+ def to_body
215
+ to_hash
216
+ end
217
+
218
+ # Returns the object in the form of hash
219
+ # @return [Hash] Returns the object in the form of hash
220
+ def to_hash
221
+ hash = {}
222
+ self.class.attribute_map.each_pair do |attr, param|
223
+ value = self.send(attr)
224
+ next if value.nil?
225
+ hash[param] = _to_hash(value)
226
+ end
227
+ hash
228
+ end
229
+
230
+ # Outputs non-array value in the form of hash
231
+ # For object, use to_hash. Otherwise, just return the value
232
+ # @param [Object] value Any valid value
233
+ # @return [Hash] Returns the value in the form of hash
234
+ def _to_hash(value)
235
+ if value.is_a?(Array)
236
+ value.compact.map{ |v| _to_hash(v) }
237
+ elsif value.is_a?(Hash)
238
+ {}.tap do |hash|
239
+ value.each { |k, v| hash[k] = _to_hash(v) }
240
+ end
241
+ elsif value.respond_to? :to_hash
242
+ value.to_hash
243
+ else
244
+ value
245
+ end
246
+ end
247
+
248
+ end
249
+
250
+ end
@@ -0,0 +1,355 @@
1
+ =begin
2
+ #Smooch
3
+
4
+ #The Smooch API is a unified interface for powering messaging in your customer experiences across every channel. Our API speeds access to new markets, reduces time to ship, eliminates complexity, and helps you build the best experiences for your customers. For more information, visit our [official documentation](https://docs.smooch.io).
5
+
6
+ OpenAPI spec version: 1
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+
10
+ =end
11
+
12
+ require 'date'
13
+
14
+ module SmoochApi
15
+
16
+ class MessagePost
17
+ # The role of the individual posting the message. Can be either *appUser* or *appMaker*.
18
+ attr_accessor :role
19
+
20
+ # The message type.
21
+ attr_accessor :type
22
+
23
+ # The display name of the message author.
24
+ attr_accessor :name
25
+
26
+ # The email address of the message author.
27
+ attr_accessor :email
28
+
29
+ # The URL of the desired message avatar image.
30
+ attr_accessor :avatar_url
31
+
32
+ # Flat JSON object containing any custom properties associated with the message.
33
+ attr_accessor :metadata
34
+
35
+ # The payload of a reply action, if applicable.
36
+ attr_accessor :payload
37
+
38
+ # The message text. Required for text messages.
39
+ attr_accessor :text
40
+
41
+ # The mediaUrl for the image. Required for image messages.
42
+ attr_accessor :media_url
43
+
44
+ # The mediaType for the image. Required for image messages.
45
+ attr_accessor :media_type
46
+
47
+ # The items in the message list. Required for carousel and list messages.
48
+ attr_accessor :items
49
+
50
+ # The actions in the message.
51
+ attr_accessor :actions
52
+
53
+ # Specifies which channel to deliver a message to. See [list integrations](https://docs.smooch.io/rest/#list-integrations) to get integration ID and type.
54
+ attr_accessor :destination
55
+
56
+ class EnumAttributeValidator
57
+ attr_reader :datatype
58
+ attr_reader :allowable_values
59
+
60
+ def initialize(datatype, allowable_values)
61
+ @allowable_values = allowable_values.map do |value|
62
+ case datatype.to_s
63
+ when /Integer/i
64
+ value.to_i
65
+ when /Float/i
66
+ value.to_f
67
+ else
68
+ value
69
+ end
70
+ end
71
+ end
72
+
73
+ def valid?(value)
74
+ !value || allowable_values.include?(value)
75
+ end
76
+ end
77
+
78
+ # Attribute mapping from ruby-style variable name to JSON key.
79
+ def self.attribute_map
80
+ {
81
+ :'role' => :'role',
82
+ :'type' => :'type',
83
+ :'name' => :'name',
84
+ :'email' => :'email',
85
+ :'avatar_url' => :'avatarUrl',
86
+ :'metadata' => :'metadata',
87
+ :'payload' => :'payload',
88
+ :'text' => :'text',
89
+ :'media_url' => :'mediaUrl',
90
+ :'media_type' => :'mediaType',
91
+ :'items' => :'items',
92
+ :'actions' => :'actions',
93
+ :'destination' => :'destination'
94
+ }
95
+ end
96
+
97
+ # Attribute type mapping.
98
+ def self.swagger_types
99
+ {
100
+ :'role' => :'String',
101
+ :'type' => :'String',
102
+ :'name' => :'String',
103
+ :'email' => :'String',
104
+ :'avatar_url' => :'String',
105
+ :'metadata' => :'Object',
106
+ :'payload' => :'String',
107
+ :'text' => :'String',
108
+ :'media_url' => :'String',
109
+ :'media_type' => :'String',
110
+ :'items' => :'Array<MessageItem>',
111
+ :'actions' => :'Array<Action>',
112
+ :'destination' => :'Destination'
113
+ }
114
+ end
115
+
116
+ # Initializes the object
117
+ # @param [Hash] attributes Model attributes in the form of hash
118
+ def initialize(attributes = {})
119
+ return unless attributes.is_a?(Hash)
120
+
121
+ # convert string to symbol for hash key
122
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
123
+
124
+ if attributes.has_key?(:'role')
125
+ self.role = attributes[:'role']
126
+ end
127
+
128
+ if attributes.has_key?(:'type')
129
+ self.type = attributes[:'type']
130
+ end
131
+
132
+ if attributes.has_key?(:'name')
133
+ self.name = attributes[:'name']
134
+ end
135
+
136
+ if attributes.has_key?(:'email')
137
+ self.email = attributes[:'email']
138
+ end
139
+
140
+ if attributes.has_key?(:'avatarUrl')
141
+ self.avatar_url = attributes[:'avatarUrl']
142
+ end
143
+
144
+ if attributes.has_key?(:'metadata')
145
+ self.metadata = attributes[:'metadata']
146
+ end
147
+
148
+ if attributes.has_key?(:'payload')
149
+ self.payload = attributes[:'payload']
150
+ end
151
+
152
+ if attributes.has_key?(:'text')
153
+ self.text = attributes[:'text']
154
+ end
155
+
156
+ if attributes.has_key?(:'mediaUrl')
157
+ self.media_url = attributes[:'mediaUrl']
158
+ end
159
+
160
+ if attributes.has_key?(:'mediaType')
161
+ self.media_type = attributes[:'mediaType']
162
+ end
163
+
164
+ if attributes.has_key?(:'items')
165
+ if (value = attributes[:'items']).is_a?(Array)
166
+ self.items = value
167
+ end
168
+ end
169
+
170
+ if attributes.has_key?(:'actions')
171
+ if (value = attributes[:'actions']).is_a?(Array)
172
+ self.actions = value
173
+ end
174
+ end
175
+
176
+ if attributes.has_key?(:'destination')
177
+ self.destination = attributes[:'destination']
178
+ end
179
+
180
+ end
181
+
182
+ # Show invalid properties with the reasons. Usually used together with valid?
183
+ # @return Array for valid properies with the reasons
184
+ def list_invalid_properties
185
+ invalid_properties = Array.new
186
+ if @role.nil?
187
+ invalid_properties.push("invalid value for 'role', role cannot be nil.")
188
+ end
189
+
190
+ if @type.nil?
191
+ invalid_properties.push("invalid value for 'type', type cannot be nil.")
192
+ end
193
+
194
+ return invalid_properties
195
+ end
196
+
197
+ # Check to see if the all the properties in the model are valid
198
+ # @return true if the model is valid
199
+ def valid?
200
+ return false if @role.nil?
201
+ return false if @type.nil?
202
+ type_validator = EnumAttributeValidator.new('String', ["text", "image", "carousel", "list"])
203
+ return false unless type_validator.valid?(@type)
204
+ return true
205
+ end
206
+
207
+ # Custom attribute writer method checking allowed values (enum).
208
+ # @param [Object] type Object to be assigned
209
+ def type=(type)
210
+ validator = EnumAttributeValidator.new('String', ["text", "image", "carousel", "list"])
211
+ unless validator.valid?(type)
212
+ fail ArgumentError, "invalid value for 'type', must be one of #{validator.allowable_values}."
213
+ end
214
+ @type = type
215
+ end
216
+
217
+ # Checks equality by comparing each attribute.
218
+ # @param [Object] Object to be compared
219
+ def ==(o)
220
+ return true if self.equal?(o)
221
+ self.class == o.class &&
222
+ role == o.role &&
223
+ type == o.type &&
224
+ name == o.name &&
225
+ email == o.email &&
226
+ avatar_url == o.avatar_url &&
227
+ metadata == o.metadata &&
228
+ payload == o.payload &&
229
+ text == o.text &&
230
+ media_url == o.media_url &&
231
+ media_type == o.media_type &&
232
+ items == o.items &&
233
+ actions == o.actions &&
234
+ destination == o.destination
235
+ end
236
+
237
+ # @see the `==` method
238
+ # @param [Object] Object to be compared
239
+ def eql?(o)
240
+ self == o
241
+ end
242
+
243
+ # Calculates hash code according to all attributes.
244
+ # @return [Fixnum] Hash code
245
+ def hash
246
+ [role, type, name, email, avatar_url, metadata, payload, text, media_url, media_type, items, actions, destination].hash
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.swagger_types.each_pair do |key, type|
255
+ if type =~ /\AArray<(.*)>/i
256
+ # check to ensure the input is an array given that the 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
+ temp_model = SmoochApi.const_get(type).new
307
+ temp_model.build_from_hash(value)
308
+ end
309
+ end
310
+
311
+ # Returns the string representation of the object
312
+ # @return [String] String presentation of the object
313
+ def to_s
314
+ to_hash.to_s
315
+ end
316
+
317
+ # to_body is an alias to to_hash (backward compatibility)
318
+ # @return [Hash] Returns the object in the form of hash
319
+ def to_body
320
+ to_hash
321
+ end
322
+
323
+ # Returns the object in the form of hash
324
+ # @return [Hash] Returns the object in the form of hash
325
+ def to_hash
326
+ hash = {}
327
+ self.class.attribute_map.each_pair do |attr, param|
328
+ value = self.send(attr)
329
+ next if value.nil?
330
+ hash[param] = _to_hash(value)
331
+ end
332
+ hash
333
+ end
334
+
335
+ # Outputs non-array value in the form of hash
336
+ # For object, use to_hash. Otherwise, just return the value
337
+ # @param [Object] value Any valid value
338
+ # @return [Hash] Returns the value in the form of hash
339
+ def _to_hash(value)
340
+ if value.is_a?(Array)
341
+ value.compact.map{ |v| _to_hash(v) }
342
+ elsif value.is_a?(Hash)
343
+ {}.tap do |hash|
344
+ value.each { |k, v| hash[k] = _to_hash(v) }
345
+ end
346
+ elsif value.respond_to? :to_hash
347
+ value.to_hash
348
+ else
349
+ value
350
+ end
351
+ end
352
+
353
+ end
354
+
355
+ end