zyphr 0.1.70 → 0.1.72

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,328 @@
1
+ =begin
2
+ #Zyphr API
3
+
4
+ #Zyphr is a developer platform for user authentication and transactional messaging. One API covers auth (passkeys, social sign-in, passwordless, MFA, sessions, organizations) plus email, push notifications, SMS, in-app messages, and webhooks. ## 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. > **Test keys are being retired.** `zy_test_*` keys are no longer issued, and existing ones stop working on **21 October 2026**. They never delivered mail — sends were mocked and marked sent without reaching a provider, so they could not verify domain authentication, rendering, or deliverability. To test your integration, use a `zy_live_*` key against a verified domain and send to an address you control. ## 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 ## Account Sending Status Every authenticated response carries the account's current sending state so you can surface it in your own tooling without a separate call: - `X-Account-Sending-Status`: `active`, `throttled`, or `frozen` - `X-Account-Sending-Status-Reason`: human-readable reason (present only when the status is `throttled` or `frozen`) This header is informational and non-blocking on non-send endpoints (reads, billing, and deliverability stay available). Send-capable endpoints additionally enforce the state: a frozen account receives `403 account_frozen` and a throttled account receives `429 account_throttled`, both with the reason in the error message. ## 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 CreateInboxRequest
18
+ # A verified domain with inbound email enabled
19
+ attr_accessor :domain_id
20
+
21
+ # The part before `@`. Letters, numbers, `.`, `_` and `-`; cannot start or end with `.` or contain `..`. Stored lowercase. `dmarc-reports` is reserved. Mail to `<local_part>+anything@` also reaches the inbox.
22
+ attr_accessor :local_part
23
+
24
+ attr_accessor :name
25
+
26
+ # Display name for replies. No control characters and none of `\" \\ , ; @ : < >`.
27
+ attr_accessor :from_name
28
+
29
+ # Attribute mapping from ruby-style variable name to JSON key.
30
+ def self.attribute_map
31
+ {
32
+ :'domain_id' => :'domain_id',
33
+ :'local_part' => :'local_part',
34
+ :'name' => :'name',
35
+ :'from_name' => :'from_name'
36
+ }
37
+ end
38
+
39
+ # Returns attribute mapping this model knows about
40
+ def self.acceptable_attribute_map
41
+ attribute_map
42
+ end
43
+
44
+ # Returns all the JSON keys this model knows about
45
+ def self.acceptable_attributes
46
+ acceptable_attribute_map.values
47
+ end
48
+
49
+ # Attribute type mapping.
50
+ def self.openapi_types
51
+ {
52
+ :'domain_id' => :'String',
53
+ :'local_part' => :'String',
54
+ :'name' => :'String',
55
+ :'from_name' => :'String'
56
+ }
57
+ end
58
+
59
+ # List of attributes with nullable: true
60
+ def self.openapi_nullable
61
+ Set.new([
62
+ :'from_name'
63
+ ])
64
+ end
65
+
66
+ # Initializes the object
67
+ # @param [Hash] attributes Model attributes in the form of hash
68
+ def initialize(attributes = {})
69
+ if (!attributes.is_a?(Hash))
70
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::CreateInboxRequest` initialize method"
71
+ end
72
+
73
+ # check to see if the attribute exists and convert string to symbol for hash key
74
+ acceptable_attribute_map = self.class.acceptable_attribute_map
75
+ attributes = attributes.each_with_object({}) { |(k, v), h|
76
+ if (!acceptable_attribute_map.key?(k.to_sym))
77
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::CreateInboxRequest`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
78
+ end
79
+ h[k.to_sym] = v
80
+ }
81
+
82
+ if attributes.key?(:'domain_id')
83
+ self.domain_id = attributes[:'domain_id']
84
+ else
85
+ self.domain_id = nil
86
+ end
87
+
88
+ if attributes.key?(:'local_part')
89
+ self.local_part = attributes[:'local_part']
90
+ else
91
+ self.local_part = nil
92
+ end
93
+
94
+ if attributes.key?(:'name')
95
+ self.name = attributes[:'name']
96
+ end
97
+
98
+ if attributes.key?(:'from_name')
99
+ self.from_name = attributes[:'from_name']
100
+ end
101
+ end
102
+
103
+ # Show invalid properties with the reasons. Usually used together with valid?
104
+ # @return Array for valid properties with the reasons
105
+ def list_invalid_properties
106
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
107
+ invalid_properties = Array.new
108
+ if @domain_id.nil?
109
+ invalid_properties.push('invalid value for "domain_id", domain_id cannot be nil.')
110
+ end
111
+
112
+ if @local_part.nil?
113
+ invalid_properties.push('invalid value for "local_part", local_part cannot be nil.')
114
+ end
115
+
116
+ if @local_part.to_s.length > 64
117
+ invalid_properties.push('invalid value for "local_part", the character length must be smaller than or equal to 64.')
118
+ end
119
+
120
+ if !@name.nil? && @name.to_s.length > 64
121
+ invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 64.')
122
+ end
123
+
124
+ if !@from_name.nil? && @from_name.to_s.length > 78
125
+ invalid_properties.push('invalid value for "from_name", the character length must be smaller than or equal to 78.')
126
+ end
127
+
128
+ invalid_properties
129
+ end
130
+
131
+ # Check to see if the all the properties in the model are valid
132
+ # @return true if the model is valid
133
+ def valid?
134
+ warn '[DEPRECATED] the `valid?` method is obsolete'
135
+ return false if @domain_id.nil?
136
+ return false if @local_part.nil?
137
+ return false if @local_part.to_s.length > 64
138
+ return false if !@name.nil? && @name.to_s.length > 64
139
+ return false if !@from_name.nil? && @from_name.to_s.length > 78
140
+ true
141
+ end
142
+
143
+ # Custom attribute writer method with validation
144
+ # @param [Object] domain_id Value to be assigned
145
+ def domain_id=(domain_id)
146
+ if domain_id.nil?
147
+ fail ArgumentError, 'domain_id cannot be nil'
148
+ end
149
+
150
+ @domain_id = domain_id
151
+ end
152
+
153
+ # Custom attribute writer method with validation
154
+ # @param [Object] local_part Value to be assigned
155
+ def local_part=(local_part)
156
+ if local_part.nil?
157
+ fail ArgumentError, 'local_part cannot be nil'
158
+ end
159
+
160
+ if local_part.to_s.length > 64
161
+ fail ArgumentError, 'invalid value for "local_part", the character length must be smaller than or equal to 64.'
162
+ end
163
+
164
+ @local_part = local_part
165
+ end
166
+
167
+ # Custom attribute writer method with validation
168
+ # @param [Object] name Value to be assigned
169
+ def name=(name)
170
+ if name.nil?
171
+ fail ArgumentError, 'name cannot be nil'
172
+ end
173
+
174
+ if name.to_s.length > 64
175
+ fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 64.'
176
+ end
177
+
178
+ @name = name
179
+ end
180
+
181
+ # Custom attribute writer method with validation
182
+ # @param [Object] from_name Value to be assigned
183
+ def from_name=(from_name)
184
+ if !from_name.nil? && from_name.to_s.length > 78
185
+ fail ArgumentError, 'invalid value for "from_name", the character length must be smaller than or equal to 78.'
186
+ end
187
+
188
+ @from_name = from_name
189
+ end
190
+
191
+ # Checks equality by comparing each attribute.
192
+ # @param [Object] Object to be compared
193
+ def ==(o)
194
+ return true if self.equal?(o)
195
+ self.class == o.class &&
196
+ domain_id == o.domain_id &&
197
+ local_part == o.local_part &&
198
+ name == o.name &&
199
+ from_name == o.from_name
200
+ end
201
+
202
+ # @see the `==` method
203
+ # @param [Object] Object to be compared
204
+ def eql?(o)
205
+ self == o
206
+ end
207
+
208
+ # Calculates hash code according to all attributes.
209
+ # @return [Integer] Hash code
210
+ def hash
211
+ [domain_id, local_part, name, from_name].hash
212
+ end
213
+
214
+ # Builds the object from hash
215
+ # @param [Hash] attributes Model attributes in the form of hash
216
+ # @return [Object] Returns the model itself
217
+ def self.build_from_hash(attributes)
218
+ return nil unless attributes.is_a?(Hash)
219
+ attributes = attributes.transform_keys(&:to_sym)
220
+ transformed_hash = {}
221
+ openapi_types.each_pair do |key, type|
222
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
223
+ transformed_hash["#{key}"] = nil
224
+ elsif type =~ /\AArray<(.*)>/i
225
+ # check to ensure the input is an array given that the attribute
226
+ # is documented as an array but the input is not
227
+ if attributes[attribute_map[key]].is_a?(Array)
228
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
229
+ end
230
+ elsif !attributes[attribute_map[key]].nil?
231
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
232
+ end
233
+ end
234
+ new(transformed_hash)
235
+ end
236
+
237
+ # Deserializes the data based on type
238
+ # @param string type Data type
239
+ # @param string value Value to be deserialized
240
+ # @return [Object] Deserialized data
241
+ def self._deserialize(type, value)
242
+ case type.to_sym
243
+ when :Time
244
+ Time.parse(value)
245
+ when :Date
246
+ Date.parse(value)
247
+ when :String
248
+ value.to_s
249
+ when :Integer
250
+ value.to_i
251
+ when :Float
252
+ value.to_f
253
+ when :Boolean
254
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
255
+ true
256
+ else
257
+ false
258
+ end
259
+ when :Object
260
+ # generic object (usually a Hash), return directly
261
+ value
262
+ when /\AArray<(?<inner_type>.+)>\z/
263
+ inner_type = Regexp.last_match[:inner_type]
264
+ value.map { |v| _deserialize(inner_type, v) }
265
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
266
+ k_type = Regexp.last_match[:k_type]
267
+ v_type = Regexp.last_match[:v_type]
268
+ {}.tap do |hash|
269
+ value.each do |k, v|
270
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
271
+ end
272
+ end
273
+ else # model
274
+ # models (e.g. Pet) or oneOf
275
+ klass = Zyphr.const_get(type)
276
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
277
+ end
278
+ end
279
+
280
+ # Returns the string representation of the object
281
+ # @return [String] String presentation of the object
282
+ def to_s
283
+ to_hash.to_s
284
+ end
285
+
286
+ # to_body is an alias to to_hash (backward compatibility)
287
+ # @return [Hash] Returns the object in the form of hash
288
+ def to_body
289
+ to_hash
290
+ end
291
+
292
+ # Returns the object in the form of hash
293
+ # @return [Hash] Returns the object in the form of hash
294
+ def to_hash
295
+ hash = {}
296
+ self.class.attribute_map.each_pair do |attr, param|
297
+ value = self.send(attr)
298
+ if value.nil?
299
+ is_nullable = self.class.openapi_nullable.include?(attr)
300
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
301
+ end
302
+
303
+ hash[param] = _to_hash(value)
304
+ end
305
+ hash
306
+ end
307
+
308
+ # Outputs non-array value in the form of hash
309
+ # For object, use to_hash. Otherwise, just return the value
310
+ # @param [Object] value Any valid value
311
+ # @return [Hash] Returns the value in the form of hash
312
+ def _to_hash(value)
313
+ if value.is_a?(Array)
314
+ value.compact.map { |v| _to_hash(v) }
315
+ elsif value.is_a?(Hash)
316
+ {}.tap do |hash|
317
+ value.each { |k, v| hash[k] = _to_hash(v) }
318
+ end
319
+ elsif value.respond_to? :to_hash
320
+ value.to_hash
321
+ else
322
+ value
323
+ end
324
+ end
325
+
326
+ end
327
+
328
+ end
@@ -20,6 +20,9 @@ module Zyphr
20
20
  # The receiving address the mail was sent to
