svix 0.34.1 → 0.39.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,205 @@
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 'cgi'
14
+
15
+ module Svix
16
+ class StatisticsApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # Get App Attempt Stats
23
+ # Returns application-level statistics on message attempts
24
+ # @param app_id [String]
25
+ # @param [Hash] opts the optional parameters
26
+ # @option opts [Time] :start_date
27
+ # @option opts [Time] :end_date
28
+ # @return [AttemptStatisticsResponse]
29
+ def get_app_attempt_stats_api_v1_stats_app_app_id_attempt_get(app_id, opts = {})
30
+ data, _status_code, _headers = get_app_attempt_stats_api_v1_stats_app_app_id_attempt_get_with_http_info(app_id, opts)
31
+ data
32
+ end
33
+
34
+ # Get App Attempt Stats
35
+ # Returns application-level statistics on message attempts
36
+ # @param app_id [String]
37
+ # @param [Hash] opts the optional parameters
38
+ # @option opts [Time] :start_date
39
+ # @option opts [Time] :end_date
40
+ # @return [Array<(AttemptStatisticsResponse, Integer, Hash)>] AttemptStatisticsResponse data, response status code and response headers
41
+ def get_app_attempt_stats_api_v1_stats_app_app_id_attempt_get_with_http_info(app_id, opts = {})
42
+ if @api_client.config.debugging
43
+ @api_client.config.logger.debug 'Calling API: StatisticsApi.get_app_attempt_stats_api_v1_stats_app_app_id_attempt_get ...'
44
+ end
45
+ # verify the required parameter 'app_id' is set
46
+ if @api_client.config.client_side_validation && app_id.nil?
47
+ fail ArgumentError, "Missing the required parameter 'app_id' when calling StatisticsApi.get_app_attempt_stats_api_v1_stats_app_app_id_attempt_get"
48
+ end
49
+ if @api_client.config.client_side_validation && app_id.to_s.length > 256
50
+ fail ArgumentError, 'invalid value for "app_id" when calling StatisticsApi.get_app_attempt_stats_api_v1_stats_app_app_id_attempt_get, the character length must be smaller than or equal to 256.'
51
+ end
52
+
53
+ if @api_client.config.client_side_validation && app_id.to_s.length < 1
54
+ fail ArgumentError, 'invalid value for "app_id" when calling StatisticsApi.get_app_attempt_stats_api_v1_stats_app_app_id_attempt_get, the character length must be great than or equal to 1.'
55
+ end
56
+
57
+ pattern = Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
58
+ if @api_client.config.client_side_validation && app_id !~ pattern
59
+ fail ArgumentError, "invalid value for 'app_id' when calling StatisticsApi.get_app_attempt_stats_api_v1_stats_app_app_id_attempt_get, must conform to the pattern #{pattern}."
60
+ end
61
+
62
+ # resource path
63
+ local_var_path = '/api/v1/stats/app/{app_id}/attempt/'.sub('{' + 'app_id' + '}', CGI.escape(app_id.to_s))
64
+
65
+ # query parameters
66
+ query_params = opts[:query_params] || {}
67
+ query_params[:'startDate'] = opts[:'start_date'] if !opts[:'start_date'].nil?
68
+ query_params[:'endDate'] = opts[:'end_date'] if !opts[:'end_date'].nil?
69
+
70
+ # header parameters
71
+ header_params = opts[:header_params] || {}
72
+ # HTTP header 'Accept' (if needed)
73
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
74
+
75
+ # form parameters
76
+ form_params = opts[:form_params] || {}
77
+
78
+ # http body (model)
79
+ post_body = opts[:debug_body]
80
+
81
+ # return_type
82
+ return_type = opts[:debug_return_type] || 'AttemptStatisticsResponse'
83
+
84
+ # auth_names
85
+ auth_names = opts[:debug_auth_names] || ['HTTPBearer']
86
+
87
+ new_options = opts.merge(
88
+ :operation => :"StatisticsApi.get_app_attempt_stats_api_v1_stats_app_app_id_attempt_get",
89
+ :header_params => header_params,
90
+ :query_params => query_params,
91
+ :form_params => form_params,
92
+ :body => post_body,
93
+ :auth_names => auth_names,
94
+ :return_type => return_type
95
+ )
96
+
97
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
98
+ if @api_client.config.debugging
99
+ @api_client.config.logger.debug "API called: StatisticsApi#get_app_attempt_stats_api_v1_stats_app_app_id_attempt_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
100
+ end
101
+ return data, status_code, headers
102
+ end
103
+
104
+ # Get Ep Stats
105
+ # Returns endpoint-level statistics on message attempts
106
+ # @param endpoint_id [String]
107
+ # @param app_id [String]
108
+ # @param [Hash] opts the optional parameters
109
+ # @option opts [Time] :start_date
110
+ # @option opts [Time] :end_date
111
+ # @return [AttemptStatisticsResponse]
112
+ def get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get(endpoint_id, app_id, opts = {})
113
+ data, _status_code, _headers = get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get_with_http_info(endpoint_id, app_id, opts)
114
+ data
115
+ end
116
+
117
+ # Get Ep Stats
118
+ # Returns endpoint-level statistics on message attempts
119
+ # @param endpoint_id [String]
120
+ # @param app_id [String]
121
+ # @param [Hash] opts the optional parameters
122
+ # @option opts [Time] :start_date
123
+ # @option opts [Time] :end_date
124
+ # @return [Array<(AttemptStatisticsResponse, Integer, Hash)>] AttemptStatisticsResponse data, response status code and response headers
125
+ def get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get_with_http_info(endpoint_id, app_id, opts = {})
126
+ if @api_client.config.debugging
127
+ @api_client.config.logger.debug 'Calling API: StatisticsApi.get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get ...'
128
+ end
129
+ # verify the required parameter 'endpoint_id' is set
130
+ if @api_client.config.client_side_validation && endpoint_id.nil?
131
+ fail ArgumentError, "Missing the required parameter 'endpoint_id' when calling StatisticsApi.get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get"
132
+ end
133
+ if @api_client.config.client_side_validation && endpoint_id.to_s.length > 256
134
+ fail ArgumentError, 'invalid value for "endpoint_id" when calling StatisticsApi.get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get, the character length must be smaller than or equal to 256.'
135
+ end
136
+
137
+ if @api_client.config.client_side_validation && endpoint_id.to_s.length < 1
138
+ fail ArgumentError, 'invalid value for "endpoint_id" when calling StatisticsApi.get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get, the character length must be great than or equal to 1.'
139
+ end
140
+
141
+ pattern = Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
142
+ if @api_client.config.client_side_validation && endpoint_id !~ pattern
143
+ fail ArgumentError, "invalid value for 'endpoint_id' when calling StatisticsApi.get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get, must conform to the pattern #{pattern}."
144
+ end
145
+
146
+ # verify the required parameter 'app_id' is set
147
+ if @api_client.config.client_side_validation && app_id.nil?
148
+ fail ArgumentError, "Missing the required parameter 'app_id' when calling StatisticsApi.get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get"
149
+ end
150
+ if @api_client.config.client_side_validation && app_id.to_s.length > 256
151
+ fail ArgumentError, 'invalid value for "app_id" when calling StatisticsApi.get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get, the character length must be smaller than or equal to 256.'
152
+ end
153
+
154
+ if @api_client.config.client_side_validation && app_id.to_s.length < 1
155
+ fail ArgumentError, 'invalid value for "app_id" when calling StatisticsApi.get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get, the character length must be great than or equal to 1.'
156
+ end
157
+
158
+ pattern = Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
159
+ if @api_client.config.client_side_validation && app_id !~ pattern
160
+ fail ArgumentError, "invalid value for 'app_id' when calling StatisticsApi.get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get, must conform to the pattern #{pattern}."
161
+ end
162
+
163
+ # resource path
164
+ local_var_path = '/api/v1/stats/app/{app_id}/ep/{endpoint_id}/attempt/'.sub('{' + 'endpoint_id' + '}', CGI.escape(endpoint_id.to_s)).sub('{' + 'app_id' + '}', CGI.escape(app_id.to_s))
165
+
166
+ # query parameters
167
+ query_params = opts[:query_params] || {}
168
+ query_params[:'startDate'] = opts[:'start_date'] if !opts[:'start_date'].nil?
169
+ query_params[:'endDate'] = opts[:'end_date'] if !opts[:'end_date'].nil?
170
+
171
+ # header parameters
172
+ header_params = opts[:header_params] || {}
173
+ # HTTP header 'Accept' (if needed)
174
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
175
+
176
+ # form parameters
177
+ form_params = opts[:form_params] || {}
178
+
179
+ # http body (model)
180
+ post_body = opts[:debug_body]
181
+
182
+ # return_type
183
+ return_type = opts[:debug_return_type] || 'AttemptStatisticsResponse'
184
+
185
+ # auth_names
186
+ auth_names = opts[:debug_auth_names] || ['HTTPBearer']
187
+
188
+ new_options = opts.merge(
189
+ :operation => :"StatisticsApi.get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get",
190
+ :header_params => header_params,
191
+ :query_params => query_params,
192
+ :form_params => form_params,
193
+ :body => post_body,
194
+ :auth_names => auth_names,
195
+ :return_type => return_type
196
+ )
197
+
198
+ data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
199
+ if @api_client.config.debugging
200
+ @api_client.config.logger.debug "API called: StatisticsApi#get_ep_stats_api_v1_stats_app_app_id_ep_endpoint_id_attempt_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
201
+ end
202
+ return data, status_code, headers
203
+ end
204
+ end
205
+ end
@@ -18,7 +18,7 @@ module Svix
18
18
  return @api.get_endpoint_api_v1_app_app_id_endpoint_endpoint_id_get(endpoint_id, app_id)
