zyphr 0.1.38 → 0.1.40

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