trustcomponent 0.0.1.beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.md +21 -0
  3. data/README.md +78 -0
  4. data/lib/trustcomponent/captcha.rb +24 -0
  5. data/lib/trustcomponent/client.rb +44 -0
  6. data/lib/trustcomponent/errors.rb +58 -0
  7. data/lib/trustcomponent/http_middleware.rb +83 -0
  8. data/lib/trustcomponent.rb +15 -0
  9. data/lib/trustcomponent_generated/api/analytics_server_events_api.rb +90 -0
  10. data/lib/trustcomponent_generated/api/analytics_websites_api.rb +527 -0
  11. data/lib/trustcomponent_generated/api/captcha_verifications_api.rb +88 -0
  12. data/lib/trustcomponent_generated/api/monitoring_heartbeats_api.rb +89 -0
  13. data/lib/trustcomponent_generated/api/platform_events_api.rb +106 -0
  14. data/lib/trustcomponent_generated/api/tax_validation_schedules_api.rb +147 -0
  15. data/lib/trustcomponent_generated/api/tax_validation_validation_results_api.rb +83 -0
  16. data/lib/trustcomponent_generated/api/tax_validation_validations_api.rb +156 -0
  17. data/lib/trustcomponent_generated/api_client.rb +441 -0
  18. data/lib/trustcomponent_generated/api_error.rb +58 -0
  19. data/lib/trustcomponent_generated/api_model_base.rb +88 -0
  20. data/lib/trustcomponent_generated/configuration.rb +400 -0
  21. data/lib/trustcomponent_generated/models/analytics_event_category_enum.rb +52 -0
  22. data/lib/trustcomponent_generated/models/analytics_realtime.rb +251 -0
  23. data/lib/trustcomponent_generated/models/analytics_realtime_page.rb +193 -0
  24. data/lib/trustcomponent_generated/models/analytics_realtime_point.rb +193 -0
  25. data/lib/trustcomponent_generated/models/analytics_server_event_batch_create_params.rb +295 -0
  26. data/lib/trustcomponent_generated/models/analytics_server_event_batch_event_commerce_create_params.rb +366 -0
  27. data/lib/trustcomponent_generated/models/analytics_server_event_batch_event_commerce_product_create_params.rb +298 -0
  28. data/lib/trustcomponent_generated/models/analytics_server_event_batch_event_create_params.rb +508 -0
  29. data/lib/trustcomponent_generated/models/analytics_server_event_batch_event_error_create_params.rb +269 -0
  30. data/lib/trustcomponent_generated/models/analytics_server_event_batch_event_refund_create_params.rb +211 -0
  31. data/lib/trustcomponent_generated/models/analytics_server_event_batch_result.rb +194 -0
  32. data/lib/trustcomponent_generated/models/analytics_server_event_batch_result_drop_reason_enum.rb +52 -0
  33. data/lib/trustcomponent_generated/models/analytics_server_event_batch_result_dropped.rb +213 -0
  34. data/lib/trustcomponent_generated/models/analytics_stats_breakdown.rb +351 -0
  35. data/lib/trustcomponent_generated/models/analytics_stats_breakdown_row.rb +201 -0
  36. data/lib/trustcomponent_generated/models/analytics_stats_breakdown_row_page.rb +226 -0
  37. data/lib/trustcomponent_generated/models/analytics_stats_conversions.rb +249 -0
  38. data/lib/trustcomponent_generated/models/analytics_stats_conversions_goal.rb +260 -0
  39. data/lib/trustcomponent_generated/models/analytics_stats_conversions_goal_revenue.rb +193 -0
  40. data/lib/trustcomponent_generated/models/analytics_stats_dimension_enum.rb +69 -0
  41. data/lib/trustcomponent_generated/models/analytics_stats_filter_match_mode_enum.rb +40 -0
  42. data/lib/trustcomponent_generated/models/analytics_stats_filter_operator_enum.rb +45 -0
  43. data/lib/trustcomponent_generated/models/analytics_stats_granularity_enum.rb +40 -0
  44. data/lib/trustcomponent_generated/models/analytics_stats_overview.rb +282 -0
  45. data/lib/trustcomponent_generated/models/analytics_stats_timeseries.rb +270 -0
  46. data/lib/trustcomponent_generated/models/analytics_stats_timeseries_point.rb +192 -0
  47. data/lib/trustcomponent_generated/models/analytics_stats_totals.rb +307 -0
  48. data/lib/trustcomponent_generated/models/analytics_website.rb +249 -0
  49. data/lib/trustcomponent_generated/models/analytics_websites_page.rb +249 -0
  50. data/lib/trustcomponent_generated/models/captcha_verification_result.rb +350 -0
  51. data/lib/trustcomponent_generated/models/platform_event.rb +439 -0
  52. data/lib/trustcomponent_generated/models/platform_event_actor.rb +218 -0
  53. data/lib/trustcomponent_generated/models/platform_event_actor_automation.rb +214 -0
  54. data/lib/trustcomponent_generated/models/platform_event_actor_automation_kind_enum.rb +41 -0
  55. data/lib/trustcomponent_generated/models/platform_event_actor_type_enum.rb +43 -0
  56. data/lib/trustcomponent_generated/models/platform_event_change.rb +263 -0
  57. data/lib/trustcomponent_generated/models/platform_event_change_operation_enum.rb +43 -0
  58. data/lib/trustcomponent_generated/models/platform_event_origin.rb +263 -0
  59. data/lib/trustcomponent_generated/models/platform_event_ref.rb +204 -0
  60. data/lib/trustcomponent_generated/models/platform_event_source_enum.rb +44 -0
  61. data/lib/trustcomponent_generated/models/platform_events_page.rb +314 -0
  62. data/lib/trustcomponent_generated/models/tax_validation_match_status_enum.rb +44 -0
  63. data/lib/trustcomponent_generated/models/tax_validation_provider_enum.rb +46 -0
  64. data/lib/trustcomponent_generated/models/tax_validation_provider_status_enum.rb +51 -0
  65. data/lib/trustcomponent_generated/models/tax_validation_schedule.rb +423 -0
  66. data/lib/trustcomponent_generated/models/tax_validation_schedule_create_params.rb +321 -0
  67. data/lib/trustcomponent_generated/models/tax_validation_tax_address.rb +188 -0
  68. data/lib/trustcomponent_generated/models/tax_validation_tax_identifier_scheme_enum.rb +49 -0
  69. data/lib/trustcomponent_generated/models/tax_validation_validation.rb +372 -0
  70. data/lib/trustcomponent_generated/models/tax_validation_validation_address_match.rb +290 -0
  71. data/lib/trustcomponent_generated/models/tax_validation_validation_batch_create_params.rb +176 -0
  72. data/lib/trustcomponent_generated/models/tax_validation_validation_create_params.rb +292 -0
  73. data/lib/trustcomponent_generated/models/tax_validation_validation_frequency_enum.rb +41 -0
  74. data/lib/trustcomponent_generated/models/tax_validation_validation_input.rb +322 -0
  75. data/lib/trustcomponent_generated/models/tax_validation_validation_match.rb +238 -0
  76. data/lib/trustcomponent_generated/models/tax_validation_validation_mode_enum.rb +40 -0
  77. data/lib/trustcomponent_generated/models/tax_validation_validation_outcome_enum.rb +44 -0
  78. data/lib/trustcomponent_generated/models/tax_validation_validation_request_status_enum.rb +44 -0
  79. data/lib/trustcomponent_generated/models/tax_validation_validation_response_data.rb +177 -0
  80. data/lib/trustcomponent_generated/models/tax_validation_validation_result.rb +459 -0
  81. data/lib/trustcomponent_generated/models/tax_validation_validation_schedule_attach_params.rb +225 -0
  82. data/lib/trustcomponent_generated/models/tax_validation_verification_method_enum.rb +40 -0
  83. data/lib/trustcomponent_generated/modules.rb +51 -0
  84. data/lib/trustcomponent_generated/version.rb +15 -0
  85. data/lib/trustcomponent_generated.rb +110 -0
  86. metadata +190 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c147f81069d528ab90f76cba120ff190eafdabde12b08ff05b265a81909769af
