svix 1.38.0 → 1.40.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +5 -5
  3. data/README.md +8 -1
  4. data/lib/svix/api/application_api.rb +23 -14
  5. data/lib/svix/api/authentication_api.rb +23 -11
  6. data/lib/svix/api/background_tasks_api.rb +3 -3
  7. data/lib/svix/api/broadcast_api.rb +6 -3
  8. data/lib/svix/api/endpoint_api.rb +86 -44
  9. data/lib/svix/api/environment_api.rb +8 -5
  10. data/lib/svix/api/environment_settings_api.rb +2 -2
  11. data/lib/svix/api/event_type_api.rb +39 -21
  12. data/lib/svix/api/events_api.rb +2 -2
  13. data/lib/svix/api/health_api.rb +2 -2
  14. data/lib/svix/api/inbound_api.rb +7 -4
  15. data/lib/svix/api/integration_api.rb +16 -10
  16. data/lib/svix/api/message_api.rb +21 -15
  17. data/lib/svix/api/message_attempt_api.rb +25 -25
  18. data/lib/svix/api/statistics_api.rb +9 -6
  19. data/lib/svix/api/stream_api.rb +176 -10
  20. data/lib/svix/api/stream_event_types_api.rb +486 -0
  21. data/lib/svix/api/transformation_template_api.rb +49 -22
  22. data/lib/svix/api/webhook_endpoint_api.rb +572 -0
  23. data/lib/svix/api_client.rb +45 -28
  24. data/lib/svix/api_error.rb +2 -1
  25. data/lib/svix/configuration.rb +42 -12
  26. data/lib/svix/models/aggregate_event_types_out.rb +43 -19
  27. data/lib/svix/models/app_portal_access_in.rb +19 -19
  28. data/lib/svix/models/app_portal_access_out.rb +19 -19
  29. data/lib/svix/models/app_usage_stats_in.rb +19 -19
  30. data/lib/svix/models/app_usage_stats_out.rb +43 -19
  31. data/lib/svix/models/application_in.rb +17 -19
  32. data/lib/svix/models/application_out.rb +25 -19
  33. data/lib/svix/models/application_patch.rb +15 -19
  34. data/lib/svix/models/application_stats.rb +19 -19
  35. data/lib/svix/models/application_token_expire_in.rb +15 -19
  36. data/lib/svix/models/attempt_statistics_data.rb +15 -19
  37. data/lib/svix/models/attempt_statistics_response.rb +45 -19
  38. data/lib/svix/models/auth_token_out.rb +21 -19
  39. data/lib/svix/models/azure_blob_storage_config.rb +21 -19
  40. data/lib/svix/models/background_task_out.rb +45 -19
  41. data/lib/svix/models/background_task_status.rb +7 -4
  42. data/lib/svix/models/background_task_type.rb +7 -4
  43. data/lib/svix/models/big_query_config.rb +271 -0
  44. data/lib/svix/models/border_radius_config.rb +37 -19
  45. data/lib/svix/models/border_radius_enum.rb +7 -4
  46. data/lib/svix/models/client_secret_jwt_params_in.rb +41 -19
  47. data/lib/svix/models/completion_choice.rb +21 -19
  48. data/lib/svix/models/completion_message.rb +19 -19
  49. data/lib/svix/models/create_message_token_in.rb +17 -19
  50. data/lib/svix/models/create_stream_in.rb +30 -23
  51. data/lib/svix/models/custom_color_palette.rb +15 -19
  52. data/lib/svix/models/custom_strings_override.rb +15 -19
  53. data/lib/svix/models/custom_theme_override.rb +15 -19
  54. data/lib/svix/models/dashboard_access_out.rb +19 -19
  55. data/lib/svix/models/duration.rb +19 -19
  56. data/lib/svix/models/endpoint_created_event.rb +17 -19
  57. data/lib/svix/models/endpoint_created_event_data.rb +19 -19
  58. data/lib/svix/models/endpoint_deleted_event.rb +17 -19
  59. data/lib/svix/models/endpoint_deleted_event_data.rb +19 -19
  60. data/lib/svix/models/endpoint_disabled_event.rb +17 -19
  61. data/lib/svix/models/endpoint_disabled_event_data.rb +21 -19
  62. data/lib/svix/models/endpoint_headers_in.rb +17 -19
  63. data/lib/svix/models/endpoint_headers_out.rb +19 -19
  64. data/lib/svix/models/endpoint_headers_patch_in.rb +17 -19
  65. data/lib/svix/models/endpoint_in.rb +17 -19
  66. data/lib/svix/models/endpoint_message_out.rb +47 -19
  67. data/lib/svix/models/endpoint_mtls_config_in.rb +17 -19
  68. data/lib/svix/models/endpoint_oauth_config_in.rb +45 -19
  69. data/lib/svix/models/endpoint_out.rb +29 -19
  70. data/lib/svix/models/endpoint_patch.rb +20 -20
  71. data/lib/svix/models/endpoint_secret_out.rb +17 -19
  72. data/lib/svix/models/endpoint_secret_rotate_in.rb +15 -21
  73. data/lib/svix/models/endpoint_stats.rb +23 -19
  74. data/lib/svix/models/endpoint_transformation_in.rb +15 -19
  75. data/lib/svix/models/endpoint_transformation_out.rb +15 -19
  76. data/lib/svix/models/endpoint_transformation_simulate_in.rb +21 -19
  77. data/lib/svix/models/endpoint_transformation_simulate_out.rb +41 -19
  78. data/lib/svix/models/endpoint_update.rb +17 -19
  79. data/lib/svix/models/endpoint_updated_event.rb +17 -19
  80. data/lib/svix/models/endpoint_updated_event_data.rb +19 -19
  81. data/lib/svix/models/environment_in.rb +19 -19
  82. data/lib/svix/models/environment_out.rb +21 -19
  83. data/lib/svix/models/environment_settings_out.rb +15 -19
  84. data/lib/svix/models/event_example_in.rb +52 -23
  85. data/lib/svix/models/event_in.rb +55 -20
  86. data/lib/svix/models/event_out.rb +57 -20
  87. data/lib/svix/models/event_stream_out.rb +21 -19
  88. data/lib/svix/models/event_type_example_out.rb +17 -19
  89. data/lib/svix/models/event_type_from_open_api.rb +95 -20
  90. data/lib/svix/models/event_type_import_open_api_in.rb +15 -19
  91. data/lib/svix/models/event_type_import_open_api_out.rb +17 -19
  92. data/lib/svix/models/event_type_import_open_api_out_data.rb +17 -19
  93. data/lib/svix/models/event_type_in.rb +19 -19
  94. data/lib/svix/models/event_type_out.rb +25 -19
  95. data/lib/svix/models/event_type_patch.rb +15 -19
  96. data/lib/svix/models/event_type_schema_in.rb +17 -19
  97. data/lib/svix/models/event_type_update.rb +17 -19
  98. data/lib/svix/models/export_event_type_out.rb +43 -19
  99. data/lib/svix/models/font_size_config.rb +15 -19
  100. data/lib/svix/models/generate_in.rb +17 -19
  101. data/lib/svix/models/generate_out.rb +25 -19
  102. data/lib/svix/models/google_cloud_storage_config.rb +19 -19
  103. data/lib/svix/models/http_error_out.rb +19 -19
  104. data/lib/svix/models/http_validation_error.rb +17 -19
  105. data/lib/svix/models/hubspot_oauth_config_in.rb +17 -19
  106. data/lib/svix/models/inbound_path_params.rb +19 -19
  107. data/lib/svix/models/incoming_webhook_payload_out.rb +15 -19
  108. data/lib/svix/models/integration_in.rb +17 -19
  109. data/lib/svix/models/integration_key_out.rb +17 -19
  110. data/lib/svix/models/integration_out.rb +23 -19
  111. data/lib/svix/models/integration_update.rb +17 -19
  112. data/lib/svix/models/kafka_security_protocol_type.rb +7 -4
  113. data/lib/svix/models/list_response_application_out.rb +19 -19
  114. data/lib/svix/models/list_response_application_stats.rb +19 -19
  115. data/lib/svix/models/list_response_background_task_out.rb +19 -19
  116. data/lib/svix/models/list_response_endpoint_message_out.rb +19 -19
  117. data/lib/svix/models/list_response_endpoint_out.rb +19 -19
  118. data/lib/svix/models/list_response_event_type_out.rb +19 -19
  119. data/lib/svix/models/list_response_integration_out.rb +19 -19
  120. data/lib/svix/models/list_response_message_attempt_endpoint_out.rb +19 -19
  121. data/lib/svix/models/list_response_message_attempt_out.rb +19 -19
  122. data/lib/svix/models/list_response_message_endpoint_out.rb +19 -19
  123. data/lib/svix/models/list_response_message_out.rb +19 -19
  124. data/lib/svix/models/list_response_operational_webhook_endpoint_out.rb +259 -0
  125. data/lib/svix/models/list_response_sink_out.rb +19 -19
  126. data/lib/svix/models/list_response_stream_event_type_out.rb +259 -0
  127. data/lib/svix/models/list_response_stream_out.rb +19 -19
  128. data/lib/svix/models/list_response_stream_sink_out.rb +19 -19
  129. data/lib/svix/models/list_response_template_out.rb +19 -19
  130. data/lib/svix/models/message_attempt_endpoint_out.rb +57 -19
  131. data/lib/svix/models/message_attempt_exhausted_event.rb +17 -19
  132. data/lib/svix/models/message_attempt_exhausted_event_data.rb +23 -19
  133. data/lib/svix/models/message_attempt_failed_data.rb +21 -19
  134. data/lib/svix/models/message_attempt_failing_event.rb +17 -19
  135. data/lib/svix/models/message_attempt_failing_event_data.rb +23 -19
  136. data/lib/svix/models/message_attempt_headers_out.rb +19 -19
  137. data/lib/svix/models/message_attempt_out.rb +57 -19
  138. data/lib/svix/models/message_attempt_recovered_event.rb +17 -19
  139. data/lib/svix/models/message_attempt_recovered_event_data.rb +23 -19
  140. data/lib/svix/models/message_attempt_trigger_type.rb +7 -4
  141. data/lib/svix/models/message_broadcast_in.rb +19 -19
  142. data/lib/svix/models/message_broadcast_out.rb +43 -19
  143. data/lib/svix/models/message_endpoint_out.rb +51 -19
  144. data/lib/svix/models/message_events_out.rb +21 -19
  145. data/lib/svix/models/message_in.rb +19 -19
  146. data/lib/svix/models/message_out.rb +23 -19
  147. data/lib/svix/models/message_raw_payload_out.rb +17 -19
  148. data/lib/svix/models/message_status.rb +7 -4
  149. data/lib/svix/models/message_subscriber_auth_token_out.rb +19 -19
  150. data/lib/svix/models/o_auth_payload_in.rb +19 -19
  151. data/lib/svix/models/o_auth_payload_out.rb +15 -19
  152. data/lib/svix/models/oauth2_auth_method_in.rb +7 -4
  153. data/lib/svix/models/oauth2_grant_type_in.rb +7 -4
  154. data/lib/svix/models/oauth_jws_signing_algorithm.rb +7 -4
  155. data/lib/svix/models/one_time_token_in.rb +17 -19
  156. data/lib/svix/models/one_time_token_out.rb +17 -19
  157. data/lib/svix/models/operational_webhook_endpoint_in.rb +408 -0
  158. data/lib/svix/models/operational_webhook_endpoint_out.rb +442 -0
  159. data/lib/svix/models/operational_webhook_endpoint_secret_in.rb +233 -0
  160. data/lib/svix/models/operational_webhook_endpoint_secret_out.rb +243 -0
  161. data/lib/svix/models/operational_webhook_endpoint_update.rb +380 -0
  162. data/lib/svix/models/ordering.rb +7 -4
  163. data/lib/svix/models/recover_in.rb +17 -19
  164. data/lib/svix/models/recover_out.rb +43 -19
  165. data/lib/svix/models/redshift_config.rb +25 -19
  166. data/lib/svix/models/replay_in.rb +17 -19
  167. data/lib/svix/models/replay_out.rb +43 -19
  168. data/lib/svix/models/retry_schedule_in_out.rb +15 -19
  169. data/lib/svix/models/rotated_url_out.rb +17 -19
  170. data/lib/svix/models/s3_config.rb +23 -19
  171. data/lib/svix/models/settings_in.rb +15 -19
  172. data/lib/svix/models/settings_out.rb +15 -19
  173. data/lib/svix/models/sink_http_config.rb +17 -19
  174. data/lib/svix/models/sink_in.rb +4 -4
  175. data/lib/svix/models/sink_in_one_of.rb +21 -19
  176. data/lib/svix/models/sink_in_one_of1.rb +25 -19
  177. data/lib/svix/models/sink_in_one_of2.rb +23 -19
  178. data/lib/svix/models/sink_in_one_of3.rb +19 -19
  179. data/lib/svix/models/sink_otel_v1_config.rb +17 -19
  180. data/lib/svix/models/sink_out.rb +4 -4
  181. data/lib/svix/models/sink_payload_format.rb +7 -4
  182. data/lib/svix/models/sink_status.rb +7 -4
  183. data/lib/svix/models/sink_status_in.rb +7 -4
  184. data/lib/svix/models/sink_transform_in.rb +15 -19
  185. data/lib/svix/models/sink_transformation_out.rb +15 -19
  186. data/lib/svix/models/snowflake_config.rb +21 -19
  187. data/lib/svix/models/statistics_period.rb +7 -4
  188. data/lib/svix/models/status_code_class.rb +7 -4
  189. data/lib/svix/models/stream_event_type_in.rb +262 -0
  190. data/lib/svix/models/stream_event_type_out.rb +294 -0
  191. data/lib/svix/models/stream_event_type_patch.rb +254 -0
  192. data/lib/svix/models/stream_in.rb +24 -22
  193. data/lib/svix/models/stream_out.rb +28 -22
  194. data/lib/svix/models/stream_patch.rb +22 -22
  195. data/lib/svix/models/stream_sink_in.rb +6 -5
  196. data/lib/svix/models/stream_sink_in_one_of.rb +19 -19
  197. data/lib/svix/models/stream_sink_in_one_of1.rb +19 -19
  198. data/lib/svix/models/stream_sink_in_one_of2.rb +19 -19
  199. data/lib/svix/models/stream_sink_in_one_of3.rb +19 -19
  200. data/lib/svix/models/stream_sink_in_one_of4.rb +19 -19
  201. data/lib/svix/models/stream_sink_in_one_of5.rb +19 -19
  202. data/lib/svix/models/stream_sink_in_one_of6.rb +19 -19
  203. data/lib/svix/models/stream_sink_in_one_of7.rb +271 -0
  204. data/lib/svix/models/stream_sink_out.rb +6 -5
  205. data/lib/svix/models/stream_sink_patch.rb +6 -5
  206. data/lib/svix/models/template_in.rb +43 -21
  207. data/lib/svix/models/template_out.rb +57 -19
  208. data/lib/svix/models/template_patch.rb +43 -21
  209. data/lib/svix/models/template_update.rb +41 -19
  210. data/lib/svix/models/transformation_http_method.rb +7 -4
  211. data/lib/svix/models/transformation_simulate_in.rb +21 -19
  212. data/lib/svix/models/transformation_simulate_out.rb +41 -19
  213. data/lib/svix/models/transformation_template_kind.rb +7 -4
  214. data/lib/svix/models/validation_error.rb +21 -19
  215. data/lib/svix/operational_webhook_endpoint_api.rb +37 -0
  216. data/lib/svix/version.rb +1 -1
  217. data/svix.gemspec +12 -2
  218. metadata +45 -22
  219. data/lib/svix/api/sink_api.rb +0 -176
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: 1.1.1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 5.2.0
9
+ Generator version: 7.9.0
10
10
 
