zyphr 0.1.39 → 0.1.41

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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -14
  3. data/docs/AddWorkflowStep201Response.md +20 -0
  4. data/docs/AddWorkflowStepRequest.md +30 -0
  5. data/docs/AuthRegistrationApi.md +1 -1
  6. data/docs/CreateWorkflow201Response.md +20 -0
  7. data/docs/CreateWorkflowRequest.md +26 -0
  8. data/docs/DeleteWorkflow200Response.md +20 -0
  9. data/docs/{TopicDeleteResponseData.md → DeleteWorkflow200ResponseData.md} +2 -2
  10. data/docs/DeleteWorkflowStep200Response.md +20 -0
  11. data/docs/DeleteWorkflowStep200ResponseData.md +22 -0
  12. data/docs/ListWorkflowExecutions200Response.md +20 -0
  13. data/docs/{SmsListResponseMeta.md → ListWorkflowExecutions200ResponseMeta.md} +2 -2
  14. data/docs/ListWorkflows200Response.md +20 -0
  15. data/docs/ListWorkflows200ResponseMeta.md +32 -0
  16. data/docs/ReorderWorkflowStepsRequest.md +18 -0
  17. data/docs/SignInWithGameCenterRequest.md +1 -1
  18. data/docs/SmsListResponse.md +1 -1
  19. data/docs/TopicDeleteResponse.md +1 -1
  20. data/docs/TriggerWorkflow202Response.md +20 -0
  21. data/docs/TriggerWorkflow202ResponseData.md +22 -0
  22. data/docs/TriggerWorkflowRequest.md +24 -0
  23. data/docs/UpdateWorkflowRequest.md +24 -0
  24. data/docs/UpdateWorkflowStatusRequest.md +18 -0
  25. data/docs/UpdateWorkflowStepRequest.md +20 -0
  26. data/docs/Workflow.md +42 -0
  27. data/docs/WorkflowStatus.md +15 -0
  28. data/docs/WorkflowStep.md +38 -0
  29. data/docs/WorkflowStepType.md +15 -0
  30. data/docs/WorkflowsApi.md +901 -0
  31. data/lib/zyphr/api/auth_registration_api.rb +2 -2
  32. data/lib/zyphr/api/workflows_api.rb +897 -0
  33. data/lib/zyphr/models/add_workflow_step201_response.rb +229 -0
  34. data/lib/zyphr/models/add_workflow_step_request.rb +384 -0
  35. data/lib/zyphr/models/create_workflow201_response.rb +229 -0
  36. data/lib/zyphr/models/create_workflow_request.rb +292 -0
  37. data/lib/zyphr/models/delete_workflow200_response.rb +229 -0
  38. data/lib/zyphr/models/{topic_delete_response_data.rb → delete_workflow200_response_data.rb} +3 -3
  39. data/lib/zyphr/models/delete_workflow_step200_response.rb +229 -0
  40. data/lib/zyphr/models/delete_workflow_step200_response_data.rb +238 -0
  41. data/lib/zyphr/models/list_workflow_executions200_response.rb +231 -0
  42. data/lib/zyphr/models/{sms_list_response_meta.rb → list_workflow_executions200_response_meta.rb} +3 -3
  43. data/lib/zyphr/models/list_workflows200_response.rb +231 -0
  44. data/lib/zyphr/models/list_workflows200_response_meta.rb +284 -0
  45. data/lib/zyphr/models/reorder_workflow_steps_request.rb +249 -0
  46. data/lib/zyphr/models/sign_in_with_game_center_request.rb +1 -1
  47. data/lib/zyphr/models/sms_list_response.rb +1 -1
  48. data/lib/zyphr/models/topic_delete_response.rb +1 -1
  49. data/lib/zyphr/models/trigger_workflow202_response.rb +229 -0
  50. data/lib/zyphr/models/trigger_workflow202_response_data.rb +240 -0
  51. data/lib/zyphr/models/trigger_workflow_request.rb +272 -0
  52. data/lib/zyphr/models/update_workflow_request.rb +269 -0
  53. data/lib/zyphr/models/{v1_muse_subjects_suggest_post_request.rb → update_workflow_status_request.rb} +19 -86
  54. data/lib/zyphr/models/update_workflow_step_request.rb +232 -0
  55. data/lib/zyphr/models/workflow.rb +514 -0
  56. data/lib/zyphr/models/workflow_status.rb +42 -0
  57. data/lib/zyphr/models/workflow_step.rb +505 -0
  58. data/lib/zyphr/models/workflow_step_type.rb +47 -0
  59. data/lib/zyphr.rb +24 -4
  60. data/spec/api/auth_registration_api_spec.rb +1 -1
  61. data/spec/api/workflows_api_spec.rb +192 -0
  62. data/spec/models/add_workflow_step201_response_spec.rb +42 -0
  63. data/spec/models/add_workflow_step_request_spec.rb +76 -0
  64. data/spec/models/create_workflow201_response_spec.rb +42 -0
  65. data/spec/models/{v1_muse_subjects_suggest_post_request_spec.rb → create_workflow_request_spec.rb} +16 -14
  66. data/spec/models/{topic_delete_response_data_spec.rb → delete_workflow200_response_data_spec.rb} +6 -6
  67. data/spec/models/delete_workflow200_response_spec.rb +42 -0
  68. data/spec/models/delete_workflow_step200_response_data_spec.rb +48 -0
  69. data/spec/models/delete_workflow_step200_response_spec.rb +42 -0
  70. data/spec/models/{sms_list_response_meta_spec.rb → list_workflow_executions200_response_meta_spec.rb} +6 -6
  71. data/spec/models/list_workflow_executions200_response_spec.rb +42 -0
  72. data/spec/models/list_workflows200_response_meta_spec.rb +78 -0
  73. data/spec/models/list_workflows200_response_spec.rb +42 -0
  74. data/spec/models/reorder_workflow_steps_request_spec.rb +36 -0
  75. data/spec/models/trigger_workflow202_response_data_spec.rb +48 -0
  76. data/spec/models/trigger_workflow202_response_spec.rb +42 -0
  77. data/spec/models/trigger_workflow_request_spec.rb +54 -0
  78. data/spec/models/update_workflow_request_spec.rb +54 -0
  79. data/spec/models/update_workflow_status_request_spec.rb +36 -0
  80. data/spec/models/update_workflow_step_request_spec.rb +42 -0
  81. data/spec/models/workflow_spec.rb +108 -0
  82. data/spec/models/workflow_status_spec.rb +30 -0
  83. data/spec/models/workflow_step_spec.rb +100 -0
  84. data/spec/models/workflow_step_type_spec.rb +30 -0
  85. data/zyphr.gemspec +1 -1
  86. metadata +97 -17
  87. data/docs/MuseApi.md +0 -681
  88. data/docs/V1MuseSubjectsSuggestPostRequest.md +0 -24
  89. data/lib/zyphr/api/muse_api.rb +0 -644
  90. data/spec/api/muse_api_spec.rb +0 -156
