zyphr 0.1.26 → 0.1.28

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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +21 -0
  3. data/docs/AddDomain200Response.md +20 -0
  4. data/docs/AddDomain200ResponseMeta.md +20 -0
  5. data/docs/AddDomainRequest.md +18 -0
  6. data/docs/DeleteDomainResponse.md +20 -0
  7. data/docs/DeleteDomainResponseData.md +20 -0
  8. data/docs/DnsRecord.md +26 -0
  9. data/docs/DomainListResponse.md +20 -0
  10. data/docs/DomainListResponseMeta.md +24 -0
  11. data/docs/DomainResponse.md +38 -0
  12. data/docs/DomainsApi.md +436 -0
  13. data/docs/GetDomain200Response.md +20 -0
  14. data/docs/GetDomain200ResponseMeta.md +18 -0
  15. data/docs/VerificationStatusResponse.md +20 -0
  16. data/docs/VerificationStatusResponseData.md +32 -0
  17. data/docs/VerifyDomainResponse.md +20 -0
  18. data/docs/VerifyDomainResponseData.md +24 -0
  19. data/lib/zyphr/api/domains_api.rb +399 -0
  20. data/lib/zyphr/models/add_domain200_response.rb +229 -0
  21. data/lib/zyphr/models/add_domain200_response_meta.rb +229 -0
  22. data/lib/zyphr/models/add_domain_request.rb +238 -0
  23. data/lib/zyphr/models/delete_domain_response.rb +263 -0
  24. data/lib/zyphr/models/delete_domain_response_data.rb +263 -0
  25. data/lib/zyphr/models/dns_record.rb +373 -0
  26. data/lib/zyphr/models/domain_list_response.rb +265 -0
  27. data/lib/zyphr/models/domain_list_response_meta.rb +249 -0
  28. data/lib/zyphr/models/domain_response.rb +463 -0
  29. data/lib/zyphr/models/get_domain200_response.rb +229 -0
  30. data/lib/zyphr/models/get_domain200_response_meta.rb +220 -0
  31. data/lib/zyphr/models/verification_status_response.rb +263 -0
  32. data/lib/zyphr/models/verification_status_response_data.rb +415 -0
  33. data/lib/zyphr/models/verify_domain_response.rb +263 -0
  34. data/lib/zyphr/models/verify_domain_response_data.rb +339 -0
  35. data/lib/zyphr.rb +16 -0
  36. data/spec/api/domains_api_spec.rb +106 -0
  37. data/spec/models/add_domain200_response_meta_spec.rb +42 -0
  38. data/spec/models/add_domain200_response_spec.rb +42 -0
  39. data/spec/models/add_domain_request_spec.rb +36 -0
  40. data/spec/models/delete_domain_response_data_spec.rb +42 -0
  41. data/spec/models/delete_domain_response_spec.rb +42 -0
  42. data/spec/models/dns_record_spec.rb +68 -0
  43. data/spec/models/domain_list_response_meta_spec.rb +54 -0
  44. data/spec/models/domain_list_response_spec.rb +42 -0
  45. data/spec/models/domain_response_spec.rb +100 -0
  46. data/spec/models/get_domain200_response_meta_spec.rb +36 -0
  47. data/spec/models/get_domain200_response_spec.rb +42 -0
  48. data/spec/models/verification_status_response_data_spec.rb +82 -0
  49. data/spec/models/verification_status_response_spec.rb +42 -0
  50. data/spec/models/verify_domain_response_data_spec.rb +58 -0
  51. data/spec/models/verify_domain_response_spec.rb +42 -0
  52. data/zyphr.gemspec +1 -1
  53. metadata +435 -371
