activitysmith 0.1.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.
Files changed (30) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +116 -0
  4. data/generated/activitysmith_openapi/api/live_activities_api.rb +226 -0
  5. data/generated/activitysmith_openapi/api/push_notifications_api.rb +90 -0
  6. data/generated/activitysmith_openapi/api_client.rb +394 -0
  7. data/generated/activitysmith_openapi/api_error.rb +58 -0
  8. data/generated/activitysmith_openapi/configuration.rb +309 -0
  9. data/generated/activitysmith_openapi/models/content_state_end.rb +393 -0
  10. data/generated/activitysmith_openapi/models/content_state_start.rb +397 -0
  11. data/generated/activitysmith_openapi/models/content_state_update.rb +362 -0
  12. data/generated/activitysmith_openapi/models/live_activity_end_request.rb +237 -0
  13. data/generated/activitysmith_openapi/models/live_activity_end_response.rb +271 -0
  14. data/generated/activitysmith_openapi/models/live_activity_limit_error.rb +270 -0
  15. data/generated/activitysmith_openapi/models/live_activity_start_request.rb +221 -0
  16. data/generated/activitysmith_openapi/models/live_activity_start_response.rb +271 -0
  17. data/generated/activitysmith_openapi/models/live_activity_update_request.rb +237 -0
  18. data/generated/activitysmith_openapi/models/live_activity_update_response.rb +271 -0
  19. data/generated/activitysmith_openapi/models/push_notification_request.rb +239 -0
  20. data/generated/activitysmith_openapi/models/push_notification_response.rb +255 -0
  21. data/generated/activitysmith_openapi/models/rate_limit_error.rb +237 -0
  22. data/generated/activitysmith_openapi/models/send_push_notification429_response.rb +105 -0
  23. data/generated/activitysmith_openapi/version.rb +15 -0
  24. data/generated/activitysmith_openapi.rb +55 -0
  25. data/lib/activitysmith/client.rb +47 -0
  26. data/lib/activitysmith/live_activities.rb +44 -0
  27. data/lib/activitysmith/notifications.rb +28 -0
  28. data/lib/activitysmith/version.rb +5 -0
  29. data/lib/activitysmith.rb +6 -0
  30. metadata +129 -0