@@ -0,0 +1,229 @@
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 ## 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 CreateWorkflow201Response
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' => :'Workflow',
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::CreateWorkflow201Response` 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::CreateWorkflow201Response`. 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
@@ -0,0 +1,292 @@
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 ## 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 CreateWorkflowRequest
18
+ # Human-readable workflow name.
19
+ attr_accessor :name
20
+
21
+ # Unique workflow key within the project. Derived from `name` when omitted.
22
+ attr_accessor :key
23
+
24
+ # Optional description of what the workflow does.
25
+ attr_accessor :description
26
+
27
+ # Marks the workflow as critical (bypasses certain preference checks).
28
+ attr_accessor :is_critical
29
+
30
+ # Optional tags for organizing workflows.
31
+ attr_accessor :tags
32
+
33
+ # Attribute mapping from ruby-style variable name to JSON key.
34
+ def self.attribute_map
35
+ {
36
+ :'name' => :'name',
37
+ :'key' => :'key',
38
+ :'description' => :'description',
39
+ :'is_critical' => :'is_critical',
40
+ :'tags' => :'tags'
41
+ }
42
+ end
43
+
44
+ # Returns attribute mapping this model knows about
45
+ def self.acceptable_attribute_map
46
+ attribute_map
47
+ end
48
+
49
+ # Returns all the JSON keys this model knows about
50
+ def self.acceptable_attributes
51
+ acceptable_attribute_map.values
52
+ end
53
+
54
+ # Attribute type mapping.
55
+ def self.openapi_types
56
+ {
57
+ :'name' => :'String',
58
+ :'key' => :'String',
59
+ :'description' => :'String',
60
+ :'is_critical' => :'Boolean',
61
+ :'tags' => :'Array<String>'
62
+ }
63
+ end
64
+
65
+ # List of attributes with nullable: true
66
+ def self.openapi_nullable
67
+ Set.new([
68
+ :'description',
69
+ ])
70
+ end
71
+
72
+ # Initializes the object
73
+ # @param [Hash] attributes Model attributes in the form of hash
74
+ def initialize(attributes = {})
75
+ if (!attributes.is_a?(Hash))
76
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Zyphr::CreateWorkflowRequest` initialize method"
77
+ end
78
+
79
+ # check to see if the attribute exists and convert string to symbol for hash key
80
+ acceptable_attribute_map = self.class.acceptable_attribute_map
81
+ attributes = attributes.each_with_object({}) { |(k, v), h|
82
+ if (!acceptable_attribute_map.key?(k.to_sym))
83
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Zyphr::CreateWorkflowRequest`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
84
+ end
85
+ h[k.to_sym] = v
86
+ }
87
+
88
+ if attributes.key?(:'name')
89
+ self.name = attributes[:'name']
90
+ else
91
+ self.name = nil
92
+ end
93
+
94
+ if attributes.key?(:'key')
95
+ self.key = attributes[:'key']
96
+ end
97
+
98
+ if attributes.key?(:'description')
99
+ self.description = attributes[:'description']
100
+ end
101
+
102
+ if attributes.key?(:'is_critical')
103
+ self.is_critical = attributes[:'is_critical']
104
+ else
105
+ self.is_critical = false
106
+ end
107
+
108
+ if attributes.key?(:'tags')
109
+ if (value = attributes[:'tags']).is_a?(Array)
110
+ self.tags = value
111
+ end
112
+ end
113
+ end
114
+
115
+ # Show invalid properties with the reasons. Usually used together with valid?
116
+ # @return Array for valid properties with the reasons
117
+ def list_invalid_properties
118
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
119
+ invalid_properties = Array.new
120
+ if @name.nil?
121
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
122
+ end
123
+
124
+ if @name.to_s.length > 255
125
+ invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 255.')
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 @name.nil?
136
+ return false if @name.to_s.length > 255
137
+ true
138
+ end
139
+
140
+ # Custom attribute writer method with validation
141
+ # @param [Object] name Value to be assigned
142
+ def name=(name)
143
+ if name.nil?
144
+ fail ArgumentError, 'name cannot be nil'
145
+ end
146
+
147
+ if name.to_s.length > 255
148
+ fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 255.'
149
+ end
150
+
151
+ @name = name
152
+ end
153
+
154
+ # Checks equality by comparing each attribute.
155
+ # @param [Object] Object to be compared
156
+ def ==(o)
157
+ return true if self.equal?(o)
158
+ self.class == o.class &&
159
+ name == o.name &&
160
+ key == o.key &&
161
+ description == o.description &&
162
+ is_critical == o.is_critical &&
163
+ tags == o.tags
164
+ end
165
+
166
+ # @see the `==` method
167
+ # @param [Object] Object to be compared
168
+ def eql?(o)
169
+ self == o
170
+ end
171
+
172
+ # Calculates hash code according to all attributes.
173
+ # @return [Integer] Hash code
174
+ def hash
175
+ [name, key, description, is_critical, tags].hash
176
+ end
177
+
178
+ # Builds the object from hash
179
+ # @param [Hash] attributes Model attributes in the form of hash
180
+ # @return [Object] Returns the model itself
181
+ def self.build_from_hash(attributes)
182
+ return nil unless attributes.is_a?(Hash)
183
+ attributes = attributes.transform_keys(&:to_sym)
184
+ transformed_hash = {}
185
+ openapi_types.each_pair do |key, type|
186
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
187
+ transformed_hash["#{key}"] = nil
188
+ elsif type =~ /\AArray<(.*)>/i
189
+ # check to ensure the input is an array given that the attribute
190
+ # is documented as an array but the input is not
191
+ if attributes[attribute_map[key]].is_a?(Array)
192
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
193
+ end
194
+ elsif !attributes[attribute_map[key]].nil?
195
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
196
+ end
197
+ end
198
+ new(transformed_hash)
199
+ end
200
+
201
+ # Deserializes the data based on type
202
+ # @param string type Data type
203
+ # @param string value Value to be deserialized
204
+ # @return [Object] Deserialized data
205
+ def self._deserialize(type, value)
206
+ case type.to_sym
207
+ when :Time
208
+ Time.parse(value)
209
+ when :Date
210
+ Date.parse(value)
211
+ when :String
212
+ value.to_s
213
+ when :Integer
214
+ value.to_i
215
+ when :Float
216
+ value.to_f
217
+ when :Boolean
218
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
219
+ true
220
+ else
221
+ false
222
+ end
223
+ when :Object
224
+ # generic object (usually a Hash), return directly
225
+ value
226
+ when /\AArray<(?<inner_type>.+)>\z/
227
+ inner_type = Regexp.last_match[:inner_type]
228
+ value.map { |v| _deserialize(inner_type, v) }
229
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
230
+ k_type = Regexp.last_match[:k_type]
231
+ v_type = Regexp.last_match[:v_type]
232
+ {}.tap do |hash|
233
+ value.each do |k, v|
234
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
235
+ end
236
+ end
237
+ else # model
238
+ # models (e.g. Pet) or oneOf
239
+ klass = Zyphr.const_get(type)
240
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
241
+ end
242
+ end
243
+
244
+ # Returns the string representation of the object
245
+ # @return [String] String presentation of the object
246
+ def to_s
247
+ to_hash.to_s
248
+ end
249
+
250
+ # to_body is an alias to to_hash (backward compatibility)
251
+ # @return [Hash] Returns the object in the form of hash
252
+ def to_body
253
+ to_hash
254
+ end
255
+
256
+ # Returns the object in the form of hash
257
+ # @return [Hash] Returns the object in the form of hash
258
+ def to_hash
259
+ hash = {}
260
+ self.class.attribute_map.each_pair do |attr, param|
261
+ value = self.send(attr)
262
+ if value.nil?
263
+ is_nullable = self.class.openapi_nullable.include?(attr)
264
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
265
+ end
266
+
267
+ hash[param] = _to_hash(value)
268
+ end
269
+ hash
270
+ end
271
+
272
+ # Outputs non-array value in the form of hash
273
+ # For object, use to_hash. Otherwise, just return the value
274
+ # @param [Object] value Any valid value
275
+ # @return [Hash] Returns the value in the form of hash
276
+ def _to_hash(value)
277
+ if value.is_a?(Array)
278
+ value.compact.map { |v| _to_hash(v) }
279
+ elsif value.is_a?(Hash)
280
+ {}.tap do |hash|
281
+ value.each { |k, v| hash[k] = _to_hash(v) }
282
+ end
283
+ elsif value.respond_to? :to_hash
284
+ value.to_hash
285
+ else
286
+ value
287
+ end
288
+ end
289
+
290
+ end
291
+
292
+ end