@@ -0,0 +1,415 @@
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 VerificationStatusResponseData
18
+ attr_accessor :domain_id
19
+
20
+ attr_accessor :domain
21
+
22
+ attr_accessor :status
23
+
24
+ attr_accessor :records_verified
25
+
26
+ attr_accessor :records_total
27
+
28
+ # Internal verification progress detail
29
+ attr_accessor :progress
30
+
31
+ attr_accessor :dns_records
32
+
33
+ attr_accessor :last_checked_at
34
+
35
+ class EnumAttributeValidator
36
+ attr_reader :datatype
37
+ attr_reader :allowable_values
38
+
39
+ def initialize(datatype, allowable_values)
40
+ @allowable_values = allowable_values.map do |value|
41
+ case datatype.to_s
42
+ when /Integer/i
43
+ value.to_i
44
+ when /Float/i
45
+ value.to_f
46
+ else
47
+ value
48
+ end
49
+ end
50
+ end
51
+
52
+ def valid?(value)
53
+ !value || allowable_values.include?(value)
54
+ end
55
+ end
56
+
57
+ # Attribute mapping from ruby-style variable name to JSON key.
58
+ def self.attribute_map
59
+ {
60
+ :'domain_id' => :'domain_id',
61
+ :'domain' => :'domain',
62
+ :'status' => :'status',
63
+ :'records_verified' => :'records_verified',
64
+ :'records_total' => :'records_total',
65
+ :'progress' => :'progress',
66
+ :'dns_records' => :'dns_records',
67
+ :'last_checked_at' => :'last_checked_at'
68
+ }
69
+ end
70
+
71
+ # Returns attribute mapping this model knows about
72
+ def self.acceptable_attribute_map
73
+ attribute_map
74
+ end
75
+
76
+ # Returns all the JSON keys this model knows about
77
+ def self.acceptable_attributes
78
+ acceptable_attribute_map.values
79
+ end
80
+
81
+ # Attribute type mapping.
82
+ def self.openapi_types
83
+ {
84
+ :'domain_id' => :'String',
85
+ :'domain' => :'String',
86
+ :'status' => :'String',
87
+ :'records_verified' => :'Integer',
88
+ :'records_total' => :'Integer',
89
+ :'progress' => :'Hash<String, Object>',
90
+ :'dns_records' => :'Array<DnsRecord>',
91
+ :'last_checked_at' => :'Time'
92
+ }
93
+ end
94
+
95
+ # List of attributes with nullable: true
96
+ def self.openapi_nullable
97
+ Set.new([
98
+ :'last_checked_at'
99
+ ])
100
+ end
101
+
102
+ # Initializes the object
103
+ # @param [Hash] attributes Model attributes in the form of hash
104
+ def initialize(attributes = {})
105
+ if (!attributes.is_a?(Hash))
106
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::VerificationStatusResponseData` initialize method"
107
+ end
108
+
109
+ # check to see if the attribute exists and convert string to symbol for hash key
110
+ acceptable_attribute_map = self.class.acceptable_attribute_map
111
+ attributes = attributes.each_with_object({}) { |(k, v), h|
112
+ if (!acceptable_attribute_map.key?(k.to_sym))
113
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::VerificationStatusResponseData`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
114
+ end
115
+ h[k.to_sym] = v
116
+ }
117
+
118
+ if attributes.key?(:'domain_id')
119
+ self.domain_id = attributes[:'domain_id']
120
+ else
121
+ self.domain_id = nil
122
+ end
123
+
124
+ if attributes.key?(:'domain')
125
+ self.domain = attributes[:'domain']
126
+ else
127
+ self.domain = nil
128
+ end
129
+
130
+ if attributes.key?(:'status')
131
+ self.status = attributes[:'status']
132
+ else
133
+ self.status = nil
134
+ end
135
+
136
+ if attributes.key?(:'records_verified')
137
+ self.records_verified = attributes[:'records_verified']
138
+ else
139
+ self.records_verified = nil
140
+ end
141
+
142
+ if attributes.key?(:'records_total')
143
+ self.records_total = attributes[:'records_total']
144
+ else
145
+ self.records_total = nil
146
+ end
147
+
148
+ if attributes.key?(:'progress')
149
+ if (value = attributes[:'progress']).is_a?(Hash)
150
+ self.progress = value
151
+ end
152
+ end
153
+
154
+ if attributes.key?(:'dns_records')
155
+ if (value = attributes[:'dns_records']).is_a?(Array)
156
+ self.dns_records = value
157
+ end
158
+ else
159
+ self.dns_records = nil
160
+ end
161
+
162
+ if attributes.key?(:'last_checked_at')
163
+ self.last_checked_at = attributes[:'last_checked_at']
164
+ end
165
+ end
166
+
167
+ # Show invalid properties with the reasons. Usually used together with valid?
168
+ # @return Array for valid properties with the reasons
169
+ def list_invalid_properties
170
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
171
+ invalid_properties = Array.new
172
+ if @domain_id.nil?
173
+ invalid_properties.push('invalid value for "domain_id", domain_id cannot be nil.')
174
+ end
175
+
176
+ if @domain.nil?
177
+ invalid_properties.push('invalid value for "domain", domain cannot be nil.')
178
+ end
179
+
180
+ if @status.nil?
181
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
182
+ end
183
+
184
+ if @records_verified.nil?
185
+ invalid_properties.push('invalid value for "records_verified", records_verified cannot be nil.')
186
+ end
187
+
188
+ if @records_total.nil?
189
+ invalid_properties.push('invalid value for "records_total", records_total cannot be nil.')
190
+ end
191
+
192
+ if @dns_records.nil?
193
+ invalid_properties.push('invalid value for "dns_records", dns_records cannot be nil.')
194
+ end
195
+
196
+ invalid_properties
197
+ end
198
+
199
+ # Check to see if the all the properties in the model are valid
200
+ # @return true if the model is valid
201
+ def valid?
202
+ warn '[DEPRECATED] the `valid?` method is obsolete'
203
+ return false if @domain_id.nil?
204
+ return false if @domain.nil?
205
+ return false if @status.nil?
206
+ status_validator = EnumAttributeValidator.new('String', ["pending", "verifying", "verified", "failed"])
207
+ return false unless status_validator.valid?(@status)
208
+ return false if @records_verified.nil?
209
+ return false if @records_total.nil?
210
+ return false if @dns_records.nil?
211
+ true
212
+ end
213
+
214
+ # Custom attribute writer method with validation
215
+ # @param [Object] domain_id Value to be assigned
216
+ def domain_id=(domain_id)
217
+ if domain_id.nil?
218
+ fail ArgumentError, 'domain_id cannot be nil'
219
+ end
220
+
221
+ @domain_id = domain_id
222
+ end
223
+
224
+ # Custom attribute writer method with validation
225
+ # @param [Object] domain Value to be assigned
226
+ def domain=(domain)
227
+ if domain.nil?
228
+ fail ArgumentError, 'domain cannot be nil'
229
+ end
230
+
231
+ @domain = domain
232
+ end
233
+
234
+ # Custom attribute writer method checking allowed values (enum).
235
+ # @param [Object] status Object to be assigned
236
+ def status=(status)
237
+ validator = EnumAttributeValidator.new('String', ["pending", "verifying", "verified", "failed"])
238
+ unless validator.valid?(status)
239
+ fail ArgumentError, "invalid value for \"status\", must be one of #{validator.allowable_values}."
240
+ end
241
+ @status = status
242
+ end
243
+
244
+ # Custom attribute writer method with validation
245
+ # @param [Object] records_verified Value to be assigned
246
+ def records_verified=(records_verified)
247
+ if records_verified.nil?
248
+ fail ArgumentError, 'records_verified cannot be nil'
249
+ end
250
+
251
+ @records_verified = records_verified
252
+ end
253
+
254
+ # Custom attribute writer method with validation
255
+ # @param [Object] records_total Value to be assigned
256
+ def records_total=(records_total)
257
+ if records_total.nil?
258
+ fail ArgumentError, 'records_total cannot be nil'
259
+ end
260
+
261
+ @records_total = records_total
262
+ end
263
+
264
+ # Custom attribute writer method with validation
265
+ # @param [Object] dns_records Value to be assigned
266
+ def dns_records=(dns_records)
267
+ if dns_records.nil?
268
+ fail ArgumentError, 'dns_records cannot be nil'
269
+ end
270
+
271
+ @dns_records = dns_records
272
+ end
273
+
274
+ # Checks equality by comparing each attribute.
275
+ # @param [Object] Object to be compared
276
+ def ==(o)
277
+ return true if self.equal?(o)
278
+ self.class == o.class &&
279
+ domain_id == o.domain_id &&
280
+ domain == o.domain &&
281
+ status == o.status &&
282
+ records_verified == o.records_verified &&
283
+ records_total == o.records_total &&
284
+ progress == o.progress &&
285
+ dns_records == o.dns_records &&
286
+ last_checked_at == o.last_checked_at
287
+ end
288
+
289
+ # @see the `==` method
290
+ # @param [Object] Object to be compared
291
+ def eql?(o)
292
+ self == o
293
+ end
294
+
295
+ # Calculates hash code according to all attributes.
296
+ # @return [Integer] Hash code
297
+ def hash
298
+ [domain_id, domain, status, records_verified, records_total, progress, dns_records, last_checked_at].hash
299
+ end
300
+
301
+ # Builds the object from hash
302
+ # @param [Hash] attributes Model attributes in the form of hash
303
+ # @return [Object] Returns the model itself
304
+ def self.build_from_hash(attributes)
305
+ return nil unless attributes.is_a?(Hash)
306
+ attributes = attributes.transform_keys(&:to_sym)
307
+ transformed_hash = {}
308
+ openapi_types.each_pair do |key, type|
309
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
310
+ transformed_hash["#{key}"] = nil
311
+ elsif type =~ /\AArray<(.*)>/i
312
+ # check to ensure the input is an array given that the attribute
313
+ # is documented as an array but the input is not
314
+ if attributes[attribute_map[key]].is_a?(Array)
315
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
316
+ end
317
+ elsif !attributes[attribute_map[key]].nil?
318
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
319
+ end
320
+ end
321
+ new(transformed_hash)
322
+ end
323
+
324
+ # Deserializes the data based on type
325
+ # @param string type Data type
326
+ # @param string value Value to be deserialized
327
+ # @return [Object] Deserialized data
328
+ def self._deserialize(type, value)
329
+ case type.to_sym
330
+ when :Time
331
+ Time.parse(value)
332
+ when :Date
333
+ Date.parse(value)
334
+ when :String
335
+ value.to_s
336
+ when :Integer
337
+ value.to_i
338
+ when :Float
339
+ value.to_f
340
+ when :Boolean
341
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
342
+ true
343
+ else
344
+ false
345
+ end
346
+ when :Object
347
+ # generic object (usually a Hash), return directly
348
+ value
349
+ when /\AArray<(?<inner_type>.+)>\z/
350
+ inner_type = Regexp.last_match[:inner_type]
351
+ value.map { |v| _deserialize(inner_type, v) }
352
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
353
+ k_type = Regexp.last_match[:k_type]
354
+ v_type = Regexp.last_match[:v_type]
355
+ {}.tap do |hash|
356
+ value.each do |k, v|
357
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
358
+ end
359
+ end
360
+ else # model
361
+ # models (e.g. Pet) or oneOf
362
+ klass = Zyphr.const_get(type)
363
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
364
+ end
365
+ end
366
+
367
+ # Returns the string representation of the object
368
+ # @return [String] String presentation of the object
369
+ def to_s
370
+ to_hash.to_s
371
+ end
372
+
373
+ # to_body is an alias to to_hash (backward compatibility)
374
+ # @return [Hash] Returns the object in the form of hash
375
+ def to_body
376
+ to_hash
377
+ end
378
+
379
+ # Returns the object in the form of hash
380
+ # @return [Hash] Returns the object in the form of hash
381
+ def to_hash
382
+ hash = {}
383
+ self.class.attribute_map.each_pair do |attr, param|
384
+ value = self.send(attr)
385
+ if value.nil?
386
+ is_nullable = self.class.openapi_nullable.include?(attr)
387
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
388
+ end
389
+
390
+ hash[param] = _to_hash(value)
391
+ end
392
+ hash
393
+ end
394
+
395
+ # Outputs non-array value in the form of hash
396
+ # For object, use to_hash. Otherwise, just return the value
397
+ # @param [Object] value Any valid value
398
+ # @return [Hash] Returns the value in the form of hash
399
+ def _to_hash(value)
400
+ if value.is_a?(Array)
401
+ value.compact.map { |v| _to_hash(v) }
402
+ elsif value.is_a?(Hash)
403
+ {}.tap do |hash|
404
+ value.each { |k, v| hash[k] = _to_hash(v) }
405
+ end
406
+ elsif value.respond_to? :to_hash
407
+ value.to_hash
408
+ else
409
+ value
410
+ end
411
+ end
412
+
413
+ end
414
+
415
+ end
@@ -0,0 +1,263 @@
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 VerifyDomainResponse
18
+ attr_accessor :data
19
+
20
+ attr_accessor :meta
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'data' => :'data',
26
+ :'meta' => :'meta'
27
+ }
28
+ end
29
+
30
+ # Returns attribute mapping this model knows about
31
+ def self.acceptable_attribute_map
32
+ attribute_map
33
+ end
34
+
35
+ # Returns all the JSON keys this model knows about
36
+ def self.acceptable_attributes
37
+ acceptable_attribute_map.values
38
+ end
39
+
40
+ # Attribute type mapping.
41
+ def self.openapi_types
42
+ {
43
+ :'data' => :'VerifyDomainResponseData',
44
+ :'meta' => :'AddDomain200ResponseMeta'
45
+ }
46
+ end
47
+
48
+ # List of attributes with nullable: true
49
+ def self.openapi_nullable
50
+ Set.new([
51
+ ])
52
+ end
53
+
54
+ # Initializes the object
55
+ # @param [Hash] attributes Model attributes in the form of hash
56
+ def initialize(attributes = {})
57
+ if (!attributes.is_a?(Hash))
58
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::VerifyDomainResponse` initialize method"
59
+ end
60
+
61
+ # check to see if the attribute exists and convert string to symbol for hash key
62
+ acceptable_attribute_map = self.class.acceptable_attribute_map
63
+ attributes = attributes.each_with_object({}) { |(k, v), h|
64
+ if (!acceptable_attribute_map.key?(k.to_sym))
65
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::VerifyDomainResponse`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
66
+ end
67
+ h[k.to_sym] = v
68
+ }
69
+
70
+ if attributes.key?(:'data')
71
+ self.data = attributes[:'data']
72
+ else
73
+ self.data = nil
74
+ end
75
+
76
+ if attributes.key?(:'meta')
77
+ self.meta = attributes[:'meta']
78
+ else
79
+ self.meta = nil
80
+ end
81
+ end
82
+
83
+ # Show invalid properties with the reasons. Usually used together with valid?
84
+ # @return Array for valid properties with the reasons
85
+ def list_invalid_properties
86
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
87
+ invalid_properties = Array.new
88
+ if @data.nil?
89
+ invalid_properties.push('invalid value for "data", data cannot be nil.')
90
+ end
91
+
92
+ if @meta.nil?
93
+ invalid_properties.push('invalid value for "meta", meta cannot be nil.')
94
+ end
95
+
96
+ invalid_properties
97
+ end
98
+
99
+ # Check to see if the all the properties in the model are valid
100
+ # @return true if the model is valid
101
+ def valid?
102
+ warn '[DEPRECATED] the `valid?` method is obsolete'
103
+ return false if @data.nil?
104
+ return false if @meta.nil?
105
+ true
106
+ end
107
+
108
+ # Custom attribute writer method with validation
109
+ # @param [Object] data Value to be assigned
110
+ def data=(data)
111
+ if data.nil?
112
+ fail ArgumentError, 'data cannot be nil'
113
+ end
114
+
115
+ @data = data
116
+ end
117
+
118
+ # Custom attribute writer method with validation
119
+ # @param [Object] meta Value to be assigned
120
+ def meta=(meta)
121
+ if meta.nil?
122
+ fail ArgumentError, 'meta cannot be nil'
123
+ end
124
+
125
+ @meta = meta
126
+ end
127
+
128
+ # Checks equality by comparing each attribute.
129
+ # @param [Object] Object to be compared
130
+ def ==(o)
131
+ return true if self.equal?(o)
132
+ self.class == o.class &&
133
+ data == o.data &&
134
+ meta == o.meta
135
+ end
136
+
137
+ # @see the `==` method
138
+ # @param [Object] Object to be compared
139
+ def eql?(o)
140
+ self == o
141
+ end
142
+
143
+ # Calculates hash code according to all attributes.
144
+ # @return [Integer] Hash code
145
+ def hash
146
+ [data, meta].hash
147
+ end
148
+
149
+ # Builds the object from hash
150
+ # @param [Hash] attributes Model attributes in the form of hash
151
+ # @return [Object] Returns the model itself
152
+ def self.build_from_hash(attributes)
153
+ return nil unless attributes.is_a?(Hash)
154
+ attributes = attributes.transform_keys(&:to_sym)
155
+ transformed_hash = {}
156
+ openapi_types.each_pair do |key, type|
157
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
158
+ transformed_hash["#{key}"] = nil
159
+ elsif type =~ /\AArray<(.*)>/i
160
+ # check to ensure the input is an array given that the attribute
161
+ # is documented as an array but the input is not
162
+ if attributes[attribute_map[key]].is_a?(Array)
163
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
164
+ end
165
+ elsif !attributes[attribute_map[key]].nil?
166
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
167
+ end
168
+ end
169
+ new(transformed_hash)
170
+ end
171
+
172
+ # Deserializes the data based on type
173
+ # @param string type Data type
174
+ # @param string value Value to be deserialized
175
+ # @return [Object] Deserialized data
176
+ def self._deserialize(type, value)
177
+ case type.to_sym
178
+ when :Time
179
+ Time.parse(value)
180
+ when :Date
181
+ Date.parse(value)
182
+ when :String
183
+ value.to_s
184
+ when :Integer
185
+ value.to_i
186
+ when :Float
187
+ value.to_f
188
+ when :Boolean
189
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
190
+ true
191
+ else
192
+ false
193
+ end
194
+ when :Object
195
+ # generic object (usually a Hash), return directly
196
+ value
197
+ when /\AArray<(?<inner_type>.+)>\z/
198
+ inner_type = Regexp.last_match[:inner_type]
199
+ value.map { |v| _deserialize(inner_type, v) }
200
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
201
+ k_type = Regexp.last_match[:k_type]
202
+ v_type = Regexp.last_match[:v_type]
203
+ {}.tap do |hash|
204
+ value.each do |k, v|
205
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
206
+ end
207
+ end
208
+ else # model
209
+ # models (e.g. Pet) or oneOf
210
+ klass = Zyphr.const_get(type)
211
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
212
+ end
213
+ end
214
+
215
+ # Returns the string representation of the object
216
+ # @return [String] String presentation of the object
217
+ def to_s
218
+ to_hash.to_s
219
+ end
220
+
221
+ # to_body is an alias to to_hash (backward compatibility)
222
+ # @return [Hash] Returns the object in the form of hash
223
+ def to_body
224
+ to_hash
225
+ end
226
+
227
+ # Returns the object in the form of hash
228
+ # @return [Hash] Returns the object in the form of hash
229
+ def to_hash
230
+ hash = {}
231
+ self.class.attribute_map.each_pair do |attr, param|
232
+ value = self.send(attr)
233
+ if value.nil?
234
+ is_nullable = self.class.openapi_nullable.include?(attr)
235
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
236
+ end
237
+
238
+ hash[param] = _to_hash(value)
239
+ end
240
+ hash
241
+ end
242
+
243
+ # Outputs non-array value in the form of hash
244
+ # For object, use to_hash. Otherwise, just return the value
245
+ # @param [Object] value Any valid value
246
+ # @return [Hash] Returns the value in the form of hash
247
+ def _to_hash(value)
248
+ if value.is_a?(Array)
249
+ value.compact.map { |v| _to_hash(v) }
250
+ elsif value.is_a?(Hash)
251
+ {}.tap do |hash|
252
+ value.each { |k, v| hash[k] = _to_hash(v) }
253
+ end
254
+ elsif value.respond_to? :to_hash
255
+ value.to_hash
256
+ else
257
+ value
258
+ end
259
+ end
260
+
261
+ end
262
+
263
+ end