4
+ data.tar.gz: a0e5371107f02280aefee3385a5eee9284ee3b65d46a05138dabaeb33798845b
5
+ SHA512:
6
+ metadata.gz: 3d89f853d3bbf42f786eeaef44593bfd5862b9bd754676ebef23bbc54a0d900d4f8e51ef0e82783e519d5a4d6c45acb19e18bde5d4a5d7922fc7c70e653eab1d
7
+ data.tar.gz: f8a4a52e0b989a7307784df23752a2017ffbd41524f900a233b4932153498bde5a872e97fab6d8499f7243af47e7bf30c21576602c3e140a1cc9bd13a053fe2b
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Trustcaptcha GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # TrustComponent SDK for Ruby
2
+
3
+ The official SDK for the TrustComponent API: TrustCaptcha, TrustAnalytics, TrustMonitoring, Trust VAT Checker and the
4
+ platform API, in one package. Developed and hosted in the EU.
5
+
6
+ Requires Ruby 2.7 or newer (Faraday 1 or 2).
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ gem install trustcomponent
12
+ ```
13
+
14
+ ## Check a TrustCaptcha result
15
+
16
+ The widget writes a verification token into your form. One call turns it into the result:
17
+
18
+ ```ruby
19
+ require 'trustcomponent'
20
+
21
+ tc = TrustComponent::Client.new('ak_…')
22
+ result = tc.captcha.get_verification_result(params['tc-verification-token'])
23
+ if result.verification_passed
24
+ # …
25
+ end
26
+ ```
27
+
28
+ Create the API key (`ak_…`) in the dashboard under the project's API keys. The key decides which modules the client can use.
29
+
30
+ ## Every module
31
+
32
+ The client is `module → resource → operation`, with the same names in every language:
33
+
34
+ ```ruby
35
+ tc.analytics.websites.get_websites
36
+ tc.tax_validation.validations.create_validation(TrustComponent::Generated::TaxValidationValidationCreateParams.new(country_code: 'DE', raw_value: 'DE811569869'))
37
+ tc.monitoring.heartbeats.ping_heartbeat(service_id, monitor_id)
38
+ tc.platform.events.get_events
39
+ ```
40
+
41
+ The full reference of every operation is at https://docs.trustcomponent.com.
42
+
43
+ ## Configuration
44
+
45
+ ```ruby
46
+ tc = TrustComponent::Client.new('ak_…', timeout: 5, max_retries: 1, integration: 'my-plugin/1.0')
47
+ ```
48
+
49
+ Options: `host`, `timeout`, `proxy`, `max_retries`, `deprecation_warnings`, `integration`, `logger`, `faraday_adapter`.
50
+
51
+ The SDK retries only what the API reserves for retries: `429` with `Retry-After`, `502`, `503`, `504` and a lost
52
+ connection (2 retries by default). When the API marks an operation as deprecated, it logs one warning per operation.
53
+ Every request names the SDK in `User-Agent` and `TrustComponent-Sdk`, together with the integration you set.
54
+
55
+ ## Errors
56
+
57
+ Every error is a `TrustComponent::Error` carrying the HTTP status and the stable `code` of the API:
58
+ `InvalidRequestError`, `AuthenticationError`, `PermissionError`, `PlanLimitError`, `NotFoundError`, `ConflictError`, `GoneError`, `RateLimitError`, `ServerError`, `ConnectionError`, `OperationRetiredError`, `VerificationTokenInvalidError`.
59
+
60
+ ```ruby
61
+ begin
62
+ tc.captcha.get_verification_result(token)
63
+ rescue TrustComponent::NotFoundError => e
64
+ # e.status, e.code
65
+ end
66
+ ```
67
+
68
+ `OperationRetired` means the operation was switched off after its sunset: update the SDK.
69
+
70
+ ## Support
71
+
72
+ The GitHub repository of this SDK is a read-only mirror, generated from the TrustComponent API, so pull requests and
73
+ issues are not processed there. For questions and bug reports, write to mail@trustcomponent.com or contact support
74
+ through https://www.trustcomponent.com.
75
+
76
+ ## License
77
+
78
+ MIT
@@ -0,0 +1,24 @@
1
+ require 'base64'
2
+ require 'json'
3
+
4
+ module TrustComponent
5
+ VerificationToken = Struct.new(:verification_id, :client_failover)
6
+
7
+ class CaptchaModule < Generated::CaptchaModuleBase
8
+ # Returns the result of the verification behind a widget token, the one call a form handler needs.
9
+ # When the widget could not reach TrustCaptcha (+clientFailover+ in the token), the public gateway decides whether the visitor may pass.
10
+ def get_verification_result(verification_token)
11
+ token = self.class.parse_verification_token(verification_token)
12
+ verifications.get_result(token.verification_id, token.client_failover ? { client_failover: true } : {})
13
+ end
14
+
15
+ def self.parse_verification_token(verification_token)
16
+ token = JSON.parse(Base64.strict_decode64(verification_token.to_s.strip))
17
+ raise ArgumentError unless token.is_a?(Hash) && token['verificationId'].is_a?(String) && !token['verificationId'].empty?
18
+
19
+ VerificationToken.new(token['verificationId'], token['clientFailover'] == true)
20
+ rescue ArgumentError, JSON::ParserError
21
+ raise VerificationTokenInvalidError.new('The verification token is not a TrustCaptcha token', code: 'verification_token_invalid')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'base64'
2
+ require 'json'
3
+ require 'logger'
4
+ require 'uri'
5
+
6
+ module TrustComponent
7
+ # Entry point of the SDK. <tt>TrustComponent::Client.new('ak_…')</tt> is all most integrations need; keyword
8
+ # arguments change host, timeout, proxy, retries and the rest.
9
+ class Client
10
+ attr_reader :captcha, :analytics, :monitoring, :tax_validation, :platform
11
+
12
+ def initialize(api_key, host: 'https://api.trustcomponent.com', timeout: 10, proxy: nil, max_retries: 2, deprecation_warnings: true,
13
+ integration: nil, logger: ->(message) { Logger.new($stderr).warn(message) }, faraday_adapter: nil)
14
+ raise ArgumentError, 'api_key must not be empty' if api_key.nil? || api_key.strip.empty?
15
+
16
+ uri = URI.parse(host.sub(%r{/+\z}, ''))
17
+ config = Generated::Configuration.new
18
+ config.scheme = uri.scheme
19
+ config.host = uri.port == uri.default_port ? uri.host : "#{uri.host}:#{uri.port}"
20
+ config.base_path = uri.path
21
+ config.ignore_operation_servers = true
22
+ config.timeout = timeout
23
+ config.proxy = proxy if proxy
24
+ config.use(HttpMiddleware, api_key: api_key.strip, user_agent: "trustcomponent-ruby/#{VERSION}", sdk_header: sdk_header(integration),
25
+ max_retries: [max_retries, 0].max, deprecation_warnings: deprecation_warnings, logger: logger)
26
+ config.configure_faraday_connection { |conn| conn.adapter(*Array(faraday_adapter)) } if faraday_adapter
27
+ api_client = Generated::ApiClient.new(config)
28
+ api_client.default_headers['User-Agent'] = "trustcomponent-ruby/#{VERSION}"
29
+ @captcha = CaptchaModule.new(api_client)
30
+ @analytics = Generated::AnalyticsModule.new(api_client)
31
+ @monitoring = Generated::MonitoringModule.new(api_client)
32
+ @tax_validation = Generated::TaxValidationModule.new(api_client)
33
+ @platform = Generated::PlatformModule.new(api_client)
34
+ end
35
+
36
+ private
37
+
38
+ def sdk_header(integration)
39
+ metadata = { sdk: 'ruby', version: VERSION, api: Generated::API_VERSION, runtime: "ruby/#{RUBY_VERSION}", os: RbConfig::CONFIG['host_os'] }
40
+ metadata[:integration] = integration if integration
41
+ Base64.strict_encode64(JSON.generate(metadata))
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,58 @@
1
+ require 'json'
2
+
3
+ module TrustComponent
4
+ # Every error the SDK raises. +status+ is the HTTP status (0 when no response arrived), +code+ the stable reason of the API.
5
+ class Error < StandardError
6
+ attr_reader :status, :code, :detail, :retry_after_seconds
7
+
8
+ def initialize(message, status: 0, code: nil, detail: nil, retry_after_seconds: nil)
9
+ super(message)
10
+ @status = status
11
+ @code = code
12
+ @detail = detail
13
+ @retry_after_seconds = retry_after_seconds
14
+ end
15
+
16
+ def self.of(status, body, retry_after_seconds)
17
+ problem = begin
18
+ body.nil? || body.empty? ? {} : JSON.parse(body)
19
+ rescue JSON::ParserError
20
+ {}
21
+ end
22
+ problem = {} unless problem.is_a?(Hash)
23
+ code = problem['code'].is_a?(String) ? problem['code'] : nil
24
+ detail = problem['detail'].is_a?(String) ? problem['detail'] : nil
25
+ message = "TrustComponent API answered #{status}#{code ? " (#{code})" : ''}#{detail ? ": #{detail}" : ''}"
26
+ return OperationRetiredError.new("#{message}. Update the TrustComponent SDK.", status: status, code: code, detail: detail) if status == 410 && code == 'operation_retired'
27
+
28
+ klass = case status
29
+ when 400, 422 then InvalidRequestError
30
+ when 401 then AuthenticationError
31
+ when 402 then PlanLimitError
32
+ when 403 then PermissionError
33
+ when 404 then NotFoundError
34
+ when 409, 412, 423 then ConflictError
35
+ when 410 then GoneError
36
+ when 429 then RateLimitError
37
+ else status >= 500 ? ServerError : Error
38
+ end
39
+ klass.new(message, status: status, code: code, detail: detail, retry_after_seconds: retry_after_seconds)
40
+ end
41
+ end
42
+
43
+ class InvalidRequestError < Error; end
44
+ class AuthenticationError < Error; end
45
+ class PermissionError < Error; end
46
+ class PlanLimitError < Error; end
47
+ class NotFoundError < Error; end
48
+ class ConflictError < Error; end
49
+ class GoneError < Error; end
50
+ class RateLimitError < Error; end
51
+ class ServerError < Error; end
52
+ # The operation was switched off after its sunset. A newer SDK calls its successor.
53
+ class OperationRetiredError < Error; end
54
+ # No response arrived: timeout, DNS, connection refused.
55
+ class ConnectionError < Error; end
56
+ # The string is not a token of the TrustCaptcha widget.
57
+ class VerificationTokenInvalidError < Error; end
58
+ end
@@ -0,0 +1,83 @@
1
+ require 'faraday'
2
+ require 'set'
3
+ require 'time'
4
+
5
+ module TrustComponent
6
+ # The single HTTP path of the SDK: retries what the API reserves for retries (429 with Retry-After, 502/503/504,
7
+ # no response at all), warns once per deprecated operation and turns every other non-2xx answer into a typed
8
+ # TrustComponent::Error before the generated code sees it.
9
+ class HttpMiddleware < Faraday::Middleware
10
+ RETRYABLE_STATUS = [502, 503, 504].freeze
11
+ MAX_RETRY_AFTER_SECONDS = 60
12
+ UUID = /[0-9a-f]{8}-[0-9a-f-]{27}/i.freeze
13
+ @warned = Set.new
14
+ @lock = Mutex.new
15
+
16
+ class << self
17
+ def warn_once?(operation)
18
+ @lock.synchronize { @warned.add?(operation) ? true : false }
19
+ end
20
+ end
21
+
22
+ def initialize(app, options = {})
23
+ super(app)
24
+ @options = options
25
+ end
26
+
27
+ def call(env)
28
+ env.request_headers['Authorization'] = "Bearer #{@options[:api_key]}"
29
+ env.request_headers['User-Agent'] = @options[:user_agent]
30
+ env.request_headers['TrustComponent-Sdk'] = @options[:sdk_header]
31
+ body = env.body
32
+ attempt = 0
33
+ loop do
34
+ env.body = body
35
+ response = begin
36
+ @app.call(env)
37
+ rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
38
+ raise ConnectionError.new("TrustComponent API not reachable: #{e.message}") if attempt >= @options[:max_retries]
39
+
40
+ sleep(backoff(attempt))
41
+ attempt += 1
42
+ next
43
+ end
44
+ warn_if_deprecated(env, response)
45
+ return response if response.status >= 200 && response.status < 300
46
+
47
+ retry_after = retry_after_seconds(response.headers['Retry-After'])
48
+ retryable = RETRYABLE_STATUS.include?(response.status) || (response.status == 429 && !retry_after.nil?)
49
+ if retryable && attempt < @options[:max_retries] && (retry_after || 0) <= MAX_RETRY_AFTER_SECONDS
50
+ sleep(retry_after || backoff(attempt))
51
+ attempt += 1
52
+ next
53
+ end
54
+ raise Error.of(response.status, response.body.to_s, retry_after)
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def backoff(attempt)
61
+ [0.5 * (2**attempt), 8.0].min + rand * 0.25
62
+ end
63
+
64
+ def retry_after_seconds(value)
65
+ return nil if value.nil?
66
+ return [value.strip.to_i, 0].max if value.strip.match?(/\A\d+\z/)
67
+
68
+ [(Time.httpdate(value) - Time.now).to_i, 0].max
69
+ rescue ArgumentError
70
+ nil
71
+ end
72
+
73
+ def warn_if_deprecated(env, response)
74
+ return unless @options[:deprecation_warnings] && response.headers['Deprecation']
75
+
76
+ operation = "#{env.method.to_s.upcase} #{env.url.path.gsub(UUID, '{id}')}"
77
+ return unless self.class.warn_once?(operation)
78
+
79
+ sunset = response.headers['Sunset']
80
+ @options[:logger].call("TrustComponent: #{operation} is deprecated#{sunset ? " and will be switched off on #{sunset}" : ''}. Update the TrustComponent SDK.")
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,15 @@
1
+ # The generated code is declared as `module TrustComponent::Generated`, which needs the outer module first.
2
+ module TrustComponent
3
+ end
4
+
5
+ require 'trustcomponent_generated'
6
+ require 'trustcomponent_generated/modules'
7
+
8
+ module TrustComponent
9
+ VERSION = Generated::SDK_VERSION
10
+ end
11
+
12
+ require 'trustcomponent/errors'
13
+ require 'trustcomponent/http_middleware'
14
+ require 'trustcomponent/captcha'
15
+ require 'trustcomponent/client'
@@ -0,0 +1,90 @@
1
+ =begin
2
+ #TrustComponent API
3
+
4
+ #The public API of every TrustComponent module, authenticated with an API key (`ak_…`). Each operation carries its own version in its path.
5
+
6
+ The version of the OpenAPI document: 0.0.1-beta.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.24.0
10
+
11
+ =end
12
+
13
+ require 'cgi'
14
+
15
+ module TrustComponent::Generated
16
+ class AnalyticsServerEventsApi
17
+ attr_accessor :api_client
18
+
19
+ def initialize(api_client = ApiClient.default)
20
+ @api_client = api_client
21
+ end
22
+ # Accepts a batch of events from a customer backend
23
+ # Verified business events that do not depend on a browser: a completed order, a refund, a signup confirmed by e-mail, a backend error. Authenticated with a project API key; the batch names the website, which must belong to the subscription of the key. Every event carries a stable id, so a retried batch never creates a second copy. The address and user agent of the request belong to the sending server and are never used for geo, device or bot detection; the end user's address and user agent are taken from the event only when the backend sends them explicitly, and neither is stored. A purchase sent from the server replaces the browser purchase of the same order id, a browser purchase never replaces a server one. A session that holds only server events counts for goals and revenue, but is no visit: sessions, visitors and bounce rate count sessions with at least one browser event. The server answers 202 as soon as the accepted events are written and lists per reason how many events it dropped.
24
+ # @param analytics_server_event_batch_create_params [AnalyticsServerEventBatchCreateParams] Website, the consent the operator vouches for, and the events
25
+ # @param [Hash] opts the optional parameters
26
+ # @return [AnalyticsServerEventBatchResult]
27
+ def create_server_event_batch(analytics_server_event_batch_create_params, opts = {})
28
+ data, _status_code, _headers = create_server_event_batch_with_http_info(analytics_server_event_batch_create_params, opts)
29
+ data
30
+ end
31
+
32
+ # Accepts a batch of events from a customer backend
33
+ # Verified business events that do not depend on a browser: a completed order, a refund, a signup confirmed by e-mail, a backend error. Authenticated with a project API key; the batch names the website, which must belong to the subscription of the key. Every event carries a stable id, so a retried batch never creates a second copy. The address and user agent of the request belong to the sending server and are never used for geo, device or bot detection; the end user&#39;s address and user agent are taken from the event only when the backend sends them explicitly, and neither is stored. A purchase sent from the server replaces the browser purchase of the same order id, a browser purchase never replaces a server one. A session that holds only server events counts for goals and revenue, but is no visit: sessions, visitors and bounce rate count sessions with at least one browser event. The server answers 202 as soon as the accepted events are written and lists per reason how many events it dropped.
34
+ # @param analytics_server_event_batch_create_params [AnalyticsServerEventBatchCreateParams] Website, the consent the operator vouches for, and the events
35
+ # @param [Hash] opts the optional parameters
36
+ # @return [Array<(AnalyticsServerEventBatchResult, Integer, Hash)>] AnalyticsServerEventBatchResult data, response status code and response headers
37
+ def create_server_event_batch_with_http_info(analytics_server_event_batch_create_params, opts = {})
38
+ if @api_client.config.debugging
39
+ @api_client.config.logger.debug 'Calling API: AnalyticsServerEventsApi.create_server_event_batch ...'
40
+ end
41
+ # verify the required parameter 'analytics_server_event_batch_create_params' is set
42
+ if @api_client.config.client_side_validation && analytics_server_event_batch_create_params.nil?
43
+ fail ArgumentError, "Missing the required parameter 'analytics_server_event_batch_create_params' when calling AnalyticsServerEventsApi.create_server_event_batch"
44
+ end
45
+ # resource path
46
+ local_var_path = '/analytics/v1/server-events/batches'
47
+
48
+ # query parameters
49
+ query_params = opts[:query_params] || {}
50
+
51
+ # header parameters
52
+ header_params = opts[:header_params] || {}
53
+ # HTTP header 'Accept' (if needed)
54
+ header_params['Accept'] = @api_client.select_header_accept(['application/json']) unless header_params['Accept']
55
+ # HTTP header 'Content-Type'
56
+ content_type = @api_client.select_header_content_type(['application/json'])
57
+ if !content_type.nil?
58
+ header_params['Content-Type'] = content_type
59
+ end
60
+
61
+ # form parameters
62
+ form_params = opts[:form_params] || {}
63
+
64
+ # http body (model)
65
+ post_body = opts[:debug_body] || @api_client.object_to_http_body(analytics_server_event_batch_create_params)
66
+
67
+ # return_type
68
+ return_type = opts[:debug_return_type] || 'AnalyticsServerEventBatchResult'
69
+
70
+ # auth_names
71
+ auth_names = opts[:debug_auth_names] || ['bearerApiKey']
72
+
73
+ new_options = opts.merge(
74
+ :operation => :"AnalyticsServerEventsApi.create_server_event_batch",
75
+ :header_params => header_params,
76
+ :query_params => query_params,
77
+ :form_params => form_params,
78
+ :body => post_body,
79
+ :auth_names => auth_names,
80
+ :return_type => return_type
81
+ )
82
+
83
+ data, status_code, headers = @api_client.call_api(:POST, local_var_path, new_options)
84
+ if @api_client.config.debugging
85
+ @api_client.config.logger.debug "API called: AnalyticsServerEventsApi#create_server_event_batch\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
86
+ end
87
+ return data, status_code, headers
88
+ end
89
+ end
90
+ end