zyphr 0.1.75 → 0.1.76

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 (83) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +48 -1
  3. data/docs/CreateInboxLabelRequest.md +20 -0
  4. data/docs/Draft.md +36 -0
  5. data/docs/DraftAddress.md +20 -0
  6. data/docs/DraftListResponse.md +20 -0
  7. data/docs/DraftRequest.md +30 -0
  8. data/docs/DraftResponse.md +20 -0
  9. data/docs/ForwardEmailRequest.md +34 -0
  10. data/docs/InboundEmailApi.md +1853 -157
  11. data/docs/InboxLabel.md +26 -0
  12. data/docs/InboxLabelListResponse.md +20 -0
  13. data/docs/InboxLabelResponse.md +20 -0
  14. data/docs/{ReplyToInboundEmailRequest.md → ReplyEmailRequest.md} +3 -3
  15. data/docs/Thread.md +40 -0
  16. data/docs/ThreadEmail.md +38 -0
  17. data/docs/ThreadEmailAttachmentsInner.md +24 -0
  18. data/docs/ThreadEmailFrom.md +20 -0
  19. data/docs/ThreadEmailListResponse.md +20 -0
  20. data/docs/ThreadEmailResponse.md +20 -0
  21. data/docs/ThreadFolder.md +15 -0
  22. data/docs/ThreadLabelsInner.md +22 -0
  23. data/docs/ThreadLabelsRequest.md +18 -0
  24. data/docs/ThreadListResponse.md +20 -0
  25. data/docs/ThreadListResponseMeta.md +20 -0
  26. data/docs/ThreadResponse.md +20 -0
  27. data/docs/UpdateInboxLabelRequest.md +20 -0
  28. data/docs/UpdateThreadRequest.md +22 -0
  29. data/lib/zyphr/api/inbound_email_api.rb +1768 -168
  30. data/lib/zyphr/models/create_inbox_label_request.rb +272 -0
  31. data/lib/zyphr/models/draft.rb +375 -0
  32. data/lib/zyphr/models/draft_address.rb +249 -0
  33. data/lib/zyphr/models/draft_list_response.rb +231 -0
  34. data/lib/zyphr/models/draft_request.rb +299 -0
  35. data/lib/zyphr/models/draft_response.rb +229 -0
  36. data/lib/zyphr/models/forward_email_request.rb +393 -0
  37. data/lib/zyphr/models/inbox_label.rb +258 -0
  38. data/lib/zyphr/models/inbox_label_list_response.rb +231 -0
  39. data/lib/zyphr/models/inbox_label_response.rb +229 -0
  40. data/lib/zyphr/models/{reply_to_inbound_email_request.rb → reply_email_request.rb} +4 -3
  41. data/lib/zyphr/models/thread.rb +352 -0
  42. data/lib/zyphr/models/thread_email.rb +353 -0
  43. data/lib/zyphr/models/thread_email_attachments_inner.rb +248 -0
  44. data/lib/zyphr/models/thread_email_from.rb +230 -0
  45. data/lib/zyphr/models/thread_email_list_response.rb +231 -0
  46. data/lib/zyphr/models/thread_email_response.rb +229 -0
  47. data/lib/zyphr/models/thread_folder.rb +43 -0
  48. data/lib/zyphr/models/thread_labels_inner.rb +239 -0
  49. data/lib/zyphr/models/thread_labels_request.rb +248 -0
  50. data/lib/zyphr/models/thread_list_response.rb +231 -0
  51. data/lib/zyphr/models/thread_list_response_meta.rb +237 -0
  52. data/lib/zyphr/models/thread_response.rb +229 -0
  53. data/lib/zyphr/models/update_inbox_label_request.rb +264 -0
  54. data/lib/zyphr/models/update_thread_request.rb +262 -0
  55. data/lib/zyphr.rb +25 -1
  56. data/spec/api/inbound_email_api_spec.rb +292 -1
  57. data/spec/models/create_inbox_label_request_spec.rb +42 -0
  58. data/spec/models/draft_address_spec.rb +42 -0
  59. data/spec/models/draft_list_response_spec.rb +42 -0
  60. data/spec/models/draft_request_spec.rb +72 -0
  61. data/spec/models/draft_response_spec.rb +42 -0
  62. data/spec/models/draft_spec.rb +90 -0
  63. data/spec/models/forward_email_request_spec.rb +88 -0
  64. data/spec/models/inbox_label_list_response_spec.rb +42 -0
  65. data/spec/models/inbox_label_response_spec.rb +42 -0
  66. data/spec/models/inbox_label_spec.rb +60 -0
  67. data/spec/models/{reply_to_inbound_email_request_spec.rb → reply_email_request_spec.rb} +6 -6
  68. data/spec/models/thread_email_attachments_inner_spec.rb +54 -0
  69. data/spec/models/thread_email_from_spec.rb +42 -0
  70. data/spec/models/thread_email_list_response_spec.rb +42 -0
  71. data/spec/models/thread_email_response_spec.rb +42 -0
  72. data/spec/models/thread_email_spec.rb +100 -0
  73. data/spec/models/thread_folder_spec.rb +30 -0
  74. data/spec/models/thread_labels_inner_spec.rb +48 -0
  75. data/spec/models/thread_labels_request_spec.rb +36 -0
  76. data/spec/models/thread_list_response_meta_spec.rb +42 -0
  77. data/spec/models/thread_list_response_spec.rb +42 -0
  78. data/spec/models/thread_response_spec.rb +42 -0
  79. data/spec/models/thread_spec.rb +102 -0
  80. data/spec/models/update_inbox_label_request_spec.rb +42 -0
  81. data/spec/models/update_thread_request_spec.rb +48 -0
  82. data/zyphr.gemspec +1 -1
  83. metadata +102 -6
