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,373 @@
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
+ # A single DNS record that must be published for the sending domain to verify
18
+ class DnsRecord
19
+ # DNS record type
20
+ attr_accessor :type
21
+
22
+ # DNS record name (host)
23
+ attr_accessor :name
24
+
25
+ # DNS record value
26
+ attr_accessor :value
27
+
28
+ # What this record is for — useful for partial failure reasoning (e.g. \"SPF verified, DKIM #2 still pending\") instead of treating the set as opaque.
29
+ attr_accessor :purpose
30
+
31
+ # Whether this specific record has been observed in DNS
32
+ attr_accessor :verified
33
+
34
+ class EnumAttributeValidator
35
+ attr_reader :datatype
36
+ attr_reader :allowable_values
37
+
38
+ def initialize(datatype, allowable_values)
39
+ @allowable_values = allowable_values.map do |value|
40
+ case datatype.to_s
41
+ when /Integer/i
42
+ value.to_i
43
+ when /Float/i
44
+ value.to_f
45
+ else
46
+ value
47
+ end
48
+ end
49
+ end
50
+
51
+ def valid?(value)
52
+ !value || allowable_values.include?(value)
53
+ end
54
+ end
55
+
56
+ # Attribute mapping from ruby-style variable name to JSON key.
57
+ def self.attribute_map
58
+ {
59
+ :'type' => :'type',
60
+ :'name' => :'name',
61
+ :'value' => :'value',
62
+ :'purpose' => :'purpose',
63
+ :'verified' => :'verified'
64
+ }
65
+ end
66
+
67
+ # Returns attribute mapping this model knows about
68
+ def self.acceptable_attribute_map
69
+ attribute_map
70
+ end
71
+
72
+ # Returns all the JSON keys this model knows about
73
+ def self.acceptable_attributes
74
+ acceptable_attribute_map.values
75
+ end
76
+
77
+ # Attribute type mapping.
78
+ def self.openapi_types
79
+ {
80
+ :'type' => :'String',
81
+ :'name' => :'String',
82
+ :'value' => :'String',
83
+ :'purpose' => :'String',
84
+ :'verified' => :'Boolean'
85
+ }
86
+ end
87
+
88
+ # List of attributes with nullable: true
89
+ def self.openapi_nullable
90
+ Set.new([
91
+ ])
92
+ end
93
+
94
+ # Initializes the object
95
+ # @param [Hash] attributes Model attributes in the form of hash
96
+ def initialize(attributes = {})
97
+ if (!attributes.is_a?(Hash))
98
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::DnsRecord` initialize method"
99
+ end
100
+
101
+ # check to see if the attribute exists and convert string to symbol for hash key
102
+ acceptable_attribute_map = self.class.acceptable_attribute_map
103
+ attributes = attributes.each_with_object({}) { |(k, v), h|
104
+ if (!acceptable_attribute_map.key?(k.to_sym))
105
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::DnsRecord`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
106
+ end
107
+ h[k.to_sym] = v
108
+ }
109
+
110
+ if attributes.key?(:'type')
111
+ self.type = attributes[:'type']
112
+ else
113
+ self.type = nil
114
+ end
115
+
116
+ if attributes.key?(:'name')
117
+ self.name = attributes[:'name']
118
+ else
119
+ self.name = nil
120
+ end
121
+
122
+ if attributes.key?(:'value')
123
+ self.value = attributes[:'value']
124
+ else
125
+ self.value = nil
126
+ end
127
+
128
+ if attributes.key?(:'purpose')
129
+ self.purpose = attributes[:'purpose']
130
+ else
131
+ self.purpose = nil
132
+ end
133
+
134
+ if attributes.key?(:'verified')
135
+ self.verified = attributes[:'verified']
136
+ else
137
+ self.verified = nil
138
+ end
139
+ end
140
+
141
+ # Show invalid properties with the reasons. Usually used together with valid?
142
+ # @return Array for valid properties with the reasons
143
+ def list_invalid_properties
144
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
145
+ invalid_properties = Array.new
146
+ if @type.nil?
147
+ invalid_properties.push('invalid value for "type", type cannot be nil.')
148
+ end
149
+
150
+ if @name.nil?
151
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
152
+ end
153
+
154
+ if @value.nil?
155
+ invalid_properties.push('invalid value for "value", value cannot be nil.')
156
+ end
157
+
158
+ if @purpose.nil?
159
+ invalid_properties.push('invalid value for "purpose", purpose cannot be nil.')
160
+ end
161
+
162
+ if @verified.nil?
163
+ invalid_properties.push('invalid value for "verified", verified cannot be nil.')
164
+ end
165
+
166
+ invalid_properties
167
+ end
168
+
169
+ # Check to see if the all the properties in the model are valid
170
+ # @return true if the model is valid
171
+ def valid?
172
+ warn '[DEPRECATED] the `valid?` method is obsolete'
173
+ return false if @type.nil?
174
+ type_validator = EnumAttributeValidator.new('String', ["TXT", "CNAME"])
175
+ return false unless type_validator.valid?(@type)
176
+ return false if @name.nil?
177
+ return false if @value.nil?
178
+ return false if @purpose.nil?
179
+ purpose_validator = EnumAttributeValidator.new('String', ["domain_verification", "spf", "dmarc", "dkim"])
180
+ return false unless purpose_validator.valid?(@purpose)
181
+ return false if @verified.nil?
182
+ true
183
+ end
184
+
185
+ # Custom attribute writer method checking allowed values (enum).
186
+ # @param [Object] type Object to be assigned
187
+ def type=(type)
188
+ validator = EnumAttributeValidator.new('String', ["TXT", "CNAME"])
189
+ unless validator.valid?(type)
190
+ fail ArgumentError, "invalid value for \"type\", must be one of #{validator.allowable_values}."
191
+ end
192
+ @type = type
193
+ end
194
+
195
+ # Custom attribute writer method with validation
196
+ # @param [Object] name Value to be assigned
197
+ def name=(name)
198
+ if name.nil?
199
+ fail ArgumentError, 'name cannot be nil'
200
+ end
201
+
202
+ @name = name
203
+ end
204
+
205
+ # Custom attribute writer method with validation
206
+ # @param [Object] value Value to be assigned
207
+ def value=(value)
208
+ if value.nil?
209
+ fail ArgumentError, 'value cannot be nil'
210
+ end
211
+
212
+ @value = value
213
+ end
214
+
215
+ # Custom attribute writer method checking allowed values (enum).
216
+ # @param [Object] purpose Object to be assigned
217
+ def purpose=(purpose)
218
+ validator = EnumAttributeValidator.new('String', ["domain_verification", "spf", "dmarc", "dkim"])
219
+ unless validator.valid?(purpose)
220
+ fail ArgumentError, "invalid value for \"purpose\", must be one of #{validator.allowable_values}."
221
+ end
222
+ @purpose = purpose
223
+ end
224
+
225
+ # Custom attribute writer method with validation
226
+ # @param [Object] verified Value to be assigned
227
+ def verified=(verified)
228
+ if verified.nil?
229
+ fail ArgumentError, 'verified cannot be nil'
230
+ end
231
+
232
+ @verified = verified
233
+ end
234
+
235
+ # Checks equality by comparing each attribute.
236
+ # @param [Object] Object to be compared
237
+ def ==(o)
238
+ return true if self.equal?(o)
239
+ self.class == o.class &&
240
+ type == o.type &&
241
+ name == o.name &&
242
+ value == o.value &&
243
+ purpose == o.purpose &&
244
+ verified == o.verified
245
+ end
246
+
247
+ # @see the `==` method
248
+ # @param [Object] Object to be compared
249
+ def eql?(o)
250
+ self == o
251
+ end
252
+
253
+ # Calculates hash code according to all attributes.
254
+ # @return [Integer] Hash code
255
+ def hash
256
+ [type, name, value, purpose, verified].hash
257
+ end
258
+
259
+ # Builds the object from hash
260
+ # @param [Hash] attributes Model attributes in the form of hash
261
+ # @return [Object] Returns the model itself
262
+ def self.build_from_hash(attributes)
263
+ return nil unless attributes.is_a?(Hash)
264
+ attributes = attributes.transform_keys(&:to_sym)
265
+ transformed_hash = {}
266
+ openapi_types.each_pair do |key, type|
267
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
268
+ transformed_hash["#{key}"] = nil
269
+ elsif type =~ /\AArray<(.*)>/i
270
+ # check to ensure the input is an array given that the attribute
271
+ # is documented as an array but the input is not
272
+ if attributes[attribute_map[key]].is_a?(Array)
273
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
274
+ end
275
+ elsif !attributes[attribute_map[key]].nil?
276
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
277
+ end
278
+ end
279
+ new(transformed_hash)
280
+ end
281
+
282
+ # Deserializes the data based on type
283
+ # @param string type Data type
284
+ # @param string value Value to be deserialized
285
+ # @return [Object] Deserialized data
286
+ def self._deserialize(type, value)
287
+ case type.to_sym
288
+ when :Time
289
+ Time.parse(value)
290
+ when :Date
291
+ Date.parse(value)
292
+ when :String
293
+ value.to_s
294
+ when :Integer
295
+ value.to_i
296
+ when :Float
297
+ value.to_f
298
+ when :Boolean
299
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
300
+ true
301
+ else
302
+ false
303
+ end
304
+ when :Object
305
+ # generic object (usually a Hash), return directly
306
+ value
307
+ when /\AArray<(?<inner_type>.+)>\z/
308
+ inner_type = Regexp.last_match[:inner_type]
309
+ value.map { |v| _deserialize(inner_type, v) }
310
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
311
+ k_type = Regexp.last_match[:k_type]
312
+ v_type = Regexp.last_match[:v_type]
313
+ {}.tap do |hash|
314
+ value.each do |k, v|
315
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
316
+ end
317
+ end
318
+ else # model
319
+ # models (e.g. Pet) or oneOf
320
+ klass = Zyphr.const_get(type)
321
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
322
+ end
323
+ end
324
+
325
+ # Returns the string representation of the object
326
+ # @return [String] String presentation of the object
327
+ def to_s
328
+ to_hash.to_s
329
+ end
330
+
331
+ # to_body is an alias to to_hash (backward compatibility)
332
+ # @return [Hash] Returns the object in the form of hash
333
+ def to_body
334
+ to_hash
335
+ end
336
+
337
+ # Returns the object in the form of hash
338
+ # @return [Hash] Returns the object in the form of hash
339
+ def to_hash
340
+ hash = {}
341
+ self.class.attribute_map.each_pair do |attr, param|
342
+ value = self.send(attr)
343
+ if value.nil?
344
+ is_nullable = self.class.openapi_nullable.include?(attr)
345
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
346
+ end
347
+
348
+ hash[param] = _to_hash(value)
349
+ end
350
+ hash
351
+ end
352
+
353
+ # Outputs non-array value in the form of hash
354
+ # For object, use to_hash. Otherwise, just return the value
355
+ # @param [Object] value Any valid value
356
+ # @return [Hash] Returns the value in the form of hash
357
+ def _to_hash(value)
358
+ if value.is_a?(Array)
359
+ value.compact.map { |v| _to_hash(v) }
360
+ elsif value.is_a?(Hash)
361
+ {}.tap do |hash|
362
+ value.each { |k, v| hash[k] = _to_hash(v) }
363
+ end
364
+ elsif value.respond_to? :to_hash
365
+ value.to_hash
366
+ else
367
+ value
368
+ end
369
+ end
370
+
371
+ end
372
+
373
+ end
@@ -0,0 +1,265 @@
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 DomainListResponse
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' => :'Array<DomainResponse>',
44
+ :'meta' => :'DomainListResponseMeta'
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::DomainListResponse` 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::DomainListResponse`. 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
+ if (value = attributes[:'data']).is_a?(Array)
72
+ self.data = value
73
+ end
74
+ else
75
+ self.data = nil
76
+ end
77
+
78
+ if attributes.key?(:'meta')
79
+ self.meta = attributes[:'meta']
80
+ else
81
+ self.meta = nil
82
+ end
83
+ end
84
+
85
+ # Show invalid properties with the reasons. Usually used together with valid?
86
+ # @return Array for valid properties with the reasons
87
+ def list_invalid_properties
88
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
89
+ invalid_properties = Array.new
90
+ if @data.nil?
91
+ invalid_properties.push('invalid value for "data", data cannot be nil.')
92
+ end
93
+
94
+ if @meta.nil?
95
+ invalid_properties.push('invalid value for "meta", meta cannot be nil.')
96
+ end
97
+
98
+ invalid_properties
99
+ end
100
+
101
+ # Check to see if the all the properties in the model are valid
102
+ # @return true if the model is valid
103
+ def valid?
104
+ warn '[DEPRECATED] the `valid?` method is obsolete'
105
+ return false if @data.nil?
106
+ return false if @meta.nil?
107
+ true
108
+ end
109
+
110
+ # Custom attribute writer method with validation
111
+ # @param [Object] data Value to be assigned
112
+ def data=(data)
113
+ if data.nil?
114
+ fail ArgumentError, 'data cannot be nil'
115
+ end
116
+
117
+ @data = data
118
+ end
119
+
120
+ # Custom attribute writer method with validation
121
+ # @param [Object] meta Value to be assigned
122
+ def meta=(meta)
123
+ if meta.nil?
124
+ fail ArgumentError, 'meta cannot be nil'
125
+ end
126
+
127
+ @meta = meta
128
+ end
129
+
130
+ # Checks equality by comparing each attribute.
131
+ # @param [Object] Object to be compared
132
+ def ==(o)
133
+ return true if self.equal?(o)
134
+ self.class == o.class &&
135
+ data == o.data &&
136
+ meta == o.meta
137
+ end
138
+
139
+ # @see the `==` method
140
+ # @param [Object] Object to be compared
141
+ def eql?(o)
142
+ self == o
143
+ end
144
+
145
+ # Calculates hash code according to all attributes.
146
+ # @return [Integer] Hash code
147
+ def hash
148
+ [data, meta].hash
149
+ end
150
+
151
+ # Builds the object from hash
152
+ # @param [Hash] attributes Model attributes in the form of hash
153
+ # @return [Object] Returns the model itself
154
+ def self.build_from_hash(attributes)
155
+ return nil unless attributes.is_a?(Hash)
156
+ attributes = attributes.transform_keys(&:to_sym)
157
+ transformed_hash = {}
158
+ openapi_types.each_pair do |key, type|
159
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
160
+ transformed_hash["#{key}"] = nil
161
+ elsif type =~ /\AArray<(.*)>/i
162
+ # check to ensure the input is an array given that the attribute
163
+ # is documented as an array but the input is not
164
+ if attributes[attribute_map[key]].is_a?(Array)
165
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
166
+ end
167
+ elsif !attributes[attribute_map[key]].nil?
168
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
169
+ end
170
+ end
171
+ new(transformed_hash)
172
+ end
173
+
174
+ # Deserializes the data based on type
175
+ # @param string type Data type
176
+ # @param string value Value to be deserialized
177
+ # @return [Object] Deserialized data
178
+ def self._deserialize(type, value)
179
+ case type.to_sym
180
+ when :Time
181
+ Time.parse(value)
182
+ when :Date
183
+ Date.parse(value)
184
+ when :String
185
+ value.to_s
186
+ when :Integer
187
+ value.to_i
188
+ when :Float
189
+ value.to_f
190
+ when :Boolean
191
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
192
+ true
193
+ else
194
+ false
195
+ end
196
+ when :Object
197
+ # generic object (usually a Hash), return directly
198
+ value
199
+ when /\AArray<(?<inner_type>.+)>\z/
200
+ inner_type = Regexp.last_match[:inner_type]
201
+ value.map { |v| _deserialize(inner_type, v) }
202
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
203
+ k_type = Regexp.last_match[:k_type]
204
+ v_type = Regexp.last_match[:v_type]
205
+ {}.tap do |hash|
206
+ value.each do |k, v|
207
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
208
+ end
209
+ end
210
+ else # model
211
+ # models (e.g. Pet) or oneOf
212
+ klass = Zyphr.const_get(type)
213
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
214
+ end
215
+ end
216
+
217
+ # Returns the string representation of the object
218
+ # @return [String] String presentation of the object
219
+ def to_s
220
+ to_hash.to_s
221
+ end
222
+
223
+ # to_body is an alias to to_hash (backward compatibility)
224
+ # @return [Hash] Returns the object in the form of hash
225
+ def to_body
226
+ to_hash
227
+ end
228
+
229
+ # Returns the object in the form of hash
230
+ # @return [Hash] Returns the object in the form of hash
231
+ def to_hash
232
+ hash = {}
233
+ self.class.attribute_map.each_pair do |attr, param|
234
+ value = self.send(attr)
235
+ if value.nil?
236
+ is_nullable = self.class.openapi_nullable.include?(attr)
237
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
238
+ end
239
+
240
+ hash[param] = _to_hash(value)
241
+ end
242
+ hash
243
+ end
244
+
245
+ # Outputs non-array value in the form of hash
246
+ # For object, use to_hash. Otherwise, just return the value
247
+ # @param [Object] value Any valid value
248
+ # @return [Hash] Returns the value in the form of hash
249
+ def _to_hash(value)
250
+ if value.is_a?(Array)
251
+ value.compact.map { |v| _to_hash(v) }
252
+ elsif value.is_a?(Hash)
253
+ {}.tap do |hash|
254
+ value.each { |k, v| hash[k] = _to_hash(v) }
255
+ end
256
+ elsif value.respond_to? :to_hash
257
+ value.to_hash
258
+ else
259
+ value
260
+ end
261
+ end
262
+
263
+ end
264
+
265
+ end