svix 0.28.0 → 0.37.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +7 -1
  3. data/README.md +16 -3
  4. data/lib/svix/api/application_api.rb +386 -0
  5. data/lib/svix/api/authentication_api.rb +155 -0
  6. data/lib/svix/api/endpoint_api.rb +1281 -0
  7. data/lib/svix/api/event_type_api.rb +454 -0
  8. data/lib/svix/api/health_api.rb +77 -0
  9. data/lib/svix/api/message_api.rb +289 -0
  10. data/lib/svix/api/message_attempt_api.rb +678 -0
  11. data/lib/svix/api/statistics_api.rb +205 -0
  12. data/lib/svix/api_client.rb +399 -0
  13. data/lib/svix/api_error.rb +57 -0
  14. data/lib/svix/application_api.rb +29 -0
  15. data/lib/svix/authentication_api.rb +17 -0
  16. data/lib/svix/configuration.rb +277 -0
  17. data/lib/svix/endpoint_api.rb +55 -0
  18. data/{src → lib}/svix/errors.rb +0 -0
  19. data/lib/svix/event_type_api.rb +25 -0
  20. data/lib/svix/internal.rb +16 -0
  21. data/lib/svix/message_api.rb +21 -0
  22. data/lib/svix/message_attempt_api.rb +33 -0
  23. data/lib/svix/models/application_in.rb +277 -0
  24. data/lib/svix/models/application_out.rb +319 -0
  25. data/lib/svix/models/attempt_statistics_data.rb +231 -0
  26. data/lib/svix/models/attempt_statistics_response.rb +265 -0
  27. data/lib/svix/models/dashboard_access_out.rb +265 -0
  28. data/lib/svix/models/endpoint_created_event.rb +269 -0
  29. data/lib/svix/models/endpoint_created_event_data.rb +282 -0
  30. data/lib/svix/models/endpoint_deleted_event.rb +269 -0
  31. data/lib/svix/models/endpoint_deleted_event_data.rb +282 -0
  32. data/lib/svix/models/endpoint_disabled_event.rb +269 -0
  33. data/lib/svix/models/endpoint_disabled_event_data.rb +296 -0
  34. data/lib/svix/models/endpoint_headers_in.rb +225 -0
  35. data/lib/svix/models/endpoint_headers_out.rb +252 -0
  36. data/lib/svix/models/endpoint_in.rb +394 -0
  37. data/lib/svix/models/endpoint_message_out.rb +363 -0
  38. data/lib/svix/models/endpoint_out.rb +409 -0
  39. data/lib/svix/models/endpoint_secret_out.rb +245 -0
  40. data/lib/svix/models/endpoint_secret_rotate_in.rb +236 -0
  41. data/lib/svix/models/endpoint_stats.rb +265 -0
  42. data/lib/svix/models/endpoint_update.rb +367 -0
  43. data/lib/svix/models/endpoint_updated_event.rb +269 -0
  44. data/lib/svix/models/endpoint_updated_event_data.rb +282 -0
  45. data/lib/svix/models/endpointd_updated_event.rb +269 -0
  46. data/lib/svix/models/event_example_in.rb +253 -0
  47. data/lib/svix/models/event_type_example_out.rb +223 -0
  48. data/lib/svix/models/event_type_in.rb +290 -0
  49. data/lib/svix/models/event_type_out.rb +318 -0
  50. data/lib/svix/models/event_type_schema_in.rb +224 -0
  51. data/lib/svix/models/event_type_update.rb +246 -0
  52. data/lib/svix/models/http_error_out.rb +237 -0
  53. data/lib/svix/models/http_validation_error.rb +220 -0
  54. data/lib/svix/models/list_response_application_out.rb +248 -0
  55. data/lib/svix/models/list_response_endpoint_message_out.rb +248 -0
  56. data/lib/svix/models/list_response_endpoint_out.rb +248 -0
  57. data/lib/svix/models/list_response_event_type_out.rb +248 -0
  58. data/lib/svix/models/list_response_message_attempt_endpoint_out.rb +248 -0
  59. data/lib/svix/models/list_response_message_attempt_out.rb +248 -0
  60. data/lib/svix/models/list_response_message_endpoint_out.rb +248 -0
  61. data/lib/svix/models/list_response_message_out.rb +248 -0
  62. data/lib/svix/models/message_attempt_endpoint_out.rb +293 -0
  63. data/lib/svix/models/message_attempt_exhausted_event.rb +269 -0
  64. data/lib/svix/models/message_attempt_exhausted_event_data.rb +310 -0
  65. data/lib/svix/models/message_attempt_failed_event.rb +251 -0
  66. data/lib/svix/models/message_attempt_out.rb +307 -0
  67. data/lib/svix/models/message_attempt_trigger_type.rb +37 -0
  68. data/lib/svix/models/message_endpoint_out.rb +418 -0
  69. data/lib/svix/models/message_in.rb +312 -0
  70. data/lib/svix/models/message_out.rb +340 -0
  71. data/lib/svix/models/message_status.rb +39 -0
  72. data/lib/svix/models/recover_in.rb +223 -0
  73. data/lib/svix/models/statistics_period.rb +37 -0
  74. data/lib/svix/models/validation_error.rb +253 -0
  75. data/lib/svix/models/webhook_types.rb +280 -0
  76. data/lib/svix/svix.rb +43 -0
  77. data/{src → lib}/svix/util.rb +1 -1
  78. data/{src → lib}/svix/version.rb +1 -1
  79. data/{src → lib}/svix/webhook.rb +1 -1
  80. data/lib/svix.rb +80 -0
  81. data/svix.gemspec +16 -6
  82. metadata +100 -9
  83. data/.gitignore +0 -9
  84. data/src/svix.rb +0 -8
