0.0
The project is in a healthy, maintained state
TrustCaptcha, TrustAnalytics, TrustMonitoring, Trust VAT Checker and the platform API.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 3.13

Runtime

>= 1.0.1, < 3.0
 Project Readme

TrustComponent SDK for Ruby

The official SDK for the TrustComponent API: TrustCaptcha, TrustAnalytics, TrustMonitoring, Trust VAT Checker and the platform API, in one package. Developed and hosted in the EU.

Requires Ruby 2.7 or newer (Faraday 1 or 2).

Install

gem install trustcomponent

Check a TrustCaptcha result

The widget writes a verification token into your form. One call turns it into the result:

require 'trustcomponent'

tc = TrustComponent::Client.new('ak_…')
result = tc.captcha.get_verification_result(params['tc-verification-token'])
if result.is_verification_passed
  # …
end

Create the API key (ak_…) in the dashboard under the project's API keys, or under the agency's API keys to reach its client projects. The key decides which projects and modules the client can use.

Every module

The client is module → resource → operation, with the same names in every language:

project_id = tc.platform.projects.get_projects.content.first.id
tc.analytics.websites.get_websites(project_id)
tc.tax_validation.validations.create_validation(project_id, TrustComponent::Api::TaxValidationValidationCreateParams.new(country_code: 'DE', raw_value: 'DE811569869'))
tc.monitoring.monitors.ping_heartbeat(monitor_id)
tc.platform.events.get_events_of_project(project_id)

The full reference of every operation is at https://docs.trustcomponent.com/api/overview/. Guides per module: TrustCaptcha, TrustAnalytics, TrustMonitoring, Trust VAT Checker (taxValidation in the client), platform. Changes of every release: https://docs.trustcomponent.com/api/release-notes/.

Configuration

tc = TrustComponent::Client.new('ak_…', timeout: 5, max_retries: 1, integration: 'my-plugin/1.0')

Options: host, timeout, proxy, max_retries, deprecation_warnings, integration, logger, faraday_adapter.

The SDK retries only what the API reserves for retries: 429 with Retry-After, 502, 503, 504 and a lost connection (2 retries by default). When the API marks an operation as deprecated, it logs one warning per operation.

Every write (POST, PUT, PATCH, DELETE) carries an Idempotency-Key, a new one per call and the same one on each of its retries. The VAT Checker answers a retried write with the stored first answer (Idempotent-Replayed: true), so a retry after a lost answer never creates or deletes twice; a server event batch is deduplicated by the id of each event, and a repeated heartbeat ping does no harm. Pass your own key to make a call idempotent beyond one process, e.g. with your order number: create_validation(project_id, params, header_params: { 'Idempotency-Key' => 'order-4711' }). Every request names the SDK in User-Agent and TrustComponent-Sdk, together with the integration you set.

Errors

Every error is a TrustComponent::Error carrying the HTTP status and the stable code of the API: InvalidRequestError, AuthenticationError, PermissionError, PaymentRequiredError, LockedError, NotFoundError, ConflictError, GoneError, RateLimitError, ServerError, ConnectionError, OperationRetiredError, VerificationTokenInvalidError. ConnectionError means no usable answer arrived (timeout, DNS, connection refused, TLS failure, or an answer that is not one of the API, e.g. the page of a proxy); the original error is its cause.

begin
  result = tc.captcha.get_verification_result(token)
  # evaluate the result
rescue TrustComponent::ConnectionError, TrustComponent::ServerError
  # TrustCaptcha unreachable: apply your failover decision
rescue TrustComponent::Error => e
  # not verified: reject (e.status and e.code tell why)
end

OperationRetired means the operation was switched off after its sunset: update the SDK.

Support

The GitHub repository of this SDK is a read-only mirror of the released source, so pull requests and issues are not processed there. For questions and bug reports, write to mail@trustcomponent.com or contact support through https://www.trustcomponent.com.

License

MIT