11
11
  =end
12
12
 
@@ -17,6 +17,7 @@ require 'tempfile'
17
17
  require 'time'
18
18
  require 'typhoeus'
19
19
 
20
+
20
21
  module Svix
21
22
  class ApiClient
22
23
  # The Configuration object holding settings to be used in the API client.
@@ -43,14 +44,15 @@ module Svix
43
44
  end
44
45
 
45
46
  require 'securerandom'
46
-
47
+
47
48
  # Call an API with given options.
48
49
  #
49
50
  # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
50
- # the data deserialized from response body (could be nil), response status code and response headers.
51
+ # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
51
52
  def call_api(http_method, path, opts = {})
52
53
  opts[:'header_params'][:'svix-req-id'] = SecureRandom.random_number(2**32).to_s
53
54
  request = build_request(http_method, path, opts)
55
+ tempfile = download_file(request) if opts[:return_type] == 'File'
54
56
  response = request.run
55
57
 
56
58
  # retry on 5XX and general network errors
@@ -63,6 +65,7 @@ module Svix
63
65
  sleep_time = sleep_time * 2
64
66
  opts[:'header_params'][:'svix-retry-count'] = retry_count.to_s
65
67
  request = build_request(http_method, path, opts)
68
+ tempfile = download_file(request) if opts[:return_type] == 'File'
66
69
  response = request.run
