=begin
#Svix API
#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 user on your platform. - `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}`. ## 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/). ## Idempotency Svix supports [idempotency](https://en.wikipedia.org/wiki/Idempotence) for safely retrying requests without accidentally performing the same operation twice. This is useful when an API call is disrupted in transit and you do not receive a response. To perform an idempotent request, pass the idempotency key in the `Idempotency-Key` header to the request. The idempotency key should be a unique value generated by the client. You can create the key in however way you like, though we suggest using UUID v4, or any other string with enough entropy to avoid collisions. Svix's idempotency works by saving the resulting status code and body of the first request made for any given idempotency key for any successful request. Subsequent requests with the same key return the same result. Please note that idempotency is only supported for `POST` requests. ## 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.
The version of the OpenAPI document: 1.4
Generated by: https://openapi-generator.tech
OpenAPI Generator version: 5.2.0
=end
require 'cgi'
module Svix
class MessageApi
attr_accessor :api_client
def initialize(api_client = ApiClient.default)
@api_client = api_client
end
# Create Message
# Creates a new message and dispatches it to all of the application's endpoints. The `eventId` is an optional custom unique ID. It's verified to be unique only up to a day, after that no verification will be made. If a message with the same `eventId` already exists for any application in your environment, a 409 conflict error will be returned. The `eventType` indicates the type and schema of the event. All messages of a certain `eventType` are expected to have the same schema. Endpoints can choose to only listen to specific event types. Messages can also have `channels`, which similar to event types let endpoints filter by them. Unlike event types, messages can have multiple channels, and channels don't imply a specific message content or schema.
# @param app_id [String]
# @param message_in [MessageIn]
# @param [Hash] opts the optional parameters
# @option opts [Boolean] :with_content (default to true)
# @option opts [String] :idempotency_key The request's idempotency key
# @return [MessageOut]
def create_message_api_v1_app_app_id_msg_post(app_id, message_in, opts = {})
data, _status_code, _headers = create_message_api_v1_app_app_id_msg_post_with_http_info(app_id, message_in, opts)
data
end
# Create Message
# Creates a new message and dispatches it to all of the application's endpoints. The `eventId` is an optional custom unique ID. It's verified to be unique only up to a day, after that no verification will be made. If a message with the same `eventId` already exists for any application in your environment, a 409 conflict error will be returned. The `eventType` indicates the type and schema of the event. All messages of a certain `eventType` are expected to have the same schema. Endpoints can choose to only listen to specific event types. Messages can also have `channels`, which similar to event types let endpoints filter by them. Unlike event types, messages can have multiple channels, and channels don't imply a specific message content or schema.
# @param app_id [String]
# @param message_in [MessageIn]
# @param [Hash] opts the optional parameters
# @option opts [Boolean] :with_content
# @option opts [String] :idempotency_key The request's idempotency key
# @return [Array<(MessageOut, Integer, Hash)>] MessageOut data, response status code and response headers
def create_message_api_v1_app_app_id_msg_post_with_http_info(app_id, message_in, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: MessageApi.create_message_api_v1_app_app_id_msg_post ...'
end
# verify the required parameter 'app_id' is set
if @api_client.config.client_side_validation && app_id.nil?
fail ArgumentError, "Missing the required parameter 'app_id' when calling MessageApi.create_message_api_v1_app_app_id_msg_post"
end
if @api_client.config.client_side_validation && app_id.to_s.length > 256
fail ArgumentError, 'invalid value for "app_id" when calling MessageApi.create_message_api_v1_app_app_id_msg_post, the character length must be smaller than or equal to 256.'
end
if @api_client.config.client_side_validation && app_id.to_s.length < 1
fail ArgumentError, 'invalid value for "app_id" when calling MessageApi.create_message_api_v1_app_app_id_msg_post, the character length must be great than or equal to 1.'
end
pattern = Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
if @api_client.config.client_side_validation && app_id !~ pattern
fail ArgumentError, "invalid value for 'app_id' when calling MessageApi.create_message_api_v1_app_app_id_msg_post, must conform to the pattern #{pattern}."
end
# verify the required parameter 'message_in' is set
if @api_client.config.client_side_validation && message_in.nil?
fail ArgumentError, "Missing the required parameter 'message_in' when calling MessageApi.create_message_api_v1_app_app_id_msg_post"
end
# resource path
local_var_path = '/api/v1/app/{app_id}/msg/'.sub('{' + 'app_id' + '}', CGI.escape(app_id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'with_content'] = opts[:'with_content'] if !opts[:'with_content'].nil?
# header parameters
header_params = opts[:header_params] || {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
# HTTP header 'Content-Type'
header_params['Content-Type'] = @api_client.select_header_content_type(['application/json'])
header_params[:'idempotency-key'] = opts[:'idempotency_key'] if !opts[:'idempotency_key'].nil?
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body] || @api_client.object_to_http_body(message_in)
# return_type
return_type = opts[:debug_return_type] || 'MessageOut'
# auth_names
auth_names = opts[:debug_auth_names] || ['HTTPBearer']
new_options = opts.merge(
:operation => :"MessageApi.create_message_api_v1_app_app_id_msg_post",
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => return_type
)
data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: MessageApi#create_message_api_v1_app_app_id_msg_post\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# Get Message
# Get a message by its ID or eventID.
# @param msg_id [String]
# @param app_id [String]
# @param [Hash] opts the optional parameters
# @option opts [String] :idempotency_key The request's idempotency key
# @return [MessageOut]
def get_message_api_v1_app_app_id_msg_msg_id_get(msg_id, app_id, opts = {})
data, _status_code, _headers = get_message_api_v1_app_app_id_msg_msg_id_get_with_http_info(msg_id, app_id, opts)
data
end
# Get Message
# Get a message by its ID or eventID.
# @param msg_id [String]
# @param app_id [String]
# @param [Hash] opts the optional parameters
# @option opts [String] :idempotency_key The request's idempotency key
# @return [Array<(MessageOut, Integer, Hash)>] MessageOut data, response status code and response headers
def get_message_api_v1_app_app_id_msg_msg_id_get_with_http_info(msg_id, app_id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: MessageApi.get_message_api_v1_app_app_id_msg_msg_id_get ...'
end
# verify the required parameter 'msg_id' is set
if @api_client.config.client_side_validation && msg_id.nil?
fail ArgumentError, "Missing the required parameter 'msg_id' when calling MessageApi.get_message_api_v1_app_app_id_msg_msg_id_get"
end
if @api_client.config.client_side_validation && msg_id.to_s.length > 256
fail ArgumentError, 'invalid value for "msg_id" when calling MessageApi.get_message_api_v1_app_app_id_msg_msg_id_get, the character length must be smaller than or equal to 256.'
end
if @api_client.config.client_side_validation && msg_id.to_s.length < 1
fail ArgumentError, 'invalid value for "msg_id" when calling MessageApi.get_message_api_v1_app_app_id_msg_msg_id_get, the character length must be great than or equal to 1.'
end
pattern = Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
if @api_client.config.client_side_validation && msg_id !~ pattern
fail ArgumentError, "invalid value for 'msg_id' when calling MessageApi.get_message_api_v1_app_app_id_msg_msg_id_get, must conform to the pattern #{pattern}."
end
# verify the required parameter 'app_id' is set
if @api_client.config.client_side_validation && app_id.nil?
fail ArgumentError, "Missing the required parameter 'app_id' when calling MessageApi.get_message_api_v1_app_app_id_msg_msg_id_get"
end
if @api_client.config.client_side_validation && app_id.to_s.length > 256
fail ArgumentError, 'invalid value for "app_id" when calling MessageApi.get_message_api_v1_app_app_id_msg_msg_id_get, the character length must be smaller than or equal to 256.'
end
if @api_client.config.client_side_validation && app_id.to_s.length < 1
fail ArgumentError, 'invalid value for "app_id" when calling MessageApi.get_message_api_v1_app_app_id_msg_msg_id_get, the character length must be great than or equal to 1.'
end
pattern = Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
if @api_client.config.client_side_validation && app_id !~ pattern
fail ArgumentError, "invalid value for 'app_id' when calling MessageApi.get_message_api_v1_app_app_id_msg_msg_id_get, must conform to the pattern #{pattern}."
end
# resource path
local_var_path = '/api/v1/app/{app_id}/msg/{msg_id}/'.sub('{' + 'msg_id' + '}', CGI.escape(msg_id.to_s)).sub('{' + 'app_id' + '}', CGI.escape(app_id.to_s))
# query parameters
query_params = opts[:query_params] || {}
# header parameters
header_params = opts[:header_params] || {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
header_params[:'idempotency-key'] = opts[:'idempotency_key'] if !opts[:'idempotency_key'].nil?
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type] || 'MessageOut'
# auth_names
auth_names = opts[:debug_auth_names] || ['HTTPBearer']
new_options = opts.merge(
:operation => :"MessageApi.get_message_api_v1_app_app_id_msg_msg_id_get",
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => return_type
)
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: MessageApi#get_message_api_v1_app_app_id_msg_msg_id_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
# List Messages
# List all of the application's messages. The `before` parameter lets you filter all items created before a certain date and is ignored if an iterator is passed. The `after` parameter lets you filter all items created after a certain date and is ignored if an iterator is passed. `before` and `after` cannot be used simultaneously.
# @param app_id [String]
# @param [Hash] opts the optional parameters
# @option opts [String] :iterator
# @option opts [Integer] :limit (default to 50)
# @option opts [Array] :event_types
# @option opts [String] :channel
# @option opts [Time] :before
# @option opts [Time] :after
# @option opts [String] :idempotency_key The request's idempotency key
# @return [ListResponseMessageOut]
def list_messages_api_v1_app_app_id_msg_get(app_id, opts = {})
data, _status_code, _headers = list_messages_api_v1_app_app_id_msg_get_with_http_info(app_id, opts)
data
end
# List Messages
# List all of the application's messages. The `before` parameter lets you filter all items created before a certain date and is ignored if an iterator is passed. The `after` parameter lets you filter all items created after a certain date and is ignored if an iterator is passed. `before` and `after` cannot be used simultaneously.
# @param app_id [String]
# @param [Hash] opts the optional parameters
# @option opts [String] :iterator
# @option opts [Integer] :limit
# @option opts [Array] :event_types
# @option opts [String] :channel
# @option opts [Time] :before
# @option opts [Time] :after
# @option opts [String] :idempotency_key The request's idempotency key
# @return [Array<(ListResponseMessageOut, Integer, Hash)>] ListResponseMessageOut data, response status code and response headers
def list_messages_api_v1_app_app_id_msg_get_with_http_info(app_id, opts = {})
if @api_client.config.debugging
@api_client.config.logger.debug 'Calling API: MessageApi.list_messages_api_v1_app_app_id_msg_get ...'
end
# verify the required parameter 'app_id' is set
if @api_client.config.client_side_validation && app_id.nil?
fail ArgumentError, "Missing the required parameter 'app_id' when calling MessageApi.list_messages_api_v1_app_app_id_msg_get"
end
if @api_client.config.client_side_validation && app_id.to_s.length > 256
fail ArgumentError, 'invalid value for "app_id" when calling MessageApi.list_messages_api_v1_app_app_id_msg_get, the character length must be smaller than or equal to 256.'
end
if @api_client.config.client_side_validation && app_id.to_s.length < 1
fail ArgumentError, 'invalid value for "app_id" when calling MessageApi.list_messages_api_v1_app_app_id_msg_get, the character length must be great than or equal to 1.'
end
pattern = Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
if @api_client.config.client_side_validation && app_id !~ pattern
fail ArgumentError, "invalid value for 'app_id' when calling MessageApi.list_messages_api_v1_app_app_id_msg_get, must conform to the pattern #{pattern}."
end
if @api_client.config.client_side_validation && !opts[:'limit'].nil? && opts[:'limit'] > 250
fail ArgumentError, 'invalid value for "opts[:"limit"]" when calling MessageApi.list_messages_api_v1_app_app_id_msg_get, must be smaller than or equal to 250.'
end
if @api_client.config.client_side_validation && !opts[:'channel'].nil? && opts[:'channel'].to_s.length > 128
fail ArgumentError, 'invalid value for "opts[:"channel"]" when calling MessageApi.list_messages_api_v1_app_app_id_msg_get, the character length must be smaller than or equal to 128.'
end
pattern = Regexp.new(/^[a-zA-Z0-9\-_.]+$/)
if @api_client.config.client_side_validation && !opts[:'channel'].nil? && opts[:'channel'] !~ pattern
fail ArgumentError, "invalid value for 'opts[:\"channel\"]' when calling MessageApi.list_messages_api_v1_app_app_id_msg_get, must conform to the pattern #{pattern}."
end
# resource path
local_var_path = '/api/v1/app/{app_id}/msg/'.sub('{' + 'app_id' + '}', CGI.escape(app_id.to_s))
# query parameters
query_params = opts[:query_params] || {}
query_params[:'iterator'] = opts[:'iterator'] if !opts[:'iterator'].nil?
query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
query_params[:'event_types'] = @api_client.build_collection_param(opts[:'event_types'], :multi) if !opts[:'event_types'].nil?
query_params[:'channel'] = opts[:'channel'] if !opts[:'channel'].nil?
query_params[:'before'] = opts[:'before'] if !opts[:'before'].nil?
query_params[:'after'] = opts[:'after'] if !opts[:'after'].nil?
# header parameters
header_params = opts[:header_params] || {}
# HTTP header 'Accept' (if needed)
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
header_params[:'idempotency-key'] = opts[:'idempotency_key'] if !opts[:'idempotency_key'].nil?
# form parameters
form_params = opts[:form_params] || {}
# http body (model)
post_body = opts[:debug_body]
# return_type
return_type = opts[:debug_return_type] || 'ListResponseMessageOut'
# auth_names
auth_names = opts[:debug_auth_names] || ['HTTPBearer']
new_options = opts.merge(
:operation => :"MessageApi.list_messages_api_v1_app_app_id_msg_get",
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
:body => post_body,
:auth_names => auth_names,
:return_type => return_type
)
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
if @api_client.config.debugging
@api_client.config.logger.debug "API called: MessageApi#list_messages_api_v1_app_app_id_msg_get\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return data, status_code, headers
end
end
end