21
21
  attr_accessor :to_email
22
22
 
23
+ # The inbox the mail was addressed to, or null when the domain has no inboxes (or the inbox was deleted)
24
+ attr_accessor :inbox_id
25
+
23
26
  attr_accessor :from
24
27
 
25
28
  attr_accessor :cc
@@ -78,6 +81,7 @@ module Zyphr
78
81
  {
79
82
  :'id' => :'id',
80
83
  :'to_email' => :'to_email',
84
+ :'inbox_id' => :'inbox_id',
81
85
  :'from' => :'from',
82
86
  :'cc' => :'cc',
83
87
  :'subject' => :'subject',
@@ -110,6 +114,7 @@ module Zyphr
110
114
  {
111
115
  :'id' => :'String',
112
116
  :'to_email' => :'String',
117
+ :'inbox_id' => :'String',
113
118
  :'from' => :'InboundEmailFrom',
114
119
  :'cc' => :'Array<String>',
115
120
  :'subject' => :'String',
@@ -130,6 +135,7 @@ module Zyphr
130
135
  # List of attributes with nullable: true
131
136
  def self.openapi_nullable
132
137
  Set.new([
138
+ :'inbox_id',
133
139
  :'subject',
134
140
  :'text_body',
135
141
  :'html_body',
@@ -165,6 +171,10 @@ module Zyphr
165
171
  self.to_email = attributes[:'to_email']
166
172
  end
167
173
 
174
+ if attributes.key?(:'inbox_id')
175
+ self.inbox_id = attributes[:'inbox_id']
176
+ end
177
+
168
178
  if attributes.key?(:'from')
169
179
  self.from = attributes[:'from']
170
180
  end
@@ -296,6 +306,7 @@ module Zyphr
296
306
  self.class == o.class &&
297
307
  id == o.id &&
298
308
  to_email == o.to_email &&
309
+ inbox_id == o.inbox_id &&
299
310
  from == o.from &&
300
311
  cc == o.cc &&
301
312
  subject == o.subject &&
@@ -321,7 +332,7 @@ module Zyphr
321
332
  # Calculates hash code according to all attributes.
322
333
  # @return [Integer] Hash code
323
334
  def hash
324
- [id, to_email, from, cc, subject, text_body, html_body, in_reply_to, replied_to_message_id, verified, spf_verdict, dkim_verdict, dmarc_verdict, status, attachments, created_at].hash
335
+ [id, to_email, inbox_id, from, cc, subject, text_body, html_body, in_reply_to, replied_to_message_id, verified, spf_verdict, dkim_verdict, dmarc_verdict, status, attachments, created_at].hash
325
336
  end
326
337
 
327
338
  # Builds the object from hash
@@ -0,0 +1,278 @@
1
+ =begin
2
+ #Zyphr API
3
+
4
+ #Zyphr is a developer platform for user authentication and transactional messaging. One API covers auth (passkeys, social sign-in, passwordless, MFA, sessions, organizations) plus email, push notifications, SMS, in-app messages, and webhooks. ## 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. > **Test keys are being retired.** `zy_test_*` keys are no longer issued, and existing ones stop working on **21 October 2026**. They never delivered mail — sends were mocked and marked sent without reaching a provider, so they could not verify domain authentication, rendering, or deliverability. To test your integration, use a `zy_live_*` key against a verified domain and send to an address you control. ## 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 ## Account Sending Status Every authenticated response carries the account's current sending state so you can surface it in your own tooling without a separate call: - `X-Account-Sending-Status`: `active`, `throttled`, or `frozen` - `X-Account-Sending-Status-Reason`: human-readable reason (present only when the status is `throttled` or `frozen`) This header is informational and non-blocking on non-send endpoints (reads, billing, and deliverability stay available). Send-capable endpoints additionally enforce the state: a frozen account receives `403 account_frozen` and a throttled account receives `429 account_throttled`, both with the reason in the error message. ## 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 Inbox
18
+ attr_accessor :id
19
+
20
+ # The inbox's receiving address
21
+ attr_accessor :email_address
22
+
23
+ attr_accessor :domain_id
24
+
25
+ # Internal name (defaults to the address)
26
+ attr_accessor :name
27
+
28
+ # Display name recipients see on replies
29
+ attr_accessor :from_name
30
+
31
+ attr_accessor :created_at
32
+
33
+ attr_accessor :updated_at
34
+
35
+ # Attribute mapping from ruby-style variable name to JSON key.
36
+ def self.attribute_map
37
+ {
38
+ :'id' => :'id',
39
+ :'email_address' => :'email_address',
40
+ :'domain_id' => :'domain_id',
41
+ :'name' => :'name',
42
+ :'from_name' => :'from_name',
43
+ :'created_at' => :'created_at',
44
+ :'updated_at' => :'updated_at'
45
+ }
46
+ end
47
+
48
+ # Returns attribute mapping this model knows about
49
+ def self.acceptable_attribute_map
50
+ attribute_map
51
+ end
52
+
53
+ # Returns all the JSON keys this model knows about
54
+ def self.acceptable_attributes
55
+ acceptable_attribute_map.values
56
+ end
57
+
58
+ # Attribute type mapping.
59
+ def self.openapi_types
60
+ {
61
+ :'id' => :'String',
62
+ :'email_address' => :'String',
63
+ :'domain_id' => :'String',
64
+ :'name' => :'String',
65
+ :'from_name' => :'String',
66
+ :'created_at' => :'Time',
67
+ :'updated_at' => :'Time'
68
+ }
69
+ end
70
+
71
+ # List of attributes with nullable: true
72
+ def self.openapi_nullable
73
+ Set.new([
74
+ :'from_name',
75
+ ])
76
+ end
77
+
78
+ # Initializes the object
79
+ # @param [Hash] attributes Model attributes in the form of hash
80
+ def initialize(attributes = {})
81
+ if (!attributes.is_a?(Hash))
82
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::Inbox` initialize method"
83
+ end
84
+
85
+ # check to see if the attribute exists and convert string to symbol for hash key
86
+ acceptable_attribute_map = self.class.acceptable_attribute_map
87
+ attributes = attributes.each_with_object({}) { |(k, v), h|
88
+ if (!acceptable_attribute_map.key?(k.to_sym))
89
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::Inbox`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
90
+ end
91
+ h[k.to_sym] = v
92
+ }
93
+
94
+ if attributes.key?(:'id')
95
+ self.id = attributes[:'id']
96
+ end
97
+
98
+ if attributes.key?(:'email_address')
99
+ self.email_address = attributes[:'email_address']
100
+ end
101
+
102
+ if attributes.key?(:'domain_id')
103
+ self.domain_id = attributes[:'domain_id']
104
+ end
105
+
106
+ if attributes.key?(:'name')
107
+ self.name = attributes[:'name']
108
+ end
109
+
110
+ if attributes.key?(:'from_name')
111
+ self.from_name = attributes[:'from_name']
112
+ end
113
+
114
+ if attributes.key?(:'created_at')
115
+ self.created_at = attributes[:'created_at']
116
+ end
117
+
118
+ if attributes.key?(:'updated_at')
119
+ self.updated_at = attributes[:'updated_at']
120
+ end
121
+ end
122
+
123
+ # Show invalid properties with the reasons. Usually used together with valid?
124
+ # @return Array for valid properties with the reasons
125
+ def list_invalid_properties
126
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
127
+ invalid_properties = Array.new
128
+ invalid_properties
129
+ end
130
+
131
+ # Check to see if the all the properties in the model are valid
132
+ # @return true if the model is valid
133
+ def valid?
134
+ warn '[DEPRECATED] the `valid?` method is obsolete'
135
+ true
136
+ end
137
+
138
+ # Checks equality by comparing each attribute.
139
+ # @param [Object] Object to be compared
140
+ def ==(o)
141
+ return true if self.equal?(o)
142
+ self.class == o.class &&
143
+ id == o.id &&
144
+ email_address == o.email_address &&
145
+ domain_id == o.domain_id &&
146
+ name == o.name &&
147
+ from_name == o.from_name &&
148
+ created_at == o.created_at &&
149
+ updated_at == o.updated_at
150
+ end
151
+
152
+ # @see the `==` method
153
+ # @param [Object] Object to be compared
154
+ def eql?(o)
155
+ self == o
156
+ end
157
+
158
+ # Calculates hash code according to all attributes.
159
+ # @return [Integer] Hash code
160
+ def hash
161
+ [id, email_address, domain_id, name, from_name, created_at, updated_at].hash
162
+ end
163
+
164
+ # Builds the object from hash
165
+ # @param [Hash] attributes Model attributes in the form of hash
166
+ # @return [Object] Returns the model itself
167
+ def self.build_from_hash(attributes)
168
+ return nil unless attributes.is_a?(Hash)
169
+ attributes = attributes.transform_keys(&:to_sym)
170
+ transformed_hash = {}
171
+ openapi_types.each_pair do |key, type|
172
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
173
+ transformed_hash["#{key}"] = nil
174
+ elsif type =~ /\AArray<(.*)>/i
175
+ # check to ensure the input is an array given that the attribute
176
+ # is documented as an array but the input is not
177
+ if attributes[attribute_map[key]].is_a?(Array)
178
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
179
+ end
180
+ elsif !attributes[attribute_map[key]].nil?
181
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
182
+ end
183
+ end
184
+ new(transformed_hash)
185
+ end
186
+
187
+ # Deserializes the data based on type
188
+ # @param string type Data type
189
+ # @param string value Value to be deserialized
190
+ # @return [Object] Deserialized data
191
+ def self._deserialize(type, value)
192
+ case type.to_sym
193
+ when :Time
194
+ Time.parse(value)
195
+ when :Date
196
+ Date.parse(value)
197
+ when :String
198
+ value.to_s
199
+ when :Integer
200
+ value.to_i
201
+ when :Float
202
+ value.to_f
203
+ when :Boolean
204
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
205
+ true
206
+ else
207
+ false
208
+ end
209
+ when :Object
210
+ # generic object (usually a Hash), return directly
211
+ value
212
+ when /\AArray<(?<inner_type>.+)>\z/
213
+ inner_type = Regexp.last_match[:inner_type]
214
+ value.map { |v| _deserialize(inner_type, v) }
215
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
216
+ k_type = Regexp.last_match[:k_type]
217
+ v_type = Regexp.last_match[:v_type]
218
+ {}.tap do |hash|
219
+ value.each do |k, v|
220
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
221
+ end
222
+ end
223
+ else # model
224
+ # models (e.g. Pet) or oneOf
225
+ klass = Zyphr.const_get(type)
226
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
227
+ end
228
+ end
229
+
230
+ # Returns the string representation of the object
231
+ # @return [String] String presentation of the object
232
+ def to_s
233
+ to_hash.to_s
234
+ end
235
+
236
+ # to_body is an alias to to_hash (backward compatibility)
237
+ # @return [Hash] Returns the object in the form of hash
238
+ def to_body
239
+ to_hash
240
+ end
241
+
242
+ # Returns the object in the form of hash
243
+ # @return [Hash] Returns the object in the form of hash
244
+ def to_hash
245
+ hash = {}
246
+ self.class.attribute_map.each_pair do |attr, param|
247
+ value = self.send(attr)
248
+ if value.nil?
249
+ is_nullable = self.class.openapi_nullable.include?(attr)
250
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
251
+ end
252
+
253
+ hash[param] = _to_hash(value)
254
+ end
255
+ hash
256
+ end
257
+
258
+ # Outputs non-array value in the form of hash
259
+ # For object, use to_hash. Otherwise, just return the value
260
+ # @param [Object] value Any valid value
261
+ # @return [Hash] Returns the value in the form of hash
262
+ def _to_hash(value)
263
+ if value.is_a?(Array)
264
+ value.compact.map { |v| _to_hash(v) }
265
+ elsif value.is_a?(Hash)
266
+ {}.tap do |hash|
267
+ value.each { |k, v| hash[k] = _to_hash(v) }
268
+ end
269
+ elsif value.respond_to? :to_hash
270
+ value.to_hash
271
+ else
272
+ value
273
+ end
274
+ end
275
+
276
+ end
277
+
278
+ end