67
70
  end
68
71
 
@@ -85,7 +88,9 @@ module Svix
85
88
  end
86
89
  end
87
90
 
88
- if opts[:return_type]
91
+ if opts[:return_type] == 'File'
92
+ data = tempfile
93
+ elsif opts[:return_type]
89
94
  data = deserialize(response, opts[:return_type])
90
95
  else
91
96
  data = nil
@@ -103,12 +108,25 @@ module Svix
103
108
  # @option opts [Object] :body HTTP body (JSON/XML)
104
109
  # @return [Typhoeus::Request] A Typhoeus Request
105
110
  def build_request(http_method, path, opts = {})
111
+
112
+ begin
113
+ require 'typhoeus'
114
+ rescue LoadError
115
+ raise <<~MESSAGE
116
+ To use svix for sending outgoing webhooks, you need to install the typheous gem.
117
+ Please add it to your Gemfile and then run `bundle install`:
118
+
119
+ gem 'typhoeus'
120
+ MESSAGE
121
+ end
122
+
106
123
  url = build_request_url(path, opts)
107
124
  http_method = http_method.to_sym.downcase
108
125
 
109
126
  header_params = @default_headers.merge(opts[:header_params] || {})
110
127
  query_params = opts[:query_params] || {}
111
128
  form_params = opts[:form_params] || {}