19
19
  end
20
20
 
21
- def update(app_id, endpoint_id, endpoint_in)
21
+ def update(app_id, endpoint_id, endpoint_update)
22
22
  return @api.update_endpoint_api_v1_app_app_id_endpoint_endpoint_id_put(endpoint_id, app_id, endpoint_update)
23
23
  end
24
24
 
@@ -34,5 +34,22 @@ module Svix
34
34
  return @api.rotate_endpoint_secret_api_v1_app_app_id_endpoint_endpoint_id_secret_rotate_post(endpoint_id, app_id, endpoint_secret_rotate_in)
35
35
  end
36
36
 
37
+ def recover(app_id, endpoint_id, recover_in)
38
+ @api.resend_failed_webhooks_api_v1_app_app_id_endpoint_endpoint_id_recover_post(app_id, endpoint_id, recover_in)
39
+ nil
40
+ end
41
+
42
+ def get_headers(app_id, endpoint_id)
43
+ return @api.get_endpoint_headers_api_v1_app_app_id_endpoint_endpoint_id_headers_get(endpoint_id app_id)
44
+ end
45
+
46
+ def update_headers(app_id, endpoint_id, endpoint_headers_in)
47
+ return @api.update_endpoint_headers_api_v1_app_app_id_endpoint_endpoint_id_headers_put(app_id, endpoint_id, endpoint_headers_in)
48
+ end
49
+
50
+ def patch_headers(app_id, endpoint_id, endpoint_headers_in)
51
+ return @api.patch_endpoint_headers_api_v1_app_app_id_endpoint_endpoint_id_headers_patch(app_id, endpoint_id, endpoint_headers_in)
52
+ end
53
+
37
54
  end