@@ -0,0 +1,309 @@
1
+ =begin
2
+ #ActivitySmith API
3
+
4
+ #Send push notifications and Live Activities to your own devices via a single API key.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.7.0
10
+
11
+ =end
12
+
13
+ module OpenapiClient
14
+ class Configuration
15
+ # Defines url scheme
16
+ attr_accessor :scheme
17
+
18
+ # Defines url host
19
+ attr_accessor :host
20
+
21
+ # Defines url base path
22
+ attr_accessor :base_path
23
+
24
+ # Define server configuration index
25
+ attr_accessor :server_index
26
+
27
+ # Define server operation configuration index
28
+ attr_accessor :server_operation_index
29
+
30
+ # Default server variables
31
+ attr_accessor :server_variables
32
+
33
+ # Default server operation variables
34
+ attr_accessor :server_operation_variables
35
+
36
+ # Defines API keys used with API Key authentications.
37
+ #
38
+ # @return [Hash] key: parameter name, value: parameter value (API key)
39
+ #
40
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
41
+ # config.api_key['api_key'] = 'xxx'
42
+ attr_accessor :api_key
43
+
44
+ # Defines API key prefixes used with API Key authentications.
45
+ #
46
+ # @return [Hash] key: parameter name, value: API key prefix
47
+ #
48
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
49
+ # config.api_key_prefix['api_key'] = 'Token'
50
+ attr_accessor :api_key_prefix
51
+
52
+ # Defines the username used with HTTP basic authentication.
53
+ #
54
+ # @return [String]
55
+ attr_accessor :username
56
+
57
+ # Defines the password used with HTTP basic authentication.
58
+ #
59
+ # @return [String]
60
+ attr_accessor :password
61
+
62
+ # Defines the access token (Bearer) used with OAuth2.
63
+ attr_accessor :access_token
64
+
65
+ # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
66
+ # Overrides the access_token if set
67
+ # @return [Proc]
68
+ attr_accessor :access_token_getter
69
+
70
+ # Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
71
+ # HTTP responses with return type `File` will be returned as a stream of binary data.
72
+ # Default to false.
73
+ attr_accessor :return_binary_data
74
+
75
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
76
+ # details will be logged with `logger.debug` (see the `logger` attribute).
77
+ # Default to false.
78
+ #
79
+ # @return [true, false]
80
+ attr_accessor :debugging
81
+
82
+ # Set this to ignore operation servers for the API client. This is useful when you need to
83
+ # send requests to a different server than the one specified in the OpenAPI document.
84
+ # Will default to the base url defined in the spec but can be overridden by setting
85
+ # `scheme`, `host`, `base_path` directly.
86
+ # Default to false.
87
+ # @return [true, false]
88
+ attr_accessor :ignore_operation_servers
89
+
90
+ # Defines the logger used for debugging.
91
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
92
+ #
93
+ # @return [#debug]
94
+ attr_accessor :logger
95
+
96
+ # Defines the temporary folder to store downloaded files
97
+ # (for API endpoints that have file response).
98
+ # Default to use `Tempfile`.
99
+ #
100
+ # @return [String]
101
+ attr_accessor :temp_folder_path
102
+
103
+ # The time limit for HTTP request in seconds.
104
+ # Default to 0 (never times out).
105
+ attr_accessor :timeout
106
+
107
+ # Set this to false to skip client side validation in the operation.
108
+ # Default to true.
109
+ # @return [true, false]
110
+ attr_accessor :client_side_validation
111
+
112
+ ### TLS/SSL setting
113
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
114
+ # Default to true.
115
+ #
116
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
117
+ #
118
+ # @return [true, false]
119
+ attr_accessor :verify_ssl
120
+
121
+ ### TLS/SSL setting
122
+ # Set this to false to skip verifying SSL host name
123
+ # Default to true.
124
+ #
125
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
126
+ #
127
+ # @return [true, false]
128
+ attr_accessor :verify_ssl_host
129
+
130
+ ### TLS/SSL setting
131
+ # Set this to customize the certificate file to verify the peer.
132
+ #
133
+ # @return [String] the path to the certificate file
134
+ #
135
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
136
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
137
+ attr_accessor :ssl_ca_cert
138
+
139
+ ### TLS/SSL setting
140
+ # Client certificate file (for client certificate)
141
+ attr_accessor :cert_file
142
+
143
+ ### TLS/SSL setting
144
+ # Client private key file (for client certificate)
145
+ attr_accessor :key_file
146
+
147
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
148
+ # Default to nil.
149
+ #
150
+ # @see The params_encoding option of Ethon. Related source code:
151
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
152
+ attr_accessor :params_encoding
153
+
154
+
155
+ attr_accessor :inject_format
156
+
157
+ attr_accessor :force_ending_format
158
+
159
+ def initialize
160
+ @scheme = 'https'
161
+ @host = 'activitysmith.com'
162
+ @base_path = '/api'
163
+ @server_index = nil
164
+ @server_operation_index = {}
165
+ @server_variables = {}
166
+ @server_operation_variables = {}
167
+ @api_key = {}
168
+ @api_key_prefix = {}
169
+ @client_side_validation = true
170
+ @verify_ssl = true
171
+ @verify_ssl_host = true
172
+ @cert_file = nil
173
+ @key_file = nil
174
+ @timeout = 0
175
+ @params_encoding = nil
176
+ @debugging = false
177
+ @ignore_operation_servers = false
178
+ @inject_format = false
179
+ @force_ending_format = false
180
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
181
+
182
+ yield(self) if block_given?
183
+ end
184
+
185
+ # The default Configuration object.
186
+ def self.default
187
+ @@default ||= Configuration.new
188
+ end
189
+
190
+ def configure
191
+ yield(self) if block_given?
192
+ end
193
+
194
+ def scheme=(scheme)
195
+ # remove :// from scheme
196
+ @scheme = scheme.sub(/:\/\//, '')
197
+ end
198
+
199
+ def host=(host)
200
+ # remove http(s):// and anything after a slash
201
+ @host = host.sub(/https?:\/\//, '').split('/').first
202
+ end
203
+
204
+ def base_path=(base_path)
205
+ # Add leading and trailing slashes to base_path
206
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
207
+ @base_path = '' if @base_path == '/'
208
+ end
209
+
210
+ # Returns base URL for specified operation based on server settings
211
+ def base_url(operation = nil)
212
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
213
+ if operation_server_settings.key?(operation) then
214
+ index = server_operation_index.fetch(operation, server_index)
215
+ server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
216
+ else
217
+ server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
218
+ end
219
+ end
220
+
221
+ # Gets API key (with prefix if set).
222
+ # @param [String] param_name the parameter name of API key auth
223
+ def api_key_with_prefix(param_name, param_alias = nil)
224
+ key = @api_key[param_name]
225
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
226
+ if @api_key_prefix[param_name]
227
+ "#{@api_key_prefix[param_name]} #{key}"
228
+ else
229
+ key
230
+ end
231
+ end
232
+
233
+ # Gets access_token using access_token_getter or uses the static access_token
234
+ def access_token_with_refresh
235
+ return access_token if access_token_getter.nil?
236
+ access_token_getter.call
237
+ end
238
+
239
+ # Gets Basic Auth token string
240
+ def basic_auth_token
241
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
242
+ end
243
+
244
+ # Returns Auth Settings hash for api client.
245
+ def auth_settings
246
+ {
247
+ 'apiKeyAuth' =>
248
+ {
249
+ type: 'bearer',
250
+ in: 'header',
251
+ format: 'API Key',
252
+ key: 'Authorization',
253
+ value: "Bearer #{access_token_with_refresh}"
254
+ },
255
+ }
256
+ end
257
+
258
+ # Returns an array of Server setting
259
+ def server_settings
260
+ [
261
+ {
262
+ url: "https://activitysmith.com/api",
263
+ description: "No description provided",
264
+ }
265
+ ]
266
+ end
267
+
268
+ def operation_server_settings
269
+ {
270
+ }
271
+ end
272
+
273
+ # Returns URL based on server settings
274
+ #
275
+ # @param index array index of the server settings
276
+ # @param variables hash of variable and the corresponding value
277
+ def server_url(index, variables = {}, servers = nil)
278
+ servers = server_settings if servers == nil
279
+
280
+ # check array index out of bound
281
+ if (index.nil? || index < 0 || index >= servers.size)
282
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
283
+ end
284
+
285
+ server = servers[index]
286
+ url = server[:url]
287
+
288
+ return url unless server.key? :variables
289
+
290
+ # go through variable and assign a value
291
+ server[:variables].each do |name, variable|
292
+ if variables.key?(name)
293
+ if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
294
+ url.gsub! "{" + name.to_s + "}", variables[name]
295
+ else
296
+ fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
297
+ end
298
+ else
299
+ # use default value
300
+ url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
301
+ end
302
+ end
303
+
304
+ url
305
+ end
306
+
307
+
308
+ end
309
+ end
@@ -0,0 +1,393 @@
1
+ =begin
2
+ #ActivitySmith API
3
+
4
+ #Send push notifications and Live Activities to your own devices via a single API key.
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.7.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module OpenapiClient
17
+ # End payload. Required fields are title and current_step. number_of_steps is optional.
18
+ class ContentStateEnd
19
+ attr_accessor :title
20
+
21
+ attr_accessor :subtitle
22
+
23
+ attr_accessor :number_of_steps
24
+
25
+ attr_accessor :current_step
26
+
27
+ # Optional. Accent color for the Live Activity. Defaults to blue.
28
+ attr_accessor :color
29
+
30
+ # Optional. Overrides color for the current step.
31
+ attr_accessor :step_color
32
+
33
+ # Optional. Minutes before the ended Live Activity is dismissed. Default 3. Set 0 for immediate dismissal. iOS will dismiss ended Live Activities after ~4 hours max.
34
+ attr_accessor :auto_dismiss_minutes
35
+
36
+ class EnumAttributeValidator
37
+ attr_reader :datatype
38
+ attr_reader :allowable_values
39
+
40
+ def initialize(datatype, allowable_values)
41
+ @allowable_values = allowable_values.map do |value|
42
+ case datatype.to_s
43
+ when /Integer/i
44
+ value.to_i
45
+ when /Float/i
46
+ value.to_f
47
+ else
48
+ value
49
+ end
50
+ end
51
+ end
52
+
53
+ def valid?(value)
54
+ !value || allowable_values.include?(value)
55
+ end
56
+ end
57
+
58
+ # Attribute mapping from ruby-style variable name to JSON key.
59
+ def self.attribute_map
60
+ {
61
+ :'title' => :'title',
62
+ :'subtitle' => :'subtitle',
63
+ :'number_of_steps' => :'number_of_steps',
64
+ :'current_step' => :'current_step',
65
+ :'color' => :'color',
66
+ :'step_color' => :'step_color',
67
+ :'auto_dismiss_minutes' => :'auto_dismiss_minutes'
68
+ }
69
+ end
70
+
71
+ # Returns all the JSON keys this model knows about
72
+ def self.acceptable_attributes
73
+ attribute_map.values
74
+ end
75
+
76
+ # Attribute type mapping.
77
+ def self.openapi_types
78
+ {
79
+ :'title' => :'String',
80
+ :'subtitle' => :'String',
81
+ :'number_of_steps' => :'Integer',
82
+ :'current_step' => :'Integer',
83
+ :'color' => :'String',
84
+ :'step_color' => :'String',
85
+ :'auto_dismiss_minutes' => :'Integer'
86
+ }
87
+ end
88
+
89
+ # List of attributes with nullable: true
90
+ def self.openapi_nullable
91
+ Set.new([
92
+ ])
93
+ end
94
+
95
+ # Initializes the object
96
+ # @param [Hash] attributes Model attributes in the form of hash
97
+ def initialize(attributes = {})
98
+ if (!attributes.is_a?(Hash))
99
+ fail ArgumentError, "The input argument (attributes) must be a hash in `OpenapiClient::ContentStateEnd` initialize method"
100
+ end
101
+
102
+ # check to see if the attribute exists and convert string to symbol for hash key
103
+ attributes = attributes.each_with_object({}) { |(k, v), h|
104
+ if (!self.class.attribute_map.key?(k.to_sym))
105
+ fail ArgumentError, "`#{k}` is not a valid attribute in `OpenapiClient::ContentStateEnd`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
106
+ end
107
+ h[k.to_sym] = v
108
+ }
109
+
110
+ if attributes.key?(:'title')
111
+ self.title = attributes[:'title']
112
+ else
113
+ self.title = nil
114
+ end
115
+
116
+ if attributes.key?(:'subtitle')
117
+ self.subtitle = attributes[:'subtitle']
118
+ end
119
+
120
+ if attributes.key?(:'number_of_steps')
121
+ self.number_of_steps = attributes[:'number_of_steps']
122
+ end
123
+
124
+ if attributes.key?(:'current_step')
125
+ self.current_step = attributes[:'current_step']
126
+ else
127
+ self.current_step = nil
128
+ end
129
+
130
+ if attributes.key?(:'color')
131
+ self.color = attributes[:'color']
132
+ else
133
+ self.color = 'blue'
134
+ end
135
+
136
+ if attributes.key?(:'step_color')
137
+ self.step_color = attributes[:'step_color']
138
+ end
139
+
140
+ if attributes.key?(:'auto_dismiss_minutes')
141
+ self.auto_dismiss_minutes = attributes[:'auto_dismiss_minutes']
142
+ else
143
+ self.auto_dismiss_minutes = 3
144
+ end
145
+ end
146
+
147
+ # Show invalid properties with the reasons. Usually used together with valid?
148
+ # @return Array for valid properties with the reasons
149
+ def list_invalid_properties
150
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
151
+ invalid_properties = Array.new
152
+ if @title.nil?
153
+ invalid_properties.push('invalid value for "title", title cannot be nil.')
154
+ end
155
+
156
+ if !@number_of_steps.nil? && @number_of_steps < 1
157
+ invalid_properties.push('invalid value for "number_of_steps", must be greater than or equal to 1.')
158
+ end
159
+
160
+ if @current_step.nil?
161
+ invalid_properties.push('invalid value for "current_step", current_step cannot be nil.')
162
+ end
163
+
164
+ if @current_step < 1
165
+ invalid_properties.push('invalid value for "current_step", must be greater than or equal to 1.')
166
+ end
167
+
168
+ if !@auto_dismiss_minutes.nil? && @auto_dismiss_minutes < 0
169
+ invalid_properties.push('invalid value for "auto_dismiss_minutes", must be greater than or equal to 0.')
170
+ end
171
+
172
+ invalid_properties
173
+ end
174
+
175
+ # Check to see if the all the properties in the model are valid
176
+ # @return true if the model is valid
177
+ def valid?
178
+ warn '[DEPRECATED] the `valid?` method is obsolete'
179
+ return false if @title.nil?
180
+ return false if !@number_of_steps.nil? && @number_of_steps < 1
181
+ return false if @current_step.nil?
182
+ return false if @current_step < 1
183
+ color_validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"])
184
+ return false unless color_validator.valid?(@color)
185
+ step_color_validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"])
186
+ return false unless step_color_validator.valid?(@step_color)
187
+ return false if !@auto_dismiss_minutes.nil? && @auto_dismiss_minutes < 0
188
+ true
189
+ end
190
+
191
+ # Custom attribute writer method with validation
192
+ # @param [Object] number_of_steps Value to be assigned
193
+ def number_of_steps=(number_of_steps)
194
+ if number_of_steps.nil?
195
+ fail ArgumentError, 'number_of_steps cannot be nil'
196
+ end
197
+
198
+ if number_of_steps < 1
199
+ fail ArgumentError, 'invalid value for "number_of_steps", must be greater than or equal to 1.'
200
+ end
201
+
202
+ @number_of_steps = number_of_steps
203
+ end
204
+
205
+ # Custom attribute writer method with validation
206
+ # @param [Object] current_step Value to be assigned
207
+ def current_step=(current_step)
208
+ if current_step.nil?
209
+ fail ArgumentError, 'current_step cannot be nil'
210
+ end
211
+
212
+ if current_step < 1
213
+ fail ArgumentError, 'invalid value for "current_step", must be greater than or equal to 1.'
214
+ end
215
+
216
+ @current_step = current_step
217
+ end
218
+
219
+ # Custom attribute writer method checking allowed values (enum).
220
+ # @param [Object] color Object to be assigned
221
+ def color=(color)
222
+ validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"])
223
+ unless validator.valid?(color)
224
+ fail ArgumentError, "invalid value for \"color\", must be one of #{validator.allowable_values}."
225
+ end
226
+ @color = color
227
+ end
228
+
229
+ # Custom attribute writer method checking allowed values (enum).
230
+ # @param [Object] step_color Object to be assigned
231
+ def step_color=(step_color)
232
+ validator = EnumAttributeValidator.new('String', ["lime", "green", "cyan", "blue", "purple", "magenta", "red", "orange", "yellow"])
233
+ unless validator.valid?(step_color)
234
+ fail ArgumentError, "invalid value for \"step_color\", must be one of #{validator.allowable_values}."
235
+ end
236
+ @step_color = step_color
237
+ end
238
+
239
+ # Custom attribute writer method with validation
240
+ # @param [Object] auto_dismiss_minutes Value to be assigned
241
+ def auto_dismiss_minutes=(auto_dismiss_minutes)
242
+ if auto_dismiss_minutes.nil?
243
+ fail ArgumentError, 'auto_dismiss_minutes cannot be nil'
244
+ end
245
+
246
+ if auto_dismiss_minutes < 0
247
+ fail ArgumentError, 'invalid value for "auto_dismiss_minutes", must be greater than or equal to 0.'
248
+ end
249
+
250
+ @auto_dismiss_minutes = auto_dismiss_minutes
251
+ end
252
+
253
+ # Checks equality by comparing each attribute.
254
+ # @param [Object] Object to be compared
255
+ def ==(o)
256
+ return true if self.equal?(o)
257
+ self.class == o.class &&
258
+ title == o.title &&
259
+ subtitle == o.subtitle &&
260
+ number_of_steps == o.number_of_steps &&
261
+ current_step == o.current_step &&
262
+ color == o.color &&
263
+ step_color == o.step_color &&
264
+ auto_dismiss_minutes == o.auto_dismiss_minutes
265
+ end
266
+
267
+ # @see the `==` method
268
+ # @param [Object] Object to be compared
269
+ def eql?(o)
270
+ self == o
271
+ end
272
+
273
+ # Calculates hash code according to all attributes.
274
+ # @return [Integer] Hash code
275
+ def hash
276
+ [title, subtitle, number_of_steps, current_step, color, step_color, auto_dismiss_minutes].hash
277
+ end
278
+
279
+ # Builds the object from hash
280
+ # @param [Hash] attributes Model attributes in the form of hash
281
+ # @return [Object] Returns the model itself
282
+ def self.build_from_hash(attributes)
283
+ return nil unless attributes.is_a?(Hash)
284
+ attributes = attributes.transform_keys(&:to_sym)
285
+ transformed_hash = {}
286
+ openapi_types.each_pair do |key, type|
287
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
288
+ transformed_hash["#{key}"] = nil
289
+ elsif type =~ /\AArray<(.*)>/i
290
+ # check to ensure the input is an array given that the attribute
291
+ # is documented as an array but the input is not
292
+ if attributes[attribute_map[key]].is_a?(Array)
293
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
294
+ end
295
+ elsif !attributes[attribute_map[key]].nil?
296
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
297
+ end
298
+ end
299
+ new(transformed_hash)
300
+ end
301
+
302
+ # Deserializes the data based on type
303
+ # @param string type Data type
304
+ # @param string value Value to be deserialized
305
+ # @return [Object] Deserialized data
306
+ def self._deserialize(type, value)
307
+ case type.to_sym
308
+ when :Time
309
+ Time.parse(value)
310
+ when :Date
311
+ Date.parse(value)
312
+ when :String
313
+ value.to_s
314
+ when :Integer
315
+ value.to_i
316
+ when :Float
317
+ value.to_f
318
+ when :Boolean
319
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
320
+ true
321
+ else
322
+ false
323
+ end
324
+ when :Object
325
+ # generic object (usually a Hash), return directly
326
+ value
327
+ when /\AArray<(?<inner_type>.+)>\z/
328
+ inner_type = Regexp.last_match[:inner_type]
329
+ value.map { |v| _deserialize(inner_type, v) }
330
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
331
+ k_type = Regexp.last_match[:k_type]
332
+ v_type = Regexp.last_match[:v_type]
333
+ {}.tap do |hash|
334
+ value.each do |k, v|
335
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
336
+ end
337
+ end
338
+ else # model
339
+ # models (e.g. Pet) or oneOf
340
+ klass = OpenapiClient.const_get(type)
341
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
342
+ end
343
+ end
344
+
345
+ # Returns the string representation of the object
346
+ # @return [String] String presentation of the object
347
+ def to_s
348
+ to_hash.to_s
349
+ end
350
+
351
+ # to_body is an alias to to_hash (backward compatibility)
352
+ # @return [Hash] Returns the object in the form of hash
353
+ def to_body
354
+ to_hash
355
+ end
356
+
357
+ # Returns the object in the form of hash
358
+ # @return [Hash] Returns the object in the form of hash
359
+ def to_hash
360
+ hash = {}
361
+ self.class.attribute_map.each_pair do |attr, param|
362
+ value = self.send(attr)
363
+ if value.nil?
364
+ is_nullable = self.class.openapi_nullable.include?(attr)
365
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
366
+ end
367
+
368
+ hash[param] = _to_hash(value)
369
+ end
370
+ hash
371
+ end
372
+
373
+ # Outputs non-array value in the form of hash
374
+ # For object, use to_hash. Otherwise, just return the value
375
+ # @param [Object] value Any valid value
376
+ # @return [Hash] Returns the value in the form of hash
377
+ def _to_hash(value)
378
+ if value.is_a?(Array)
379
+ value.compact.map { |v| _to_hash(v) }
380
+ elsif value.is_a?(Hash)
381
+ {}.tap do |hash|
382
+ value.each { |k, v| hash[k] = _to_hash(v) }
383
+ end
384
+ elsif value.respond_to? :to_hash
385
+ value.to_hash
386
+ else
387
+ value
388
+ end
389
+ end
390
+
391
+ end
392
+
393
+ end