129
+ follow_location = opts[:follow_location] || true
112
130
 
113
131
  update_params_for_auth! header_params, query_params, opts[:auth_names]
114
132
 
@@ -125,7 +143,8 @@ module Svix
125
143
  :ssl_verifyhost => _verify_ssl_host,
126
144
  :sslcert => @config.cert_file,
127
145
  :sslkey => @config.key_file,
128
- :verbose => @config.debugging
146
+ :verbose => @config.debugging,
147
+ :followlocation => follow_location
129
148
  }
130
149
 
131
150
  # set custom cert, if provided
@@ -139,9 +158,7 @@ module Svix
139
158
  end
140
159
  end
141
160
 
142
- request = Typhoeus::Request.new(url, req_opts)
143
- download_file(request) if opts[:return_type] == 'File'
144
- request
161
+ Typhoeus::Request.new(url, req_opts)
145
162
  end
146
163
 
147
164
  # Builds the HTTP request body
@@ -179,6 +196,8 @@ module Svix
179
196
  # process can use.
180
197
  #
181
198
  # @see Configuration#temp_folder_path
199
+ #
200
+ # @return [Tempfile] the tempfile generated
182
201
  def download_file(request)
183
202
  tempfile = nil
184
203
  encoding = nil
@@ -193,21 +212,24 @@ module Svix
193
212
  prefix = prefix + '-' unless prefix.end_with?('-')
