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,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
@@ -0,0 +1,399 @@
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 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'time'
18
+ require 'typhoeus'
19
+
20
+ module Svix
21
+ class ApiClient
22
+ # The Configuration object holding settings to be used in the API client.
23
+ attr_accessor :config
24
+
25
+ # Defines the headers to be used in HTTP requests of all API calls by default.
26
+ #
27
+ # @return [Hash]
28
+ attr_accessor :default_headers
29
+
30
+ # Initializes the ApiClient
31
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
32
+ def initialize(config = Configuration.default)
33
+ @config = config
34
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
35
+ @default_headers = {
36
+ 'Content-Type' => 'application/json',
37
+ 'User-Agent' => @user_agent
38
+ }
39
+ end
40
+
41
+ def self.default
42
+ @@default ||= ApiClient.new
43
+ end
44
+
45
+ # Call an API with given options.
46
+ #
47
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
48
+ # the data deserialized from response body (could be nil), response status code and response headers.
49
+ def call_api(http_method, path, opts = {})
50
+ request = build_request(http_method, path, opts)
51
+ response = request.run
52
+
53
+ # retry 500s
54
+ sleep_time = 0.05
55
+ (0..1).each do |n|
56
+ break if response.success? && response.code < 500
57
+ sleep(sleep_time)
58
+ sleep_time = sleep_time * 2
59
+ response = request.run
60
+ end
61
+
62
+ if @config.debugging
63
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
64
+ end
65
+
66
+ unless response.success?
67
+ if response.timed_out?
68
+ fail ApiError.new('Connection timed out')
69
+ elsif response.code == 0
70
+ # Errors from libcurl will be made visible here
71
+ fail ApiError.new(:code => 0,
72
+ :message => response.return_message)
73
+ else
74
+ fail ApiError.new(:code => response.code,
75
+ :response_headers => response.headers,
76
+ :response_body => response.body),
77
+ response.status_message
78
+ end
79
+ end
80
+
81
+ if opts[:return_type]
82
+ data = deserialize(response, opts[:return_type])
83
+ else
84
+ data = nil
85
+ end
86
+ return data, response.code, response.headers
87
+ end
88
+
89
+ # Builds the HTTP request
90
+ #
91
+ # @param [String] http_method HTTP method/verb (e.g. POST)
92
+ # @param [String] path URL path (e.g. /account/new)
93
+ # @option opts [Hash] :header_params Header parameters
94
+ # @option opts [Hash] :query_params Query parameters
95
+ # @option opts [Hash] :form_params Query parameters
96
+ # @option opts [Object] :body HTTP body (JSON/XML)
97
+ # @return [Typhoeus::Request] A Typhoeus Request
98
+ def build_request(http_method, path, opts = {})
99
+ url = build_request_url(path, opts)
100
+ http_method = http_method.to_sym.downcase
101
+
102
+ header_params = @default_headers.merge(opts[:header_params] || {})
103
+ query_params = opts[:query_params] || {}
104
+ form_params = opts[:form_params] || {}
105
+
106
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
107
+
108
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
109
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
110
+
111
+ req_opts = {
112
+ :method => http_method,
113
+ :headers => header_params,
114
+ :params => query_params,
115
+ :params_encoding => @config.params_encoding,
116
+ :timeout => @config.timeout,
117
+ :ssl_verifypeer => @config.verify_ssl,
118
+ :ssl_verifyhost => _verify_ssl_host,
119
+ :sslcert => @config.cert_file,
120
+ :sslkey => @config.key_file,
121
+ :verbose => @config.debugging
122
+ }
123
+
124
+ # set custom cert, if provided
125
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
126
+
127
+ if [:post, :patch, :put, :delete].include?(http_method)
128
+ req_body = build_request_body(header_params, form_params, opts[:body])
129
+ req_opts.update :body => req_body
130
+ if @config.debugging
131
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
132
+ end
133
+ end
134
+
135
+ request = Typhoeus::Request.new(url, req_opts)
136
+ download_file(request) if opts[:return_type] == 'File'
137
+ request
138
+ end
139
+
140
+ # Builds the HTTP request body
141
+ #
142
+ # @param [Hash] header_params Header parameters
143
+ # @param [Hash] form_params Query parameters
144
+ # @param [Object] body HTTP body (JSON/XML)
145
+ # @return [String] HTTP body data in the form of string
146
+ def build_request_body(header_params, form_params, body)
147
+ # http form
148
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
149
+ header_params['Content-Type'] == 'multipart/form-data'
150
+ data = {}
151
+ form_params.each do |key, value|
152
+ case value
153
+ when ::File, ::Array, nil
154
+ # let typhoeus handle File, Array and nil parameters
155
+ data[key] = value
156
+ else
157
+ data[key] = value.to_s
158
+ end
159
+ end
160
+ elsif body
161
+ data = body.is_a?(String) ? body : body.to_json
162
+ else
163
+ data = nil
164
+ end
165
+ data
166
+ end
167
+
168
+ # Save response body into a file in (the defined) temporary folder, using the filename
169
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
170
+ # The response body is written to the file in chunks in order to handle files which
171
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
172
+ # process can use.
173
+ #
174
+ # @see Configuration#temp_folder_path
175
+ def download_file(request)
176
+ tempfile = nil
177
+ encoding = nil
178
+ request.on_headers do |response|
179
+ content_disposition = response.headers['Content-Disposition']
180
+ if content_disposition && content_disposition =~ /filename=/i
181
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
182
+ prefix = sanitize_filename(filename)
183
+ else
184
+ prefix = 'download-'
185
+ end
186
+ prefix = prefix + '-' unless prefix.end_with?('-')
187
+ encoding = response.body.encoding
188
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
189
+ @tempfile = tempfile
190
+ end
191
+ request.on_body do |chunk|
192
+ chunk.force_encoding(encoding)
193
+ tempfile.write(chunk)
194
+ end
195
+ request.on_complete do |response|
196
+ if tempfile
197
+ tempfile.close
198
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
199
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
200
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
201
+ "explicitly with `tempfile.delete`"
202
+ end
203
+ end
204
+ end
205
+
206
+ # Check if the given MIME is a JSON MIME.
207
+ # JSON MIME examples:
208
+ # application/json
209
+ # application/json; charset=UTF8
210
+ # APPLICATION/JSON
211
+ # */*
212
+ # @param [String] mime MIME
213
+ # @return [Boolean] True if the MIME is application/json
214
+ def json_mime?(mime)
215
+ (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
216
+ end
217
+
218
+ # Deserialize the response to the given return type.
219
+ #
220
+ # @param [Response] response HTTP response
221
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
222
+ def deserialize(response, return_type)
223
+ body = response.body
224
+
225
+ # handle file downloading - return the File instance processed in request callbacks
226
+ # note that response body is empty when the file is written in chunks in request on_body callback
227
+ return @tempfile if return_type == 'File'
228
+
229
+ return nil if body.nil? || body.empty?
230
+
231
+ # return response body directly for String return type
232
+ return body if return_type == 'String'
233
+
234
+ # ensuring a default content type
235
+ content_type = response.headers['Content-Type'] || 'application/json'
236
+
237
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
238
+
239
+ begin
240
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
241
+ rescue JSON::ParserError => e
242
+ if %w(String Date Time).include?(return_type)
243
+ data = body
244
+ else
245
+ raise e
246
+ end
247
+ end
248
+
249
+ convert_to_type data, return_type
250
+ end
251
+
252
+ # Convert data to the given return type.
253
+ # @param [Object] data Data to be converted
254
+ # @param [String] return_type Return type
255
+ # @return [Mixed] Data in a particular type
256
+ def convert_to_type(data, return_type)
257
+ return nil if data.nil?
258
+ case return_type
259
+ when 'String'
260
+ data.to_s
261
+ when 'Integer'
262
+ data.to_i
263
+ when 'Float'
264
+ data.to_f
265
+ when 'Boolean'
266
+ data == true
267
+ when 'Time'
268
+ # parse date time (expecting ISO 8601 format)
269
+ Time.parse data
270
+ when 'Date'
271
+ # parse date time (expecting ISO 8601 format)
272
+ Date.parse data
273
+ when 'Object'
274
+ # generic object (usually a Hash), return directly
275
+ data
276
+ when /\AArray<(.+)>\z/
277
+ # e.g. Array<Pet>
278
+ sub_type = $1
279
+ data.map { |item| convert_to_type(item, sub_type) }
280
+ when /\AHash\<String, (.+)\>\z/
281
+ # e.g. Hash<String, Integer>
282
+ sub_type = $1
283
+ {}.tap do |hash|
284
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
285
+ end
286
+ else
287
+ # models (e.g. Pet) or oneOf
288
+ klass = Svix.const_get(return_type)
289
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
290
+ end
291
+ end
292
+
293
+ # Sanitize filename by removing path.
294
+ # e.g. ../../sun.gif becomes sun.gif
295
+ #
296
+ # @param [String] filename the filename to be sanitized
297
+ # @return [String] the sanitized filename
298
+ def sanitize_filename(filename)
299
+ filename.gsub(/.*[\/\\]/, '')
300
+ end
301
+
302
+ def build_request_url(path, opts = {})
303
+ # Add leading and trailing slashes to path
304
+ path = "/#{path}".gsub(/\/+/, '/')
305
+ @config.base_url(opts[:operation]) + path
306
+ end
307
+
308
+ # Update hearder and query params based on authentication settings.
309
+ #
310
+ # @param [Hash] header_params Header parameters
311
+ # @param [Hash] query_params Query parameters
312
+ # @param [String] auth_names Authentication scheme name
313
+ def update_params_for_auth!(header_params, query_params, auth_names)
314
+ Array(auth_names).each do |auth_name|
315
+ auth_setting = @config.auth_settings[auth_name]
316
+ next unless auth_setting
317
+ case auth_setting[:in]
318
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
319
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
320
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
321
+ end
322
+ end
323
+ end
324
+
325
+ # Sets user agent in HTTP header
326
+ #
327
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
328
+ def user_agent=(user_agent)
329
+ @user_agent = user_agent
330
+ @default_headers['User-Agent'] = @user_agent
331
+ end
332
+
333
+ # Return Accept header based on an array of accepts provided.
334
+ # @param [Array] accepts array for Accept
335
+ # @return [String] the Accept header (e.g. application/json)
336
+ def select_header_accept(accepts)
337
+ return nil if accepts.nil? || accepts.empty?
338
+ # use JSON when present, otherwise use all of the provided
339
+ json_accept = accepts.find { |s| json_mime?(s) }
340
+ json_accept || accepts.join(',')
341
+ end
342
+
343
+ # Return Content-Type header based on an array of content types provided.
344
+ # @param [Array] content_types array for Content-Type
345
+ # @return [String] the Content-Type header (e.g. application/json)
346
+ def select_header_content_type(content_types)
347
+ # use application/json by default
348
+ return 'application/json' if content_types.nil? || content_types.empty?
349
+ # use JSON when present, otherwise use the first one
350
+ json_content_type = content_types.find { |s| json_mime?(s) }
351
+ json_content_type || content_types.first
352
+ end
353
+
354
+ # Convert object (array, hash, object, etc) to JSON string.
355
+ # @param [Object] model object to be converted into JSON string
356
+ # @return [String] JSON string representation of the object
357
+ def object_to_http_body(model)
358
+ return model if model.nil? || model.is_a?(String)
359
+ local_body = nil
360
+ if model.is_a?(Array)
361
+ local_body = model.map { |m| object_to_hash(m) }
362
+ else
363
+ local_body = object_to_hash(model)
364
+ end
365
+ local_body.to_json
366
+ end
367
+
368
+ # Convert object(non-array) to hash.
369
+ # @param [Object] obj object to be converted into JSON string
370
+ # @return [String] JSON string representation of the object
371
+ def object_to_hash(obj)
372
+ if obj.respond_to?(:to_hash)
373
+ obj.to_hash
374
+ else
375
+ obj
376
+ end
377
+ end
378
+
379
+ # Build parameter value according to the given collection format.
380
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
381
+ def build_collection_param(param, collection_format)
382
+ case collection_format
383
+ when :csv
384
+ param.join(',')
385
+ when :ssv
386
+ param.join(' ')
387
+ when :tsv
388
+ param.join("\t")
389
+ when :pipes
390
+ param.join('|')
391
+ when :multi
392
+ # return the array directly as typhoeus will handle it as expected
393
+ param
394
+ else
395
+ fail "unknown collection format: #{collection_format.inspect}"
396
+ end
397
+ end
398
+ end
399
+ end
@@ -0,0 +1,57 @@
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
+ module Svix
14
+ class ApiError < StandardError
15
+ attr_reader :code, :response_headers, :response_body
16
+
17
+ # Usage examples:
18
+ # ApiError.new
19
+ # ApiError.new("message")
20
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
21
+ # ApiError.new(:code => 404, :message => "Not Found")
22
+ def initialize(arg = nil)
23
+ if arg.is_a? Hash
24
+ if arg.key?(:message) || arg.key?('message')
25
+ super(arg[:message] || arg['message'])
26
+ else
27
+ super arg
28
+ end
29
+
30
+ arg.each do |k, v|
31
+ instance_variable_set "@#{k}", v
32
+ end
33
+ else
34
+ super arg
35
+ end
36
+ end
37
+
38
+ # Override to_s to display a friendly error message
39
+ def to_s
40
+ message
41
+ end
42
+
43
+ def message
44
+ if @message.nil?
45
+ msg = "Error message: the server returns an error"
46
+ else
47
+ msg = @message
48
+ end
49
+
50
+ msg += "\nHTTP status code: #{code}" if code
51
+ msg += "\nResponse headers: #{response_headers}" if response_headers
52
+ msg += "\nResponse body: #{response_body}" if response_body
53
+
54
+ msg
55
+ end
56
+ end
57
+ end