@@ -0,0 +1,299 @@
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
+ # Every field is optional and `null` clears it. A draft with a `thread_id` is a reply, so it can't have `to` or `subject`.
18
+ class DraftRequest
19
+ attr_accessor :thread_id
20
+
21
+ # A plain email string is also accepted.
22
+ attr_accessor :from
23
+
24
+ # One recipient; a plain email string is also accepted.
25
+ attr_accessor :to
26
+
27
+ attr_accessor :reply_to
28
+
29
+ attr_accessor :subject
30
+
31
+ attr_accessor :text
32
+
33
+ attr_accessor :html
34
+
35
+ # Attribute mapping from ruby-style variable name to JSON key.
36
+ def self.attribute_map
37
+ {
38
+ :'thread_id' => :'thread_id',
39
+ :'from' => :'from',
40
+ :'to' => :'to',
41
+ :'reply_to' => :'reply_to',
42
+ :'subject' => :'subject',
43
+ :'text' => :'text',
44
+ :'html' => :'html'
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
+ :'thread_id' => :'String',
62
+ :'from' => :'EmailAddress',
63
+ :'to' => :'EmailAddress',
64
+ :'reply_to' => :'String',
65
+ :'subject' => :'String',
66
+ :'text' => :'String',
67
+ :'html' => :'String'
68
+ }
69
+ end
70
+
71
+ # List of attributes with nullable: true
72
+ def self.openapi_nullable
73
+ Set.new([
74
+ :'thread_id',
75
+ :'from',
76
+ :'to',
77
+ :'reply_to',
78
+ :'subject',
79
+ :'text',
80
+ :'html'
81
+ ])
82
+ end
83
+
84
+ # Initializes the object
85
+ # @param [Hash] attributes Model attributes in the form of hash
86
+ def initialize(attributes = {})
87
+ if (!attributes.is_a?(Hash))
88
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::DraftRequest` initialize method"
89
+ end
90
+
91
+ # check to see if the attribute exists and convert string to symbol for hash key
92
+ acceptable_attribute_map = self.class.acceptable_attribute_map
93
+ attributes = attributes.each_with_object({}) { |(k, v), h|
94
+ if (!acceptable_attribute_map.key?(k.to_sym))
95
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::DraftRequest`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
96
+ end
97
+ h[k.to_sym] = v
98
+ }
99
+
100
+ if attributes.key?(:'thread_id')
101
+ self.thread_id = attributes[:'thread_id']
102
+ end
103
+
104
+ if attributes.key?(:'from')
105
+ self.from = attributes[:'from']
106
+ end
107
+
108
+ if attributes.key?(:'to')
109
+ self.to = attributes[:'to']
110
+ end
111
+
112
+ if attributes.key?(:'reply_to')
113
+ self.reply_to = attributes[:'reply_to']
114
+ end
115
+
116
+ if attributes.key?(:'subject')
117
+ self.subject = attributes[:'subject']
118
+ end
119
+
120
+ if attributes.key?(:'text')
121
+ self.text = attributes[:'text']
122
+ end
123
+
124
+ if attributes.key?(:'html')
125
+ self.html = attributes[:'html']
126
+ end
127
+ end
128
+
129
+ # Show invalid properties with the reasons. Usually used together with valid?
130
+ # @return Array for valid properties with the reasons
131
+ def list_invalid_properties
132
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
133
+ invalid_properties = Array.new
134
+ if !@subject.nil? && @subject.to_s.length > 998
135
+ invalid_properties.push('invalid value for "subject", the character length must be smaller than or equal to 998.')
136
+ end
137
+
138
+ invalid_properties
139
+ end
140
+
141
+ # Check to see if the all the properties in the model are valid
142
+ # @return true if the model is valid
143
+ def valid?
144
+ warn '[DEPRECATED] the `valid?` method is obsolete'
145
+ return false if !@subject.nil? && @subject.to_s.length > 998
146
+ true
147
+ end
148
+
149
+ # Custom attribute writer method with validation
150
+ # @param [Object] subject Value to be assigned
151
+ def subject=(subject)
152
+ if !subject.nil? && subject.to_s.length > 998
153
+ fail ArgumentError, 'invalid value for "subject", the character length must be smaller than or equal to 998.'
154
+ end
155
+
156
+ @subject = subject
157
+ end
158
+
159
+ # Checks equality by comparing each attribute.
160
+ # @param [Object] Object to be compared
161
+ def ==(o)
162
+ return true if self.equal?(o)
163
+ self.class == o.class &&
164
+ thread_id == o.thread_id &&
165
+ from == o.from &&
166
+ to == o.to &&
167
+ reply_to == o.reply_to &&
168
+ subject == o.subject &&
169
+ text == o.text &&
170
+ html == o.html
171
+ end
172
+
173
+ # @see the `==` method
174
+ # @param [Object] Object to be compared
175
+ def eql?(o)
176
+ self == o
177
+ end
178
+
179
+ # Calculates hash code according to all attributes.
180
+ # @return [Integer] Hash code
181
+ def hash
182
+ [thread_id, from, to, reply_to, subject, text, html].hash
183
+ end
184
+
185
+ # Builds the object from hash
186
+ # @param [Hash] attributes Model attributes in the form of hash
187
+ # @return [Object] Returns the model itself
188
+ def self.build_from_hash(attributes)
189
+ return nil unless attributes.is_a?(Hash)
190
+ attributes = attributes.transform_keys(&:to_sym)
191
+ transformed_hash = {}
192
+ openapi_types.each_pair do |key, type|
193
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
194
+ transformed_hash["#{key}"] = nil
195
+ elsif type =~ /\AArray<(.*)>/i
196
+ # check to ensure the input is an array given that the attribute
197
+ # is documented as an array but the input is not
198
+ if attributes[attribute_map[key]].is_a?(Array)
199
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
200
+ end
201
+ elsif !attributes[attribute_map[key]].nil?
202
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
203
+ end
204
+ end
205
+ new(transformed_hash)
206
+ end
207
+
208
+ # Deserializes the data based on type
209
+ # @param string type Data type
210
+ # @param string value Value to be deserialized
211
+ # @return [Object] Deserialized data
212
+ def self._deserialize(type, value)
213
+ case type.to_sym
214
+ when :Time
215
+ Time.parse(value)
216
+ when :Date
217
+ Date.parse(value)
218
+ when :String
219
+ value.to_s
220
+ when :Integer
221
+ value.to_i
222
+ when :Float
223
+ value.to_f
224
+ when :Boolean
225
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
226
+ true
227
+ else
228
+ false
229
+ end
230
+ when :Object
231
+ # generic object (usually a Hash), return directly
232
+ value
233
+ when /\AArray<(?<inner_type>.+)>\z/
234
+ inner_type = Regexp.last_match[:inner_type]
235
+ value.map { |v| _deserialize(inner_type, v) }
236
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
237
+ k_type = Regexp.last_match[:k_type]
238
+ v_type = Regexp.last_match[:v_type]
239
+ {}.tap do |hash|
240
+ value.each do |k, v|
241
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
242
+ end
243
+ end
244
+ else # model
245
+ # models (e.g. Pet) or oneOf
246
+ klass = Zyphr.const_get(type)
247
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
248
+ end
249
+ end
250
+
251
+ # Returns the string representation of the object
252
+ # @return [String] String presentation of the object
253
+ def to_s
254
+ to_hash.to_s
255
+ end
256
+
257
+ # to_body is an alias to to_hash (backward compatibility)
258
+ # @return [Hash] Returns the object in the form of hash
259
+ def to_body
260
+ to_hash
261
+ end
262
+
263
+ # Returns the object in the form of hash
264
+ # @return [Hash] Returns the object in the form of hash
265
+ def to_hash
266
+ hash = {}
267
+ self.class.attribute_map.each_pair do |attr, param|
268
+ value = self.send(attr)
269
+ if value.nil?
270
+ is_nullable = self.class.openapi_nullable.include?(attr)
271
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
272
+ end
273
+
274
+ hash[param] = _to_hash(value)
275
+ end
276
+ hash
277
+ end
278
+
279
+ # Outputs non-array value in the form of hash
280
+ # For object, use to_hash. Otherwise, just return the value
281
+ # @param [Object] value Any valid value
282
+ # @return [Hash] Returns the value in the form of hash
283
+ def _to_hash(value)
284
+ if value.is_a?(Array)
285
+ value.compact.map { |v| _to_hash(v) }
286
+ elsif value.is_a?(Hash)
287
+ {}.tap do |hash|
288
+ value.each { |k, v| hash[k] = _to_hash(v) }
289
+ end
290
+ elsif value.respond_to? :to_hash
291
+ value.to_hash
292
+ else
293
+ value
294
+ end
295
+ end
296
+
297
+ end
298
+
299
+ end
@@ -0,0 +1,229 @@
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 DraftResponse
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' => :'Draft',
44
+ :'meta' => :'RequestMeta'
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::DraftResponse` 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::DraftResponse`. 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
+ end
73
+
74
+ if attributes.key?(:'meta')
75
+ self.meta = attributes[:'meta']
76
+ end
77
+ end
78
+
79
+ # Show invalid properties with the reasons. Usually used together with valid?
80
+ # @return Array for valid properties with the reasons
81
+ def list_invalid_properties
82
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
83
+ invalid_properties = Array.new
84
+ invalid_properties
85
+ end
86
+
87
+ # Check to see if the all the properties in the model are valid
88
+ # @return true if the model is valid
89
+ def valid?
90
+ warn '[DEPRECATED] the `valid?` method is obsolete'
91
+ true
92
+ end
93
+
94
+ # Checks equality by comparing each attribute.
95
+ # @param [Object] Object to be compared
96
+ def ==(o)
97
+ return true if self.equal?(o)
98
+ self.class == o.class &&
99
+ data == o.data &&
100
+ meta == o.meta
101
+ end
102
+
103
+ # @see the `==` method
104
+ # @param [Object] Object to be compared
105
+ def eql?(o)
106
+ self == o
107
+ end
108
+
109
+ # Calculates hash code according to all attributes.
110
+ # @return [Integer] Hash code
111
+ def hash
112
+ [data, meta].hash
113
+ end
114
+
115
+ # Builds the object from hash
116
+ # @param [Hash] attributes Model attributes in the form of hash
117
+ # @return [Object] Returns the model itself
118
+ def self.build_from_hash(attributes)
119
+ return nil unless attributes.is_a?(Hash)
120
+ attributes = attributes.transform_keys(&:to_sym)
121
+ transformed_hash = {}
122
+ openapi_types.each_pair do |key, type|
123
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
124
+ transformed_hash["#{key}"] = nil
125
+ elsif type =~ /\AArray<(.*)>/i
126
+ # check to ensure the input is an array given that the attribute
127
+ # is documented as an array but the input is not
128
+ if attributes[attribute_map[key]].is_a?(Array)
129
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
130
+ end
131
+ elsif !attributes[attribute_map[key]].nil?
132
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
133
+ end
134
+ end
135
+ new(transformed_hash)
136
+ end
137
+
138
+ # Deserializes the data based on type
139
+ # @param string type Data type
140
+ # @param string value Value to be deserialized
141
+ # @return [Object] Deserialized data
142
+ def self._deserialize(type, value)
143
+ case type.to_sym
144
+ when :Time
145
+ Time.parse(value)
146
+ when :Date
147
+ Date.parse(value)
148
+ when :String
149
+ value.to_s
150
+ when :Integer
151
+ value.to_i
152
+ when :Float
153
+ value.to_f
154
+ when :Boolean
155
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
156
+ true
157
+ else
158
+ false
159
+ end
160
+ when :Object
161
+ # generic object (usually a Hash), return directly
162
+ value
163
+ when /\AArray<(?<inner_type>.+)>\z/
164
+ inner_type = Regexp.last_match[:inner_type]
165
+ value.map { |v| _deserialize(inner_type, v) }
166
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
167
+ k_type = Regexp.last_match[:k_type]
168
+ v_type = Regexp.last_match[:v_type]
169
+ {}.tap do |hash|
170
+ value.each do |k, v|
171
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
172
+ end
173
+ end
174
+ else # model
175
+ # models (e.g. Pet) or oneOf
176
+ klass = Zyphr.const_get(type)
177
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
178
+ end
179
+ end
180
+
181
+ # Returns the string representation of the object
182
+ # @return [String] String presentation of the object
183
+ def to_s
184
+ to_hash.to_s
185
+ end
186
+
187
+ # to_body is an alias to to_hash (backward compatibility)
188
+ # @return [Hash] Returns the object in the form of hash
189
+ def to_body
190
+ to_hash
191
+ end
192
+
193
+ # Returns the object in the form of hash
194
+ # @return [Hash] Returns the object in the form of hash
195
+ def to_hash
196
+ hash = {}
197
+ self.class.attribute_map.each_pair do |attr, param|
198
+ value = self.send(attr)
199
+ if value.nil?
200
+ is_nullable = self.class.openapi_nullable.include?(attr)
201
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
202
+ end
203
+
204
+ hash[param] = _to_hash(value)
205
+ end
206
+ hash
207
+ end
208
+
209
+ # Outputs non-array value in the form of hash
210
+ # For object, use to_hash. Otherwise, just return the value
211
+ # @param [Object] value Any valid value
212
+ # @return [Hash] Returns the value in the form of hash
213
+ def _to_hash(value)
214
+ if value.is_a?(Array)
215
+ value.compact.map { |v| _to_hash(v) }
216
+ elsif value.is_a?(Hash)
217
+ {}.tap do |hash|
218
+ value.each { |k, v| hash[k] = _to_hash(v) }
219
+ end
220
+ elsif value.respond_to? :to_hash
221
+ value.to_hash
222
+ else
223
+ value
224
+ end
225
+ end
226
+
227
+ end
228
+
229
+ end