@@ -0,0 +1,296 @@
1
+ =begin
2
+ #Svix API
3
+
4
+ #Welcome to the Svix API documentation! Useful links: [Homepage](https://www.svix.com) | [Support email](mailto:support+docs@svix.com) | [Blog](https://www.svix.com/blog/) | [Slack Community](https://www.svix.com/slack/) # Introduction This is the reference documentation and schemas for the [Svix webhook service](https://www.svix.com) API. For tutorials and other documentation please refer to [the documentation](https://docs.svix.com). ## Main concepts In Svix you have four important entities you will be interacting with: - `messages`: these are the webhooks being sent. They can have contents and a few other properties. - `application`: this is where `messages` are sent to. Usually you want to create one application for each of your users. - `endpoint`: endpoints are the URLs messages will be sent to. Each application can have multiple `endpoints` and each message sent to that application will be sent to all of them (unless they are not subscribed to the sent event type). - `event-type`: event types are identifiers denoting the type of the message being sent. Event types are primarily used to decide which events are sent to which endpoint. ## Authentication Get your authentication token (`AUTH_TOKEN`) from the [Svix dashboard](https://dashboard.svix.com) and use it as part of the `Authorization` header as such: `Authorization: Bearer ${AUTH_TOKEN}`. <SecurityDefinitions /> ## Code samples The code samples assume you already have the respective libraries installed and you know how to use them. For the latest information on how to do that, please refer to [the documentation](https://docs.svix.com/). ## Cross-Origin Resource Sharing This API features Cross-Origin Resource Sharing (CORS) implemented in compliance with [W3C spec](https://www.w3.org/TR/cors/). And that allows cross-domain communication from the browser. All responses have a wildcard same-origin which makes them completely public and accessible to everyone, including any code on any site.
5
+
6
+ The version of the OpenAPI document: 1.4
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.2.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Svix
17
+ class EndpointDisabledEventData
18
+ attr_accessor :app_id
19
+
20
+ # Optional unique identifier for the application
21
+ attr_accessor :app_uid
22
+
23
+ attr_accessor :endpoint_id
24
+
25
+ attr_accessor :fail_since
26
+
27
+ # Attribute mapping from ruby-style variable name to JSON key.
28
+ def self.attribute_map
29
+ {
30
+ :'app_id' => :'appId',
31
+ :'app_uid' => :'appUid',
32
+ :'endpoint_id' => :'endpointId',
33
+ :'fail_since' => :'failSince'
34
+ }
35
+ end
36
+
37
+ # Returns all the JSON keys this model knows about
38
+ def self.acceptable_attributes
39
+ attribute_map.values
40
+ end
41
+
42
+ # Attribute type mapping.
43
+ def self.openapi_types
44
+ {
45
+ :'app_id' => :'String',
46
+ :'app_uid' => :'String',
47
+ :'endpoint_id' => :'String',
48
+ :'fail_since' => :'Time'
49
+ }
50
+ end
51
+
52
+ # List of attributes with nullable: true
53
+ def self.openapi_nullable
54
+ Set.new([
55
+ ])
56
+ end
57
+
58
+ # Initializes the object
59
+ # @param [Hash] attributes Model attributes in the form of hash
60
+ def initialize(attributes = {})
61
+ if (!attributes.is_a?(Hash))
62
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Svix::EndpointDisabledEventData` initialize method"
63
+ end
64
+
65
+ # check to see if the attribute exists and convert string to symbol for hash key
66
+ attributes = attributes.each_with_object({}) { |(k, v), h|
67
+ if (!self.class.attribute_map.key?(k.to_sym))
68
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Svix::EndpointDisabledEventData`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
69
+ end
70
+ h[k.to_sym] = v
71
+ }
72
+
73
+ if attributes.key?(:'app_id')
74
+ self.app_id = attributes[:'app_id']
75
+ end
76
+
77
+ if attributes.key?(:'app_uid')
78
+ self.app_uid = attributes[:'app_uid']
79
+ end
80
+
81
+ if attributes.key?(:'endpoint_id')
82
+ self.endpoint_id = attributes[:'endpoint_id']
83
+ end
84
+
85
+ if attributes.key?(:'fail_since')
86
+ self.fail_since = attributes[:'fail_since']
87
+ end
88
+ end
89
+
90
+ # Show invalid properties with the reasons. Usually used together with valid?
91
+ # @return Array for valid properties with the reasons
92
+ def list_invalid_properties
93
+ invalid_properties = Array.new
94
+ if @app_id.nil?
95
+ invalid_properties.push('invalid value for "app_id", app_id cannot be nil.')
96
+ end
97
+
98
+ if !@app_uid.nil? && @app_uid.to_s.length > 256
99
+ invalid_properties.push('invalid value for "app_uid", the character length must be smaller than or equal to 256.')
100
+ end
101
+
102
+ if !@app_uid.nil? && @app_uid.to_s.length < 1
103
+ invalid_properties.push('invalid value for "app_uid", the character length must be great than or equal to 1.')
104
+ end
105
+
106
+ pattern = Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
107
+ if !@app_uid.nil? && @app_uid !~ pattern
108
+ invalid_properties.push("invalid value for \"app_uid\", must conform to the pattern #{pattern}.")
109
+ end
110
+
111
+ if @endpoint_id.nil?
112
+ invalid_properties.push('invalid value for "endpoint_id", endpoint_id cannot be nil.')
113
+ end
114
+
115
+ if @fail_since.nil?
116
+ invalid_properties.push('invalid value for "fail_since", fail_since cannot be nil.')
117
+ end
118
+
119
+ invalid_properties
120
+ end
121
+
122
+ # Check to see if the all the properties in the model are valid
123
+ # @return true if the model is valid
124
+ def valid?
125
+ return false if @app_id.nil?
126
+ return false if !@app_uid.nil? && @app_uid.to_s.length > 256
127
+ return false if !@app_uid.nil? && @app_uid.to_s.length < 1
128
+ return false if !@app_uid.nil? && @app_uid !~ Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
129
+ return false if @endpoint_id.nil?
130
+ return false if @fail_since.nil?
131
+ true
132
+ end
133
+
134
+ # Custom attribute writer method with validation
135
+ # @param [Object] app_uid Value to be assigned
136
+ def app_uid=(app_uid)
137
+ if !app_uid.nil? && app_uid.to_s.length > 256
138
+ fail ArgumentError, 'invalid value for "app_uid", the character length must be smaller than or equal to 256.'
139
+ end
140
+
141
+ if !app_uid.nil? && app_uid.to_s.length < 1
142
+ fail ArgumentError, 'invalid value for "app_uid", the character length must be great than or equal to 1.'
143
+ end
144
+
145
+ pattern = Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
146
+ if !app_uid.nil? && app_uid !~ pattern
147
+ fail ArgumentError, "invalid value for \"app_uid\", must conform to the pattern #{pattern}."
148
+ end
149
+
150
+ @app_uid = app_uid
151
+ end
152
+
153
+ # Checks equality by comparing each attribute.
154
+ # @param [Object] Object to be compared
155
+ def ==(o)
156
+ return true if self.equal?(o)
157
+ self.class == o.class &&
158
+ app_id == o.app_id &&
159
+ app_uid == o.app_uid &&
160
+ endpoint_id == o.endpoint_id &&
161
+ fail_since == o.fail_since
162
+ end
163
+
164
+ # @see the `==` method
165
+ # @param [Object] Object to be compared
166
+ def eql?(o)
167
+ self == o
168
+ end
169
+
170
+ # Calculates hash code according to all attributes.
171
+ # @return [Integer] Hash code
172
+ def hash
173
+ [app_id, app_uid, endpoint_id, fail_since].hash
174
+ end
175
+
176
+ # Builds the object from hash
177
+ # @param [Hash] attributes Model attributes in the form of hash
178
+ # @return [Object] Returns the model itself
179
+ def self.build_from_hash(attributes)
180
+ new.build_from_hash(attributes)
181
+ end
182
+
183
+ # Builds the object from hash
184
+ # @param [Hash] attributes Model attributes in the form of hash
185
+ # @return [Object] Returns the model itself
186
+ def build_from_hash(attributes)
187
+ return nil unless attributes.is_a?(Hash)
188
+ self.class.openapi_types.each_pair do |key, type|
189
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
190
+ self.send("#{key}=", nil)
191
+ elsif type =~ /\AArray<(.*)>/i
192
+ # check to ensure the input is an array given that the attribute
193
+ # is documented as an array but the input is not
194
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
195
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
196
+ end
197
+ elsif !attributes[self.class.attribute_map[key]].nil?
198
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
199
+ end
200
+ end
201
+
202
+ self
203
+ end
204
+
205
+ # Deserializes the data based on type
206
+ # @param string type Data type
207
+ # @param string value Value to be deserialized
208
+ # @return [Object] Deserialized data
209
+ def _deserialize(type, value)
210
+ case type.to_sym
211
+ when :Time
212
+ Time.parse(value)
213
+ when :Date
214
+ Date.parse(value)
215
+ when :String
216
+ value.to_s
217
+ when :Integer
218
+ value.to_i
219
+ when :Float
220
+ value.to_f
221
+ when :Boolean
222
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
223
+ true
224
+ else
225
+ false
226
+ end
227
+ when :Object
228
+ # generic object (usually a Hash), return directly
229
+ value
230
+ when /\AArray<(?<inner_type>.+)>\z/
231
+ inner_type = Regexp.last_match[:inner_type]
232
+ value.map { |v| _deserialize(inner_type, v) }
233
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
234
+ k_type = Regexp.last_match[:k_type]
235
+ v_type = Regexp.last_match[:v_type]
236
+ {}.tap do |hash|
237
+ value.each do |k, v|
238
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
239
+ end
240
+ end
241
+ else # model
242
+ # models (e.g. Pet) or oneOf
243
+ klass = Svix.const_get(type)
244
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
245
+ end
246
+ end
247
+
248
+ # Returns the string representation of the object
249
+ # @return [String] String presentation of the object
250
+ def to_s
251
+ to_hash.to_s
252
+ end
253
+
254
+ # to_body is an alias to to_hash (backward compatibility)
255
+ # @return [Hash] Returns the object in the form of hash
256
+ def to_body
257
+ to_hash
258
+ end
259
+
260
+ # Returns the object in the form of hash
261
+ # @return [Hash] Returns the object in the form of hash
262
+ def to_hash
263
+ hash = {}
264
+ self.class.attribute_map.each_pair do |attr, param|
265
+ value = self.send(attr)
266
+ if value.nil?
267
+ is_nullable = self.class.openapi_nullable.include?(attr)
268
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
269
+ end
270
+
271
+ hash[param] = _to_hash(value)
272
+ end
273
+ hash
274
+ end
275
+
276
+ # Outputs non-array value in the form of hash
277
+ # For object, use to_hash. Otherwise, just return the value
278
+ # @param [Object] value Any valid value
279
+ # @return [Hash] Returns the value in the form of hash
280
+ def _to_hash(value)
281
+ if value.is_a?(Array)
282
+ value.compact.map { |v| _to_hash(v) }
283
+ elsif value.is_a?(Hash)
284
+ {}.tap do |hash|
285
+ value.each { |k, v| hash[k] = _to_hash(v) }
286
+ end
287
+ elsif value.respond_to? :to_hash
288
+ value.to_hash
289
+ else
290
+ value
291
+ end
292
+ end
293
+
294
+ end
295
+
296
+ end
@@ -0,0 +1,225 @@
1
+ =begin
2
+ #Svix API
3
+
4
+ #Welcome to the Svix API documentation! Useful links: [Homepage](https://www.svix.com) | [Support email](mailto:support+docs@svix.com) | [Blog](https://www.svix.com/blog/) | [Slack Community](https://www.svix.com/slack/) # Introduction This is the reference documentation and schemas for the [Svix webhook service](https://www.svix.com) API. For tutorials and other documentation please refer to [the documentation](https://docs.svix.com). ## Main concepts In Svix you have four important entities you will be interacting with: - `messages`: these are the webhooks being sent. They can have contents and a few other properties. - `application`: this is where `messages` are sent to. Usually you want to create one application for each of your users. - `endpoint`: endpoints are the URLs messages will be sent to. Each application can have multiple `endpoints` and each message sent to that application will be sent to all of them (unless they are not subscribed to the sent event type). - `event-type`: event types are identifiers denoting the type of the message being sent. Event types are primarily used to decide which events are sent to which endpoint. ## Authentication Get your authentication token (`AUTH_TOKEN`) from the [Svix dashboard](https://dashboard.svix.com) and use it as part of the `Authorization` header as such: `Authorization: Bearer ${AUTH_TOKEN}`. <SecurityDefinitions /> ## Code samples The code samples assume you already have the respective libraries installed and you know how to use them. For the latest information on how to do that, please refer to [the documentation](https://docs.svix.com/). ## Cross-Origin Resource Sharing This API features Cross-Origin Resource Sharing (CORS) implemented in compliance with [W3C spec](https://www.w3.org/TR/cors/). And that allows cross-domain communication from the browser. All responses have a wildcard same-origin which makes them completely public and accessible to everyone, including any code on any site.
5
+
6
+ The version of the OpenAPI document: 1.4
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 5.2.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Svix
17
+ class EndpointHeadersIn
18
+ attr_accessor :headers
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :'headers' => :'headers'
24
+ }
25
+ end
26
+
27
+ # Returns all the JSON keys this model knows about
28
+ def self.acceptable_attributes
29
+ attribute_map.values
30
+ end
31
+
32
+ # Attribute type mapping.
33
+ def self.openapi_types
34
+ {
35
+ :'headers' => :'Hash<String, String>'
36
+ }
37
+ end
38
+
39
+ # List of attributes with nullable: true
40
+ def self.openapi_nullable
41
+ Set.new([
42
+ ])
43
+ end
44
+
45
+ # Initializes the object
46
+ # @param [Hash] attributes Model attributes in the form of hash
47
+ def initialize(attributes = {})
48
+ if (!attributes.is_a?(Hash))
49
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Svix::EndpointHeadersIn` initialize method"
50
+ end
51
+
52
+ # check to see if the attribute exists and convert string to symbol for hash key
53
+ attributes = attributes.each_with_object({}) { |(k, v), h|
54
+ if (!self.class.attribute_map.key?(k.to_sym))
55
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Svix::EndpointHeadersIn`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
56
+ end
57
+ h[k.to_sym] = v
58
+ }
59
+
60
+ if attributes.key?(:'headers')
61
+ if (value = attributes[:'headers']).is_a?(Hash)
62
+ self.headers = value
63
+ end
64
+ end
65
+ end
66
+
67
+ # Show invalid properties with the reasons. Usually used together with valid?
68
+ # @return Array for valid properties with the reasons
69
+ def list_invalid_properties
70
+ invalid_properties = Array.new
71
+ if @headers.nil?
72
+ invalid_properties.push('invalid value for "headers", headers cannot be nil.')
73
+ end
74
+
75
+ invalid_properties
76
+ end
77
+
78
+ # Check to see if the all the properties in the model are valid
79
+ # @return true if the model is valid
80
+ def valid?
81
+ return false if @headers.nil?
82
+ true
83
+ end
84
+
85
+ # Checks equality by comparing each attribute.
86
+ # @param [Object] Object to be compared
87
+ def ==(o)
88
+ return true if self.equal?(o)
89
+ self.class == o.class &&
90
+ headers == o.headers
91
+ end
92
+
93
+ # @see the `==` method
94
+ # @param [Object] Object to be compared
95
+ def eql?(o)
96
+ self == o
97
+ end
98
+
99
+ # Calculates hash code according to all attributes.
100
+ # @return [Integer] Hash code
101
+ def hash
102
+ [headers].hash
103
+ end
104
+
105
+ # Builds the object from hash
106
+ # @param [Hash] attributes Model attributes in the form of hash
107
+ # @return [Object] Returns the model itself
108
+ def self.build_from_hash(attributes)
109
+ new.build_from_hash(attributes)
110
+ end
111
+
112
+ # Builds the object from hash
113
+ # @param [Hash] attributes Model attributes in the form of hash
114
+ # @return [Object] Returns the model itself
115
+ def build_from_hash(attributes)
116
+ return nil unless attributes.is_a?(Hash)
117
+ self.class.openapi_types.each_pair do |key, type|
118
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
119
+ self.send("#{key}=", nil)
120
+ elsif type =~ /\AArray<(.*)>/i
121
+ # check to ensure the input is an array given that the attribute
122
+ # is documented as an array but the input is not
123
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
124
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
125
+ end
126
+ elsif !attributes[self.class.attribute_map[key]].nil?
127
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
128
+ end
129
+ end
130
+
131
+ self
132
+ end
133
+
134
+ # Deserializes the data based on type
135
+ # @param string type Data type
136
+ # @param string value Value to be deserialized
137
+ # @return [Object] Deserialized data
138
+ def _deserialize(type, value)
139
+ case type.to_sym
140
+ when :Time
141
+ Time.parse(value)
142
+ when :Date
143
+ Date.parse(value)
144
+ when :String
145
+ value.to_s
146
+ when :Integer
147
+ value.to_i
148
+ when :Float
149
+ value.to_f
150
+ when :Boolean
151
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
152
+ true
153
+ else
154
+ false
155
+ end
156
+ when :Object
157
+ # generic object (usually a Hash), return directly
158
+ value
159
+ when /\AArray<(?<inner_type>.+)>\z/
160
+ inner_type = Regexp.last_match[:inner_type]
161
+ value.map { |v| _deserialize(inner_type, v) }
162
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
163
+ k_type = Regexp.last_match[:k_type]
164
+ v_type = Regexp.last_match[:v_type]
165
+ {}.tap do |hash|
166
+ value.each do |k, v|
167
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
168
+ end
169
+ end
170
+ else # model
171
+ # models (e.g. Pet) or oneOf
172
+ klass = Svix.const_get(type)
173
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
174
+ end
175
+ end
176
+
177
+ # Returns the string representation of the object
178
+ # @return [String] String presentation of the object
179
+ def to_s
180
+ to_hash.to_s
181
+ end
182
+
183
+ # to_body is an alias to to_hash (backward compatibility)
184
+ # @return [Hash] Returns the object in the form of hash
185
+ def to_body
186
+ to_hash
187
+ end
188
+
189
+ # Returns the object in the form of hash
190
+ # @return [Hash] Returns the object in the form of hash
191
+ def to_hash
192
+ hash = {}
193
+ self.class.attribute_map.each_pair do |attr, param|
194
+ value = self.send(attr)
195
+ if value.nil?
196
+ is_nullable = self.class.openapi_nullable.include?(attr)
197
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
198
+ end
199
+
200
+ hash[param] = _to_hash(value)
201
+ end
202
+ hash
203
+ end
204
+
205
+ # Outputs non-array value in the form of hash
206
+ # For object, use to_hash. Otherwise, just return the value
207
+ # @param [Object] value Any valid value
208
+ # @return [Hash] Returns the value in the form of hash
209
+ def _to_hash(value)
210
+ if value.is_a?(Array)
211
+ value.compact.map { |v| _to_hash(v) }
212
+ elsif value.is_a?(Hash)
213
+ {}.tap do |hash|
214
+ value.each { |k, v| hash[k] = _to_hash(v) }
215
+ end
216
+ elsif value.respond_to? :to_hash
217
+ value.to_hash
218
+ else
219
+ value
220
+ end
221
+ end
222
+
223
+ end
224
+
225
+ end