38
55
  end
@@ -14,6 +14,10 @@ module Svix
14
14
  return @api.create_event_type_api_v1_event_type_post(event_type_in)
15
15
  end
16
16
 
17
+ def get(event_type_name)
18
+ return @api.get_event_type_api_v1_event_type_event_type_name_get(event_type_name)
19
+ end
20
+
17
21
  def update(event_type_name, event_type_update)
18
22
  return @api.update_event_type_api_v1_event_type_event_type_name_put(event_type_name, event_type_update)
19
23
  end
@@ -26,6 +26,8 @@ module Svix
26
26
  # Optional unique identifier for the application
27
27
  attr_accessor :uid
28
28
 
29
+ attr_accessor :updated_at
30
+
29
31
  # Attribute mapping from ruby-style variable name to JSON key.
30
32
  def self.attribute_map
31
33
  {
@@ -33,7 +35,8 @@ module Svix
33
35
  :'id' => :'id',
34
36
  :'name' => :'name',
35
37
  :'rate_limit' => :'rateLimit',
36
- :'uid' => :'uid'
38
+ :'uid' => :'uid',
39
+ :'updated_at' => :'updatedAt'
37
40
  }
38
41
  end
39
42
 
@@ -49,7 +52,8 @@ module Svix
49
52
  :'id' => :'String',
50
53
  :'name' => :'String',
51
54
  :'rate_limit' => :'Integer',
52
- :'uid' => :'String'
55
+ :'uid' => :'String',
56
+ :'updated_at' => :'Time'
53
57
  }
54
58
  end
55
59
 
