zyphr 0.1.34 → 0.1.36

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.
@@ -0,0 +1,351 @@
1
+ =begin
2
+ #Zyphr API
3
+
4
+ #Zyphr is a multi-channel notification platform that enables developers to send emails, push notifications, SMS, and in-app messages through a unified API. ## Authentication All API requests require authentication using an API key. Include your API key in the `X-API-Key` header: ``` X-API-Key: zy_live_xxxxxxxxxxxx ``` API keys can be created in the Zyphr Dashboard. Use `zy_test_*` keys for testing and `zy_live_*` keys for production. ## Rate Limiting The API implements rate limiting to ensure fair usage. Rate limit information is included in response headers: - `X-RateLimit-Limit`: Maximum requests per window - `X-RateLimit-Remaining`: Remaining requests in current window - `X-RateLimit-Reset`: Unix timestamp when the window resets ## Errors All errors follow a consistent format: ```json { \"error\": { \"code\": \"error_code\", \"message\": \"Human readable message\", \"details\": {} }, \"meta\": { \"request_id\": \"req_xxxx\" } } ```
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: support@zyphr.dev
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.12.0
10
+
11
+ =end
12
+
13
+ require 'cgi'
14
+
15
+ module Zyphr
16
+ class AuthEmailOTPApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # Check email OTP availability
23
+ # Check if numeric email OTP authentication is available for this application. Requires a verified sending domain on the project.
24
+ # @param [Hash] opts the optional parameters
25
+ # @return [PhoneAuthAvailabilityResponse]
26
+ def check_email_otp_availability(opts = {})
27
+ data, _status_code, _headers = check_email_otp_availability_with_http_info(opts)
28
+ data
29
+ end
30
+
31
+ # Check email OTP availability
32
+ # Check if numeric email OTP authentication is available for this application. Requires a verified sending domain on the project.
33
+ # @param [Hash] opts the optional parameters
34
+ # @return [Array<(PhoneAuthAvailabilityResponse, Integer, Hash)>] PhoneAuthAvailabilityResponse data, response status code and response headers
35
+ def check_email_otp_availability_with_http_info(opts = {})
36
+ if @api_client.config.debugging
37
+ @api_client.config.logger.debug 'Calling API: AuthEmailOTPApi.check_email_otp_availability ...'
38
+ end
39
+ # resource path
40
+ local_var_path = '/auth/email-otp/available'
41
+
42
+ # query parameters
43
+ query_params = opts[:query_params] || {}
44
+
45
+ # header parameters
46
+ header_params = opts[:header_params] || {}
47
+ # HTTP header 'Accept' (if needed)
48
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
49
+
50
+ # form parameters
51
+ form_params = opts[:form_params] || {}
52
+
53
+ # http body (model)
54
+ post_body = opts[:debug_body]
55
+
56
+ # return_type
57
+ return_type = opts[:debug_return_type] || 'PhoneAuthAvailabilityResponse'
58
+
59
+ # auth_names
60
+ auth_names = opts[:debug_auth_names] || ['ApplicationPublicKey']
61
+
62
+ new_options = opts.merge(
63
+ :operation => :"AuthEmailOTPApi.check_email_otp_availability",
64
+ :header_params => header_params,
65
+ :query_params => query_params,
66
+ :form_params => form_params,
67
+ :body => post_body,
68
+ :auth_names => auth_names,
69
+ :return_type => return_type
70
+ )
71
+
72
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
73
+ if @api_client.config.debugging
74
+ @api_client.config.logger.debug "API called: AuthEmailOTPApi#check_email_otp_availability\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
75
+ end
76
+ return data, status_code, headers
77
+ end
78
+
79
+ # Send email OTP for login
80
+ # Send a numeric verification code to an existing user's email address for login.
81
+ # @param send_email_otp_registration_request [SendEmailOtpRegistrationRequest]
82
+ # @param [Hash] opts the optional parameters
83
+ # @return [PhoneOtpSentResponse]
84
+ def send_email_otp_login(send_email_otp_registration_request, opts = {})
85
+ data, _status_code, _headers = send_email_otp_login_with_http_info(send_email_otp_registration_request, opts)
86
+ data
87
+ end
88
+
89
+ # Send email OTP for login
90
+ # Send a numeric verification code to an existing user&#39;s email address for login.
91
+ # @param send_email_otp_registration_request [SendEmailOtpRegistrationRequest]
92
+ # @param [Hash] opts the optional parameters
93
+ # @return [Array<(PhoneOtpSentResponse, Integer, Hash)>] PhoneOtpSentResponse data, response status code and response headers
94
+ def send_email_otp_login_with_http_info(send_email_otp_registration_request, opts = {})
95
+ if @api_client.config.debugging
96
+ @api_client.config.logger.debug 'Calling API: AuthEmailOTPApi.send_email_otp_login ...'
97
+ end
98
+ # verify the required parameter 'send_email_otp_registration_request' is set
99
+ if @api_client.config.client_side_validation && send_email_otp_registration_request.nil?
100
+ fail ArgumentError, "Missing the required parameter 'send_email_otp_registration_request' when calling AuthEmailOTPApi.send_email_otp_login"
101
+ end
102
+ # resource path
103
+ local_var_path = '/auth/email-otp/login/send'
104
+
105
+ # query parameters
106
+ query_params = opts[:query_params] || {}
107
+
108
+ # header parameters
109
+ header_params = opts[:header_params] || {}
110
+ # HTTP header 'Accept' (if needed)
111
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
112
+ # HTTP header 'Content-Type'
113
+ content_type = @api_client.select_header_content_type(['application/json'])
114
+ if !content_type.nil?
115
+ header_params['Content-Type'] = content_type
116
+ end
117
+
118
+ # form parameters
119
+ form_params = opts[:form_params] || {}
120
+
121
+ # http body (model)
122
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(send_email_otp_registration_request)
123
+
124
+ # return_type
125
+ return_type = opts[:debug_return_type] || 'PhoneOtpSentResponse'
126
+
127
+ # auth_names
128
+ auth_names = opts[:debug_auth_names] || ['ApplicationSecret', 'ApplicationPublicKey']
129
+
130
+ new_options = opts.merge(
131
+ :operation => :"AuthEmailOTPApi.send_email_otp_login",
132
+ :header_params => header_params,
133
+ :query_params => query_params,
134
+ :form_params => form_params,
135
+ :body => post_body,
136
+ :auth_names => auth_names,
137
+ :return_type => return_type
138
+ )
139
+
140
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
141
+ if @api_client.config.debugging
142
+ @api_client.config.logger.debug "API called: AuthEmailOTPApi#send_email_otp_login\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
143
+ end
144
+ return data, status_code, headers
145
+ end
146
+
147
+ # Send email OTP for registration
148
+ # Send a numeric verification code to an email address for new user registration.
149
+ # @param send_email_otp_registration_request [SendEmailOtpRegistrationRequest]
150
+ # @param [Hash] opts the optional parameters
151
+ # @return [PhoneOtpSentResponse]
152
+ def send_email_otp_registration(send_email_otp_registration_request, opts = {})
153
+ data, _status_code, _headers = send_email_otp_registration_with_http_info(send_email_otp_registration_request, opts)
154
+ data
155
+ end
156
+
157
+ # Send email OTP for registration
158
+ # Send a numeric verification code to an email address for new user registration.
159
+ # @param send_email_otp_registration_request [SendEmailOtpRegistrationRequest]
160
+ # @param [Hash] opts the optional parameters
161
+ # @return [Array<(PhoneOtpSentResponse, Integer, Hash)>] PhoneOtpSentResponse data, response status code and response headers
162
+ def send_email_otp_registration_with_http_info(send_email_otp_registration_request, opts = {})
163
+ if @api_client.config.debugging
164
+ @api_client.config.logger.debug 'Calling API: AuthEmailOTPApi.send_email_otp_registration ...'
165
+ end
166
+ # verify the required parameter 'send_email_otp_registration_request' is set
167
+ if @api_client.config.client_side_validation && send_email_otp_registration_request.nil?
168
+ fail ArgumentError, "Missing the required parameter 'send_email_otp_registration_request' when calling AuthEmailOTPApi.send_email_otp_registration"
169
+ end
170
+ # resource path
171
+ local_var_path = '/auth/email-otp/register/send'
172
+
173
+ # query parameters
174
+ query_params = opts[:query_params] || {}
175
+
176
+ # header parameters
177
+ header_params = opts[:header_params] || {}
178
+ # HTTP header 'Accept' (if needed)
179
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
180
+ # HTTP header 'Content-Type'
181
+ content_type = @api_client.select_header_content_type(['application/json'])
182
+ if !content_type.nil?
183
+ header_params['Content-Type'] = content_type
184
+ end
185
+
186
+ # form parameters
187
+ form_params = opts[:form_params] || {}
188
+
189
+ # http body (model)
190
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(send_email_otp_registration_request)
191
+
192
+ # return_type
193
+ return_type = opts[:debug_return_type] || 'PhoneOtpSentResponse'
194
+
195
+ # auth_names
196
+ auth_names = opts[:debug_auth_names] || ['ApplicationSecret', 'ApplicationPublicKey']
197
+
198
+ new_options = opts.merge(
199
+ :operation => :"AuthEmailOTPApi.send_email_otp_registration",
200
+ :header_params => header_params,
201
+ :query_params => query_params,
202
+ :form_params => form_params,
203
+ :body => post_body,
204
+ :auth_names => auth_names,
205
+ :return_type => return_type
206
+ )
207
+
208
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
209
+ if @api_client.config.debugging
210
+ @api_client.config.logger.debug "API called: AuthEmailOTPApi#send_email_otp_registration\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
211
+ end
212
+ return data, status_code, headers
213
+ end
214
+
215
+ # Verify email OTP login
216
+ # Verify the numeric code and login an existing user. If MFA is enabled, returns mfa_required with a challenge token.
217
+ # @param verify_email_otp_login_request [VerifyEmailOtpLoginRequest]
218
+ # @param [Hash] opts the optional parameters
219
+ # @return [AuthLoginResponse]
220
+ def verify_email_otp_login(verify_email_otp_login_request, opts = {})
221
+ data, _status_code, _headers = verify_email_otp_login_with_http_info(verify_email_otp_login_request, opts)
222
+ data
223
+ end
224
+
225
+ # Verify email OTP login
226
+ # Verify the numeric code and login an existing user. If MFA is enabled, returns mfa_required with a challenge token.
227
+ # @param verify_email_otp_login_request [VerifyEmailOtpLoginRequest]
228
+ # @param [Hash] opts the optional parameters
229
+ # @return [Array<(AuthLoginResponse, Integer, Hash)>] AuthLoginResponse data, response status code and response headers
230
+ def verify_email_otp_login_with_http_info(verify_email_otp_login_request, opts = {})
231
+ if @api_client.config.debugging
232
+ @api_client.config.logger.debug 'Calling API: AuthEmailOTPApi.verify_email_otp_login ...'
233
+ end
234
+ # verify the required parameter 'verify_email_otp_login_request' is set
235
+ if @api_client.config.client_side_validation && verify_email_otp_login_request.nil?
236
+ fail ArgumentError, "Missing the required parameter 'verify_email_otp_login_request' when calling AuthEmailOTPApi.verify_email_otp_login"
237
+ end
238
+ # resource path
239
+ local_var_path = '/auth/email-otp/login/verify'
240
+
241
+ # query parameters
242
+ query_params = opts[:query_params] || {}
243
+
244
+ # header parameters
245
+ header_params = opts[:header_params] || {}
246
+ # HTTP header 'Accept' (if needed)
247
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
248
+ # HTTP header 'Content-Type'
249
+ content_type = @api_client.select_header_content_type(['application/json'])
250
+ if !content_type.nil?
251
+ header_params['Content-Type'] = content_type
252
+ end
253
+
254
+ # form parameters
255
+ form_params = opts[:form_params] || {}
256
+
257
+ # http body (model)
258
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(verify_email_otp_login_request)
259
+
260
+ # return_type
261
+ return_type = opts[:debug_return_type] || 'AuthLoginResponse'
262
+
263
+ # auth_names
264
+ auth_names = opts[:debug_auth_names] || ['ApplicationSecret', 'ApplicationPublicKey']
265
+
266
+ new_options = opts.merge(
267
+ :operation => :"AuthEmailOTPApi.verify_email_otp_login",
268
+ :header_params => header_params,
269
+ :query_params => query_params,
270
+ :form_params => form_params,
271
+ :body => post_body,
272
+ :auth_names => auth_names,
273
+ :return_type => return_type
274
+ )
275
+
276
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
277
+ if @api_client.config.debugging
278
+ @api_client.config.logger.debug "API called: AuthEmailOTPApi#verify_email_otp_login\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
279
+ end
280
+ return data, status_code, headers
281
+ end
282
+
283
+ # Verify email OTP registration
284
+ # Verify the numeric code and create a new user account with the email address.
285
+ # @param verify_email_otp_registration_request [VerifyEmailOtpRegistrationRequest]
286
+ # @param [Hash] opts the optional parameters
287
+ # @return [AuthResultResponse]
288
+ def verify_email_otp_registration(verify_email_otp_registration_request, opts = {})
289
+ data, _status_code, _headers = verify_email_otp_registration_with_http_info(verify_email_otp_registration_request, opts)
290
+ data
291
+ end
292
+
293
+ # Verify email OTP registration
294
+ # Verify the numeric code and create a new user account with the email address.
295
+ # @param verify_email_otp_registration_request [VerifyEmailOtpRegistrationRequest]
296
+ # @param [Hash] opts the optional parameters
297
+ # @return [Array<(AuthResultResponse, Integer, Hash)>] AuthResultResponse data, response status code and response headers
298
+ def verify_email_otp_registration_with_http_info(verify_email_otp_registration_request, opts = {})
299
+ if @api_client.config.debugging
300
+ @api_client.config.logger.debug 'Calling API: AuthEmailOTPApi.verify_email_otp_registration ...'
301
+ end
302
+ # verify the required parameter 'verify_email_otp_registration_request' is set
303
+ if @api_client.config.client_side_validation && verify_email_otp_registration_request.nil?
304
+ fail ArgumentError, "Missing the required parameter 'verify_email_otp_registration_request' when calling AuthEmailOTPApi.verify_email_otp_registration"
305
+ end
306
+ # resource path
307
+ local_var_path = '/auth/email-otp/register/verify'
308
+
309
+ # query parameters
310
+ query_params = opts[:query_params] || {}
311
+
312
+ # header parameters
313
+ header_params = opts[:header_params] || {}
314
+ # HTTP header 'Accept' (if needed)
315
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
316
+ # HTTP header 'Content-Type'
317
+ content_type = @api_client.select_header_content_type(['application/json'])
318
+ if !content_type.nil?
319
+ header_params['Content-Type'] = content_type
320
+ end
321
+
322
+ # form parameters
323
+ form_params = opts[:form_params] || {}
324
+
325
+ # http body (model)
326
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(verify_email_otp_registration_request)
327
+
328
+ # return_type
329
+ return_type = opts[:debug_return_type] || 'AuthResultResponse'
330
+
331
+ # auth_names
332
+ auth_names = opts[:debug_auth_names] || ['ApplicationSecret', 'ApplicationPublicKey']
333
+
334
+ new_options = opts.merge(
335
+ :operation => :"AuthEmailOTPApi.verify_email_otp_registration",
336
+ :header_params => header_params,
337
+ :query_params => query_params,
338
+ :form_params => form_params,
339
+ :body => post_body,
340
+ :auth_names => auth_names,
341
+ :return_type => return_type
342
+ )
343
+
344
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
345
+ if @api_client.config.debugging
346
+ @api_client.config.logger.debug "API called: AuthEmailOTPApi#verify_email_otp_registration\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
347
+ end
348
+ return data, status_code, headers
349
+ end
350
+ end
351
+ end
@@ -0,0 +1,237 @@
1
+ =begin
2
+ #Zyphr API
3
+
4
+ #Zyphr is a multi-channel notification platform that enables developers to send emails, push notifications, SMS, and in-app messages through a unified API. ## Authentication All API requests require authentication using an API key. Include your API key in the `X-API-Key` header: ``` X-API-Key: zy_live_xxxxxxxxxxxx ``` API keys can be created in the Zyphr Dashboard. Use `zy_test_*` keys for testing and `zy_live_*` keys for production. ## Rate Limiting The API implements rate limiting to ensure fair usage. Rate limit information is included in response headers: - `X-RateLimit-Limit`: Maximum requests per window - `X-RateLimit-Remaining`: Remaining requests in current window - `X-RateLimit-Reset`: Unix timestamp when the window resets ## Errors All errors follow a consistent format: ```json { \"error\": { \"code\": \"error_code\", \"message\": \"Human readable message\", \"details\": {} }, \"meta\": { \"request_id\": \"req_xxxx\" } } ```
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: support@zyphr.dev
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.12.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Zyphr
17
+ class SendEmailOtpRegistrationRequest
18
+ attr_accessor :email
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :'email' => :'email'
24
+ }
25
+ end
26
+
27
+ # Returns attribute mapping this model knows about
28
+ def self.acceptable_attribute_map
29
+ attribute_map
30
+ end
31
+
32
+ # Returns all the JSON keys this model knows about
33
+ def self.acceptable_attributes
34
+ acceptable_attribute_map.values
35
+ end
36
+
37
+ # Attribute type mapping.
38
+ def self.openapi_types
39
+ {
40
+ :'email' => :'String'
41
+ }
42
+ end
43
+
44
+ # List of attributes with nullable: true
45
+ def self.openapi_nullable
46
+ Set.new([
47
+ ])
48
+ end
49
+
50
+ # Initializes the object
51
+ # @param [Hash] attributes Model attributes in the form of hash
52
+ def initialize(attributes = {})
53
+ if (!attributes.is_a?(Hash))
54
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::SendEmailOtpRegistrationRequest` initialize method"
55
+ end
56
+
57
+ # check to see if the attribute exists and convert string to symbol for hash key
58
+ acceptable_attribute_map = self.class.acceptable_attribute_map
59
+ attributes = attributes.each_with_object({}) { |(k, v), h|
60
+ if (!acceptable_attribute_map.key?(k.to_sym))
61
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::SendEmailOtpRegistrationRequest`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
62
+ end
63
+ h[k.to_sym] = v
64
+ }
65
+
66
+ if attributes.key?(:'email')
67
+ self.email = attributes[:'email']
68
+ else
69
+ self.email = nil
70
+ end
71
+ end
72
+
73
+ # Show invalid properties with the reasons. Usually used together with valid?
74
+ # @return Array for valid properties with the reasons
75
+ def list_invalid_properties
76
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
77
+ invalid_properties = Array.new
78
+ if @email.nil?
79
+ invalid_properties.push('invalid value for "email", email cannot be nil.')
80
+ end
81
+
82
+ invalid_properties
83
+ end
84
+
85
+ # Check to see if the all the properties in the model are valid
86
+ # @return true if the model is valid
87
+ def valid?
88
+ warn '[DEPRECATED] the `valid?` method is obsolete'
89
+ return false if @email.nil?
90
+ true
91
+ end
92
+
93
+ # Custom attribute writer method with validation
94
+ # @param [Object] email Value to be assigned
95
+ def email=(email)
96
+ if email.nil?
97
+ fail ArgumentError, 'email cannot be nil'
98
+ end
99
+
100
+ @email = email
101
+ end
102
+
103
+ # Checks equality by comparing each attribute.
104
+ # @param [Object] Object to be compared
105
+ def ==(o)
106
+ return true if self.equal?(o)
107
+ self.class == o.class &&
108
+ email == o.email
109
+ end
110
+
111
+ # @see the `==` method
112
+ # @param [Object] Object to be compared
113
+ def eql?(o)
114
+ self == o
115
+ end
116
+
117
+ # Calculates hash code according to all attributes.
118
+ # @return [Integer] Hash code
119
+ def hash
120
+ [email].hash
121
+ end
122
+
123
+ # Builds the object from hash
124
+ # @param [Hash] attributes Model attributes in the form of hash
125
+ # @return [Object] Returns the model itself
126
+ def self.build_from_hash(attributes)
127
+ return nil unless attributes.is_a?(Hash)
128
+ attributes = attributes.transform_keys(&:to_sym)
129
+ transformed_hash = {}
130
+ openapi_types.each_pair do |key, type|
131
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
132
+ transformed_hash["#{key}"] = nil
133
+ elsif type =~ /\AArray<(.*)>/i
134
+ # check to ensure the input is an array given that the attribute
135
+ # is documented as an array but the input is not
136
+ if attributes[attribute_map[key]].is_a?(Array)
137
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
138
+ end
139
+ elsif !attributes[attribute_map[key]].nil?
140
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
141
+ end
142
+ end
143
+ new(transformed_hash)
144
+ end
145
+
146
+ # Deserializes the data based on type
147
+ # @param string type Data type
148
+ # @param string value Value to be deserialized
149
+ # @return [Object] Deserialized data
150
+ def self._deserialize(type, value)
151
+ case type.to_sym
152
+ when :Time
153
+ Time.parse(value)
154
+ when :Date
155
+ Date.parse(value)
156
+ when :String
157
+ value.to_s
158
+ when :Integer
159
+ value.to_i
160
+ when :Float
161
+ value.to_f
162
+ when :Boolean
163
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
164
+ true
165
+ else
166
+ false
167
+ end
168
+ when :Object
169
+ # generic object (usually a Hash), return directly
170
+ value
171
+ when /\AArray<(?<inner_type>.+)>\z/
172
+ inner_type = Regexp.last_match[:inner_type]
173
+ value.map { |v| _deserialize(inner_type, v) }
174
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
175
+ k_type = Regexp.last_match[:k_type]
176
+ v_type = Regexp.last_match[:v_type]
177
+ {}.tap do |hash|
178
+ value.each do |k, v|
179
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
180
+ end
181
+ end
182
+ else # model
183
+ # models (e.g. Pet) or oneOf
184
+ klass = Zyphr.const_get(type)
185
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
186
+ end
187
+ end
188
+
189
+ # Returns the string representation of the object
190
+ # @return [String] String presentation of the object
191
+ def to_s
192
+ to_hash.to_s
193
+ end
194
+
195
+ # to_body is an alias to to_hash (backward compatibility)
196
+ # @return [Hash] Returns the object in the form of hash
197
+ def to_body
198
+ to_hash
199
+ end
200
+
201
+ # Returns the object in the form of hash
202
+ # @return [Hash] Returns the object in the form of hash
203
+ def to_hash
204
+ hash = {}
205
+ self.class.attribute_map.each_pair do |attr, param|
206
+ value = self.send(attr)
207
+ if value.nil?
208
+ is_nullable = self.class.openapi_nullable.include?(attr)
209
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
210
+ end
211
+
212
+ hash[param] = _to_hash(value)
213
+ end
214
+ hash
215
+ end
216
+
217
+ # Outputs non-array value in the form of hash
218
+ # For object, use to_hash. Otherwise, just return the value
219
+ # @param [Object] value Any valid value
220
+ # @return [Hash] Returns the value in the form of hash
221
+ def _to_hash(value)
222
+ if value.is_a?(Array)
223
+ value.compact.map { |v| _to_hash(v) }
224
+ elsif value.is_a?(Hash)
225
+ {}.tap do |hash|
226
+ value.each { |k, v| hash[k] = _to_hash(v) }
227
+ end
228
+ elsif value.respond_to? :to_hash
229
+ value.to_hash
230
+ else
231
+ value
232
+ end
233
+ end
234
+
235
+ end
236
+
237
+ end