=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.1 Generated by: https://openapi-generator.tech OpenAPI Generator version: 5.2.0 =end require 'cgi' module Svix class StatisticsApi attr_accessor :api_client def initialize(api_client = ApiClient.default) @api_client = api_client end # Calculate Aggregate App Stats # Creates a background task to calculate the message destinations for all applications in the environment. # @param app_usage_stats_in [AppUsageStatsIn] # @param [Hash] opts the optional parameters # @option opts [String] :idempotency_key The request's idempotency key # @return [AppUsageStatsOut] def calculate_aggregate_app_stats(app_usage_stats_in, opts = {}) data, _status_code, _headers = calculate_aggregate_app_stats_with_http_info(app_usage_stats_in, opts) data end # Calculate Aggregate App Stats # Creates a background task to calculate the message destinations for all applications in the environment. # @param app_usage_stats_in [AppUsageStatsIn] # @param [Hash] opts the optional parameters # @option opts [String] :idempotency_key The request's idempotency key # @return [Array<(AppUsageStatsOut, Integer, Hash)>] AppUsageStatsOut data, response status code and response headers def calculate_aggregate_app_stats_with_http_info(app_usage_stats_in, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: StatisticsApi.calculate_aggregate_app_stats ...' end # verify the required parameter 'app_usage_stats_in' is set if @api_client.config.client_side_validation && app_usage_stats_in.nil? fail ArgumentError, "Missing the required parameter 'app_usage_stats_in' when calling StatisticsApi.calculate_aggregate_app_stats" end # resource path local_var_path = '/api/v1/stats/usage/app/' # 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']) # 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(app_usage_stats_in) # return_type return_type = opts[:debug_return_type] || 'AppUsageStatsOut' # auth_names auth_names = opts[:debug_auth_names] || ['HTTPBearer'] new_options = opts.merge( :operation => :"StatisticsApi.calculate_aggregate_app_stats", :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: StatisticsApi#calculate_aggregate_app_stats\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get App Attempt Stats # Returns application-level statistics on message attempts # @param app_id [String] The app's ID or UID # @param [Hash] opts the optional parameters # @option opts [Time] :start_date # @option opts [Time] :end_date # @return [AttemptStatisticsResponse] def v1_stats_app_attempts(app_id, opts = {}) data, _status_code, _headers = v1_stats_app_attempts_with_http_info(app_id, opts) data end # Get App Attempt Stats # Returns application-level statistics on message attempts # @param app_id [String] The app's ID or UID # @param [Hash] opts the optional parameters # @option opts [Time] :start_date # @option opts [Time] :end_date # @return [Array<(AttemptStatisticsResponse, Integer, Hash)>] AttemptStatisticsResponse data, response status code and response headers def v1_stats_app_attempts_with_http_info(app_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: StatisticsApi.v1_stats_app_attempts ...' 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 StatisticsApi.v1_stats_app_attempts" end if @api_client.config.client_side_validation && app_id.to_s.length > 256 fail ArgumentError, 'invalid value for "app_id" when calling StatisticsApi.v1_stats_app_attempts, 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 StatisticsApi.v1_stats_app_attempts, 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 StatisticsApi.v1_stats_app_attempts, must conform to the pattern #{pattern}." end # resource path local_var_path = '/api/v1/stats/app/{app_id}/attempt/'.sub('{' + 'app_id' + '}', CGI.escape(app_id.to_s)) # query parameters query_params = opts[:query_params] || {} query_params[:'startDate'] = opts[:'start_date'] if !opts[:'start_date'].nil? query_params[:'endDate'] = opts[:'end_date'] if !opts[:'end_date'].nil? # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'AttemptStatisticsResponse' # auth_names auth_names = opts[:debug_auth_names] || ['HTTPBearer'] new_options = opts.merge( :operation => :"StatisticsApi.v1_stats_app_attempts", :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: StatisticsApi#v1_stats_app_attempts\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end # Get Ep Stats # Returns endpoint-level statistics on message attempts # @param app_id [String] The app's ID or UID # @param endpoint_id [String] The ep's ID or UID # @param [Hash] opts the optional parameters # @option opts [Time] :start_date # @option opts [Time] :end_date # @return [AttemptStatisticsResponse] def v1_stats_endpoint_attempts(app_id, endpoint_id, opts = {}) data, _status_code, _headers = v1_stats_endpoint_attempts_with_http_info(app_id, endpoint_id, opts) data end # Get Ep Stats # Returns endpoint-level statistics on message attempts # @param app_id [String] The app's ID or UID # @param endpoint_id [String] The ep's ID or UID # @param [Hash] opts the optional parameters # @option opts [Time] :start_date # @option opts [Time] :end_date # @return [Array<(AttemptStatisticsResponse, Integer, Hash)>] AttemptStatisticsResponse data, response status code and response headers def v1_stats_endpoint_attempts_with_http_info(app_id, endpoint_id, opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: StatisticsApi.v1_stats_endpoint_attempts ...' 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 StatisticsApi.v1_stats_endpoint_attempts" end if @api_client.config.client_side_validation && app_id.to_s.length > 256 fail ArgumentError, 'invalid value for "app_id" when calling StatisticsApi.v1_stats_endpoint_attempts, 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 StatisticsApi.v1_stats_endpoint_attempts, 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 StatisticsApi.v1_stats_endpoint_attempts, must conform to the pattern #{pattern}." end # verify the required parameter 'endpoint_id' is set if @api_client.config.client_side_validation && endpoint_id.nil? fail ArgumentError, "Missing the required parameter 'endpoint_id' when calling StatisticsApi.v1_stats_endpoint_attempts" end if @api_client.config.client_side_validation && endpoint_id.to_s.length > 256 fail ArgumentError, 'invalid value for "endpoint_id" when calling StatisticsApi.v1_stats_endpoint_attempts, the character length must be smaller than or equal to 256.' end if @api_client.config.client_side_validation && endpoint_id.to_s.length < 1 fail ArgumentError, 'invalid value for "endpoint_id" when calling StatisticsApi.v1_stats_endpoint_attempts, 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 && endpoint_id !~ pattern fail ArgumentError, "invalid value for 'endpoint_id' when calling StatisticsApi.v1_stats_endpoint_attempts, must conform to the pattern #{pattern}." end # resource path local_var_path = '/api/v1/stats/app/{app_id}/ep/{endpoint_id}/attempt/'.sub('{' + 'app_id' + '}', CGI.escape(app_id.to_s)).sub('{' + 'endpoint_id' + '}', CGI.escape(endpoint_id.to_s)) # query parameters query_params = opts[:query_params] || {} query_params[:'startDate'] = opts[:'start_date'] if !opts[:'start_date'].nil? query_params[:'endDate'] = opts[:'end_date'] if !opts[:'end_date'].nil? # header parameters header_params = opts[:header_params] || {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) # form parameters form_params = opts[:form_params] || {} # http body (model) post_body = opts[:debug_body] # return_type return_type = opts[:debug_return_type] || 'AttemptStatisticsResponse' # auth_names auth_names = opts[:debug_auth_names] || ['HTTPBearer'] new_options = opts.merge( :operation => :"StatisticsApi.v1_stats_endpoint_attempts", :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: StatisticsApi#v1_stats_endpoint_attempts\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end end end