@@ -93,6 +97,10 @@ module Svix
93
97
  if attributes.key?(:'uid')
94
98
  self.uid = attributes[:'uid']
95
99
  end
100
+
101
+ if attributes.key?(:'updated_at')
102
+ self.updated_at = attributes[:'updated_at']
103
+ end
96
104
  end
97
105
 
98
106
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -124,6 +132,10 @@ module Svix
124
132
  invalid_properties.push("invalid value for \"uid\", must conform to the pattern #{pattern}.")
125
133
  end
126
134
 
135
+ if @updated_at.nil?
136
+ invalid_properties.push('invalid value for "updated_at", updated_at cannot be nil.')
137
+ end
138
+
127
139
  invalid_properties
128
140
  end
129
141
 
@@ -136,6 +148,7 @@ module Svix
136
148
  return false if !@uid.nil? && @uid.to_s.length > 256
137
149
  return false if !@uid.nil? && @uid.to_s.length < 1
138
150
  return false if !@uid.nil? && @uid !~ Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
151
+ return false if @updated_at.nil?
139
152
  true
140
153
  end
141
154
 
@@ -167,7 +180,8 @@ module Svix
167
180
  id == o.id &&
168
181
  name == o.name &&
169
182
  rate_limit == o.rate_limit &&
170
- uid == o.uid
183
+ uid == o.uid &&
184
+ updated_at == o.updated_at
171
185
  end
172
186
 
173
187
  # @see the `==` method
@@ -179,7 +193,7 @@ module Svix
179
193
  # Calculates hash code according to all attributes.
180
194
  # @return [Integer] Hash code
181
195
  def hash
182
- [created_at, id, name, rate_limit, uid].hash
196
+ [created_at, id, name, rate_limit, uid, updated_at].hash
183
197
  end
184
198
 
185
199
  # Builds the object from hash