194
213
  encoding = response.body.encoding
195
214
  tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
196
- @tempfile = tempfile
197
215
  end
198
216
  request.on_body do |chunk|
199
217
  chunk.force_encoding(encoding)
200
218
  tempfile.write(chunk)
201
219
  end
202
- request.on_complete do |response|
203
- if tempfile
204
- tempfile.close
205
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
206
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
207
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
208
- "explicitly with `tempfile.delete`"
209
- end
220
+ # run the request to ensure the tempfile is created successfully before returning it
221
+ request.run
222
+ if tempfile
223
+ tempfile.close
224
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
225
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
226
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
227
+ "explicitly with `tempfile.delete`"
228
+ else
229
+ fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
210
230
  end
231
+
232
+ tempfile
211
233
  end
212
234
 
213
235
  # Check if the given MIME is a JSON MIME.
@@ -219,7 +241,7 @@ module Svix
219
241
  # @param [String] mime MIME
220
242
  # @return [Boolean] True if the MIME is application/json
221
243
  def json_mime?(mime)
222
- (mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
244
+ (mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
223
245
  end
224
246
 
225
247
  # Deserialize the response to the given return type.
@@ -228,15 +250,10 @@ module Svix
228
250
  # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
229
251
  def deserialize(response, return_type)
230
252
  body = response.body
231
-
232
- # handle file downloading - return the File instance processed in request callbacks
233
- # note that response body is empty when the file is written in chunks in request on_body callback
234
- return @tempfile if return_type == 'File'
235
-
236
253
  return nil if body.nil? || body.empty?
237
254
 
238
255
  # return response body directly for String return type
239
- return body if return_type == 'String'
256
+ return body.to_s if return_type == 'String'
240
257
 
241
258
  # ensuring a default content type
242
259
  content_type = response.headers['Content-Type'] || 'application/json'
@@ -303,7 +320,7 @@ module Svix
303
320
  # @param [String] filename the filename to be sanitized
304
321
  # @return [String] the sanitized filename
305
322
  def sanitize_filename(filename)
306
- filename.gsub(/.*[\/\\]/, '')
323
+ filename.split(/[\/\\]/).last
307
324
  end
308
325
 
309
326
  def build_request_url(path, opts = {})
@@ -312,7 +329,7 @@ module Svix
312
329
  @config.base_url(opts[:operation]) + path
313
330
  end
314
331
 
315
- # Update hearder and query params based on authentication settings.
332
+ # Update header and query params based on authentication settings.
316
333
  #
317
334
  # @param [Hash] header_params Header parameters
318
335
  # @param [Hash] query_params Query parameters
@@ -351,8 +368,8 @@ module Svix
351
368
  # @param [Array] content_types array for Content-Type
352
369
  # @return [String] the Content-Type header (e.g. application/json)
353
370
  def select_header_content_type(content_types)
354
- # use application/json by default
355
- return 'application/json' if content_types.nil? || content_types.empty?
371
+ # return nil by default
372
+ return if content_types.nil? || content_types.empty?
356
373
  # use JSON when present, otherwise use the first one
357
374
  json_content_type = content_types.find { |s| json_mime?(s) }
358
375
  json_content_type || content_types.first
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: 1.1.1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 5.2.0
9
+ Generator version: 7.9.0
10
10
 
11
11
  =end
12
12
 
@@ -32,6 +32,7 @@ module Svix
32
32
  end
33
33
  else
34
34
  super arg
35
+ @message = arg
35
36
  end
36
37
  end
37
38
 
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: 1.1.1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 5.2.0
9
+ Generator version: 7.9.0
10
10
 
11
11
  =end
12
12
 
@@ -62,6 +62,16 @@ module Svix
62
62
  # Defines the access token (Bearer) used with OAuth2.
63
63
  attr_accessor :access_token
64
64
 
65
+ # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
66
+ # Overrides the access_token if set
67
+ # @return [Proc]
68
+ attr_accessor :access_token_getter
69
+
70
+ # Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
71
+ # HTTP responses with return type `File` will be returned as a stream of binary data.
72
+ # Default to false.
73
+ attr_accessor :return_binary_data
74
+
65
75
  # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
66
76
  # details will be logged with `logger.debug` (see the `logger` attribute).
67
77
  # Default to false.
@@ -69,6 +79,14 @@ module Svix
69
79
  # @return [true, false]
70
80
  attr_accessor :debugging
71
81
 
82
+ # Set this to ignore operation servers for the API client. This is useful when you need to
83
+ # send requests to a different server than the one specified in the OpenAPI document.
84
+ # Will default to the base url defined in the spec but can be overridden by setting
85
+ # `scheme`, `host`, `base_path` directly.
86
+ # Default to false.
87
+ # @return [true, false]
88
+ attr_accessor :ignore_operation_servers
89
+
72
90
  # Defines the logger used for debugging.
73
91
  # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
74
92
  #
@@ -133,6 +151,7 @@ module Svix
133
151
  # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
134
152
  attr_accessor :params_encoding
135
153
 
154
+
136
155
  attr_accessor :inject_format
137
156
 
138
157
  attr_accessor :force_ending_format
@@ -141,20 +160,21 @@ module Svix
141
160
  @scheme = 'https'
142
161
  @host = 'api.eu.svix.com'
143
162
  @base_path = ''
144
- @server_index = 0
163
+ @server_index = nil
145
164
  @server_operation_index = {}
146
165
  @server_variables = {}
147
166
  @server_operation_variables = {}
148
167
  @api_key = {}
149
168
  @api_key_prefix = {}
150
- @timeout = 0
151
169
  @client_side_validation = true
152
170
  @verify_ssl = true
153
171
  @verify_ssl_host = true
154
- @params_encoding = nil
155
172
  @cert_file = nil
156
173
  @key_file = nil
174
+ @timeout = 0
175
+ @params_encoding = nil
157
176
  @debugging = false
177
+ @ignore_operation_servers = false
158
178
  @inject_format = false
159
179
  @force_ending_format = false
160
180
  @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
@@ -189,10 +209,13 @@ module Svix
189
209
 
190
210
  # Returns base URL for specified operation based on server settings
191
211
  def base_url(operation = nil)
192
- index = server_operation_index.fetch(operation, server_index)
193
- return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
194
-
195
- server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
212
+ return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if ignore_operation_servers
213
+ if operation_server_settings.key?(operation) then
214
+ index = server_operation_index.fetch(operation, server_index)
215
+ server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
216
+ else
217
+ server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') : server_url(server_index, server_variables, nil)
218
+ end
196
219
  end
197
220
 
198
221
  # Gets API key (with prefix if set).
@@ -207,6 +230,12 @@ module Svix
207
230
  end
208
231
  end
209
232
 
233
+ # Gets access_token using access_token_getter or uses the static access_token
234
+ def access_token_with_refresh
235
+ return access_token if access_token_getter.nil?
236
+ access_token_getter.call
237
+ end
238
+
210
239
  # Gets Basic Auth token string
211
240
  def basic_auth_token
212
241
  'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
@@ -219,9 +248,8 @@ module Svix
219
248
  {
220
249
  type: 'bearer',
221
250
  in: 'header',
222
- format: 'null',
223
251
  key: 'Authorization',
224
- value: "Bearer #{access_token}"
252
+ value: "Bearer #{access_token_with_refresh}"
225
253
  },
226
254
  }
227
255
  end
@@ -253,8 +281,8 @@ module Svix
253
281
  servers = server_settings if servers == nil
254
282
 
255
283
  # check array index out of bound
256
- if (index < 0 || index >= servers.size)
257
- fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
284
+ if (index.nil? || index < 0 || index >= servers.size)
285
+ fail ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
258
286
  end
259
287
 
260
288
  server = servers[index]
@@ -278,5 +306,7 @@ module Svix
278
306
 
279
307
  url
280
308
  end
309
+
310
+
281
311
  end
282
312
  end
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: 1.1.1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 5.2.0
9
+ Generator version: 7.9.0
10
10
 
11
11
  =end
12
12
 
@@ -21,6 +21,28 @@ module Svix
21
21
 
22
22
  attr_accessor :task
23
23
 
24
+ class EnumAttributeValidator
25
+ attr_reader :datatype
26
+ attr_reader :allowable_values
27
+
28
+ def initialize(datatype, allowable_values)
29
+ @allowable_values = allowable_values.map do |value|
30
+ case datatype.to_s
31
+ when /Integer/i
32
+ value.to_i
33
+ when /Float/i
34
+ value.to_f
35
+ else
36
+ value
37
+ end
38
+ end
39
+ end
40
+
41
+ def valid?(value)
42
+ !value || allowable_values.include?(value)
43
+ end
44
+ end
45
+
24
46
  # Attribute mapping from ruby-style variable name to JSON key.
25
47
  def self.attribute_map
26
48
  {
@@ -67,20 +89,27 @@ module Svix
67
89
 
68
90
  if attributes.key?(:'id')
69
91
  self.id = attributes[:'id']
92
+ else
93
+ self.id = nil
70
94
  end
71
95
 
72
96
  if attributes.key?(:'status')
73
97
  self.status = attributes[:'status']
98
+ else
99
+ self.status = nil
74
100
  end
75
101
 
76
102
  if attributes.key?(:'task')
77
103
  self.task = attributes[:'task']
104
+ else
105
+ self.task = nil
78
106
  end
79
107
  end
80
108
 
81
109
  # Show invalid properties with the reasons. Usually used together with valid?
82
110
  # @return Array for valid properties with the reasons
83
111
  def list_invalid_properties
112
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
84
113
  invalid_properties = Array.new
85
114
  if @id.nil?
86
115
  invalid_properties.push('invalid value for "id", id cannot be nil.')
@@ -100,6 +129,7 @@ module Svix
100
129
  # Check to see if the all the properties in the model are valid
101
130
  # @return true if the model is valid
102
131
  def valid?
132
+ warn '[DEPRECATED] the `valid?` method is obsolete'
103
133
  return false if @id.nil?
104
134
  return false if @status.nil?
105
135
  return false if @task.nil?
@@ -132,36 +162,30 @@ module Svix
132
162
  # @param [Hash] attributes Model attributes in the form of hash
133
163
  # @return [Object] Returns the model itself
134
164
  def self.build_from_hash(attributes)
135
- new.build_from_hash(attributes)
136
- end
137
-
138
- # Builds the object from hash
139
- # @param [Hash] attributes Model attributes in the form of hash
140
- # @return [Object] Returns the model itself
141
- def build_from_hash(attributes)
142
165
  return nil unless attributes.is_a?(Hash)
143
- self.class.openapi_types.each_pair do |key, type|
144
- if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
145
- self.send("#{key}=", nil)
166
+ attributes = attributes.transform_keys(&:to_sym)
167
+ transformed_hash = {}
168
+ openapi_types.each_pair do |key, type|
169
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
170
+ transformed_hash["#{key}"] = nil
146
171
  elsif type =~ /\AArray<(.*)>/i
147
172
  # check to ensure the input is an array given that the attribute
148
173
  # is documented as an array but the input is not
149
- if attributes[self.class.attribute_map[key]].is_a?(Array)
150
- self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
174
+ if attributes[attribute_map[key]].is_a?(Array)
175
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
151
176
  end
152
- elsif !attributes[self.class.attribute_map[key]].nil?
153
- self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
177
+ elsif !attributes[attribute_map[key]].nil?
178
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
154
179
  end
155
180
  end
156
-
157
- self
181
+ new(transformed_hash)
158
182
  end
159
183
 
160
184
  # Deserializes the data based on type
161
185
  # @param string type Data type
162
186
  # @param string value Value to be deserialized
163
187
  # @return [Object] Deserialized data
164
- def _deserialize(type, value)
188
+ def self._deserialize(type, value)
165
189
  case type.to_sym
166
190
  when :Time
167
191
  Time.parse(value)
@@ -196,7 +220,7 @@ module Svix
196
220
  else # model
197
221
  # models (e.g. Pet) or oneOf
198
222
  klass = Svix.const_get(type)
199
- klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
223
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
200
224
  end
201
225
  end
202
226
 
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: 1.1.1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 5.2.0
9
+ Generator version: 7.9.0
10
10
 
11
11
  =end
12
12
 
@@ -98,6 +98,7 @@ module Svix
98
98
  # Show invalid properties with the reasons. Usually used together with valid?
99
99
  # @return Array for valid properties with the reasons
100
100
  def list_invalid_properties
101
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
101
102
  invalid_properties = Array.new
102
103
  if !@expiry.nil? && @expiry > 604800
103
104
  invalid_properties.push('invalid value for "expiry", must be smaller than or equal to 604800.')
@@ -113,6 +114,7 @@ module Svix
113
114
  # Check to see if the all the properties in the model are valid
114
115
  # @return true if the model is valid
115
116
  def valid?
117
+ warn '[DEPRECATED] the `valid?` method is obsolete'
116
118
  return false if !@expiry.nil? && @expiry > 604800
117
119
  return false if !@expiry.nil? && @expiry < 3600
118
120
  true
@@ -135,6 +137,10 @@ module Svix
135
137
  # Custom attribute writer method with validation
136
138
  # @param [Object] feature_flags Value to be assigned
137
139
  def feature_flags=(feature_flags)
140
+ if feature_flags.nil?
141
+ fail ArgumentError, 'feature_flags cannot be nil'
142
+ end
143
+
138
144
  @feature_flags = feature_flags
139
145
  end
140
146
 
@@ -165,36 +171,30 @@ module Svix
165
171
  # @param [Hash] attributes Model attributes in the form of hash
166
172
  # @return [Object] Returns the model itself
167
173
  def self.build_from_hash(attributes)
168
- new.build_from_hash(attributes)
169
- end
170
-
171
- # Builds the object from hash
172
- # @param [Hash] attributes Model attributes in the form of hash
173
- # @return [Object] Returns the model itself
174
- def build_from_hash(attributes)
175
174
  return nil unless attributes.is_a?(Hash)
176
- self.class.openapi_types.each_pair do |key, type|
177
- if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
178
- self.send("#{key}=", nil)
175
+ attributes = attributes.transform_keys(&:to_sym)
176
+ transformed_hash = {}
177
+ openapi_types.each_pair do |key, type|
178
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
179
+ transformed_hash["#{key}"] = nil
179
180
  elsif type =~ /\AArray<(.*)>/i
180
181
  # check to ensure the input is an array given that the attribute
181
182
  # is documented as an array but the input is not
182
- if attributes[self.class.attribute_map[key]].is_a?(Array)
183
- self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
183
+ if attributes[attribute_map[key]].is_a?(Array)
184
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
184
185
  end
185
- elsif !attributes[self.class.attribute_map[key]].nil?
186
- self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
186
+ elsif !attributes[attribute_map[key]].nil?
187
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
187
188
  end
188
189
  end
189
-
190
- self
190
+ new(transformed_hash)
191
191
  end
192
192
 
193
193
  # Deserializes the data based on type
194
194
  # @param string type Data type
195
195
  # @param string value Value to be deserialized
196
196
  # @return [Object] Deserialized data
197
- def _deserialize(type, value)
197
+ def self._deserialize(type, value)
198
198
  case type.to_sym
199
199
  when :Time
200
200
  Time.parse(value)
@@ -229,7 +229,7 @@ module Svix
229
229
  else # model
230
230
  # models (e.g. Pet) or oneOf
231
231
  klass = Svix.const_get(type)
232
- klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
232
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
233
233
  end
234
234
  end
235
235
 
@@ -6,7 +6,7 @@
6
6
  The version of the OpenAPI document: 1.1.1
7
7
 
8
8
  Generated by: https://openapi-generator.tech
9
- OpenAPI Generator version: 5.2.0
9
+ Generator version: 7.9.0
10
10
 
11
11
  =end
12
12
 
@@ -63,16 +63,21 @@ module Svix
63
63
 
64
64
  if attributes.key?(:'token')
65
65
  self.token = attributes[:'token']
66
+ else
67
+ self.token = nil
66
68
  end
67
69
 
68
70
  if attributes.key?(:'url')
69
71
  self.url = attributes[:'url']
72
+ else
73
+ self.url = nil
70
74
  end
71
75
  end
72
76
 
73
77
  # Show invalid properties with the reasons. Usually used together with valid?
74
78
  # @return Array for valid properties with the reasons
75
79
  def list_invalid_properties
80
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
76
81
  invalid_properties = Array.new
77
82
  if @token.nil?
78
83
  invalid_properties.push('invalid value for "token", token cannot be nil.')
@@ -96,6 +101,7 @@ module Svix
96
101
  # Check to see if the all the properties in the model are valid
97
102
  # @return true if the model is valid
98
103
  def valid?
104
+ warn '[DEPRECATED] the `valid?` method is obsolete'
99
105
  return false if @token.nil?
100
106
  return false if @url.nil?
101
107
  return false if @url.to_s.length > 65536
@@ -146,36 +152,30 @@ module Svix
146
152
  # @param [Hash] attributes Model attributes in the form of hash
147
153
  # @return [Object] Returns the model itself
148
154
  def self.build_from_hash(attributes)
149
- new.build_from_hash(attributes)
150
- end
151
-
152
- # Builds the object from hash
153
- # @param [Hash] attributes Model attributes in the form of hash
154
- # @return [Object] Returns the model itself
155
- def build_from_hash(attributes)
156
155
  return nil unless attributes.is_a?(Hash)
157
- self.class.openapi_types.each_pair do |key, type|
158
- if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
159
- self.send("#{key}=", nil)
156
+ attributes = attributes.transform_keys(&:to_sym)
157
+ transformed_hash = {}
158
+ openapi_types.each_pair do |key, type|
159
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
160
+ transformed_hash["#{key}"] = nil
160
161
  elsif type =~ /\AArray<(.*)>/i
161
162
  # check to ensure the input is an array given that the attribute
162
163
  # is documented as an array but the input is not
163
- if attributes[self.class.attribute_map[key]].is_a?(Array)
164
- self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
164
+ if attributes[attribute_map[key]].is_a?(Array)
165
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
165
166
  end
166
- elsif !attributes[self.class.attribute_map[key]].nil?
167
- self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
167
+ elsif !attributes[attribute_map[key]].nil?
168
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
168
169
  end
169
170
  end
170
-
171
- self
171
+ new(transformed_hash)
172
172
  end
173
173
 
174
174
  # Deserializes the data based on type
175
175
  # @param string type Data type
176
176
  # @param string value Value to be deserialized
177
177
  # @return [Object] Deserialized data
178
- def _deserialize(type, value)
178
+ def self._deserialize(type, value)
179
179
  case type.to_sym
180
180
  when :Time
181
181
  Time.parse(value)
@@ -210,7 +210,7 @@ module Svix
210
210
  else # model
211
211
  # models (e.g. Pet) or oneOf
212
212
  klass = Svix.const_get(type)
213
- klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
213
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
214
214
  end
215
215
  end
216
216