@@ -0,0 +1,231 @@
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 AttemptStatisticsData
18
+ attr_accessor :failure_count
19
+
20
+ attr_accessor :success_count
21
+
22
+ # Attribute mapping from ruby-style variable name to JSON key.
23
+ def self.attribute_map
24
+ {
25
+ :'failure_count' => :'failureCount',
26
+ :'success_count' => :'successCount'
27
+ }
28
+ end
29
+
30
+ # Returns all the JSON keys this model knows about
31
+ def self.acceptable_attributes
32
+ attribute_map.values
33
+ end
34
+
35
+ # Attribute type mapping.
36
+ def self.openapi_types
37
+ {
38
+ :'failure_count' => :'Array<Integer>',
39
+ :'success_count' => :'Array<Integer>'
40
+ }
41
+ end
42
+
43
+ # List of attributes with nullable: true
44
+ def self.openapi_nullable
45
+ Set.new([
46
+ ])
47
+ end
48
+
49
+ # Initializes the object
50
+ # @param [Hash] attributes Model attributes in the form of hash
51
+ def initialize(attributes = {})
52
+ if (!attributes.is_a?(Hash))
53
+ fail ArgumentError, "The input argument (attributes) must be a hash in `Svix::AttemptStatisticsData` initialize method"
54
+ end
55
+
56
+ # check to see if the attribute exists and convert string to symbol for hash key
57
+ attributes = attributes.each_with_object({}) { |(k, v), h|
58
+ if (!self.class.attribute_map.key?(k.to_sym))
59
+ fail ArgumentError, "`#{k}` is not a valid attribute in `Svix::AttemptStatisticsData`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
60
+ end
61
+ h[k.to_sym] = v
62
+ }
63
+
64
+ if attributes.key?(:'failure_count')
65
+ if (value = attributes[:'failure_count']).is_a?(Array)
66
+ self.failure_count = value
67
+ end
68
+ end
69
+
70
+ if attributes.key?(:'success_count')
71
+ if (value = attributes[:'success_count']).is_a?(Array)
72
+ self.success_count = value
73
+ end
74
+ end
75
+ end
76
+
77
+ # Show invalid properties with the reasons. Usually used together with valid?
78
+ # @return Array for valid properties with the reasons
79
+ def list_invalid_properties
80
+ invalid_properties = Array.new
81
+ invalid_properties
82
+ end
83
+
84
+ # Check to see if the all the properties in the model are valid
85
+ # @return true if the model is valid
86
+ def valid?
87
+ true
88
+ end
89
+
90
+ # Checks equality by comparing each attribute.
91
+ # @param [Object] Object to be compared
92
+ def ==(o)
93
+ return true if self.equal?(o)
94
+ self.class == o.class &&
95
+ failure_count == o.failure_count &&
96
+ success_count == o.success_count
97
+ end
98
+
99
+ # @see the `==` method
100
+ # @param [Object] Object to be compared
101
+ def eql?(o)
102
+ self == o
103
+ end
104
+
105
+ # Calculates hash code according to all attributes.
106
+ # @return [Integer] Hash code
107
+ def hash
108
+ [failure_count, success_count].hash
109
+ end
110
+
111
+ # Builds the object from hash
112
+ # @param [Hash] attributes Model attributes in the form of hash
113
+ # @return [Object] Returns the model itself
114
+ def self.build_from_hash(attributes)
115
+ new.build_from_hash(attributes)
116
+ end
117
+
118
+ # Builds the object from hash
119
+ # @param [Hash] attributes Model attributes in the form of hash
120
+ # @return [Object] Returns the model itself
121
+ def build_from_hash(attributes)
122
+ return nil unless attributes.is_a?(Hash)
123
+ self.class.openapi_types.each_pair do |key, type|
124
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
125
+ self.send("#{key}=", nil)
126
+ elsif type =~ /\AArray<(.*)>/i
127
+ # check to ensure the input is an array given that the attribute
128
+ # is documented as an array but the input is not
129
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
130
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
131
+ end
132
+ elsif !attributes[self.class.attribute_map[key]].nil?
133
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
134
+ end
135
+ end
136
+
137
+ self
138
+ end
139
+
140
+ # Deserializes the data based on type
141
+ # @param string type Data type
142
+ # @param string value Value to be deserialized
143
+ # @return [Object] Deserialized data
144
+ def _deserialize(type, value)
145
+ case type.to_sym
146
+ when :Time
147
+ Time.parse(value)
148
+ when :Date
149
+ Date.parse(value)
150
+ when :String
151
+ value.to_s
152
+ when :Integer
153
+ value.to_i
154
+ when :Float
155
+ value.to_f
156
+ when :Boolean
157
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
158
+ true
159
+ else
160
+ false
161
+ end
162
+ when :Object
163
+ # generic object (usually a Hash), return directly
164
+ value
165
+ when /\AArray<(?<inner_type>.+)>\z/
166
+ inner_type = Regexp.last_match[:inner_type]
167
+ value.map { |v| _deserialize(inner_type, v) }
168
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
169
+ k_type = Regexp.last_match[:k_type]
170
+ v_type = Regexp.last_match[:v_type]
171
+ {}.tap do |hash|
172
+ value.each do |k, v|
173
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
174
+ end
175
+ end
176
+ else # model
177
+ # models (e.g. Pet) or oneOf
178
+ klass = Svix.const_get(type)
179
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
180
+ end
181
+ end
182
+
183
+ # Returns the string representation of the object
184
+ # @return [String] String presentation of the object
185
+ def to_s
186
+ to_hash.to_s
187
+ end
188
+
189
+ # to_body is an alias to to_hash (backward compatibility)
190
+ # @return [Hash] Returns the object in the form of hash
191
+ def to_body
192
+ to_hash
193
+ end
194
+
195
+ # Returns the object in the form of hash
196
+ # @return [Hash] Returns the object in the form of hash
197
+ def to_hash
198
+ hash = {}
199
+ self.class.attribute_map.each_pair do |attr, param|
200
+ value = self.send(attr)
201
+ if value.nil?
202
+ is_nullable = self.class.openapi_nullable.include?(attr)
203
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
204
+ end
205
+
206
+ hash[param] = _to_hash(value)
207
+ end
208
+ hash
209
+ end
210
+
211
+ # Outputs non-array value in the form of hash
212
+ # For object, use to_hash. Otherwise, just return the value
213
+ # @param [Object] value Any valid value
214
+ # @return [Hash] Returns the value in the form of hash
215
+ def _to_hash(value)
216
+ if value.is_a?(Array)
217
+ value.compact.map { |v| _to_hash(v) }
218
+ elsif value.is_a?(Hash)
219
+ {}.tap do |hash|
220
+ value.each { |k, v| hash[k] = _to_hash(v) }
221
+ end
222
+ elsif value.respond_to? :to_hash
223
+ value.to_hash
224
+ else
225
+ value
226
+ end
227
+ end
228
+
229
+ end
230
+
231
+ end