Skip to content

abxy-labs/tripwire-server-ruby

Repository files navigation

Tripwire Ruby Library

Preview Ruby 2.6+ License: MIT

The Tripwire Ruby library provides convenient access to the Tripwire API from applications written in Ruby. It includes a client for Sessions, visitor fingerprints, Teams, Team API key management, and sealed token verification.

The library also provides:

  • a fast configuration path using TRIPWIRE_SECRET_KEY
  • lazy helpers for cursor-based pagination
  • structured API errors and built-in sealed token verification

Documentation

See the Tripwire docs and API reference.

Installation

You don't need this source code unless you want to modify the gem. If you just want to use the package, run:

bundle add tripwire-server

Requirements

  • Ruby 2.6+

Usage

The library needs to be configured with your account's secret key. Set TRIPWIRE_SECRET_KEY in your environment or pass secret_key directly:

require "tripwire/server"

client = Tripwire::Server::Client.new(secret_key: "sk_live_...")

page = client.sessions.list(verdict: "bot", limit: 25)
session = client.sessions.get("sid_0123456789abcdefghjkmnpqrs")

puts "#{session[:decision][:automation_status]} #{session[:highlights].first&.fetch(:summary, nil)}"

Sealed token verification

result = Tripwire::Server.safe_verify_tripwire_token(sealed_token, "sk_live_...")

if result[:ok]
  puts "#{result[:data][:decision][:verdict]} #{result[:data][:decision][:risk_score]}"
else
  warn result[:error].message
end

Pagination

client.sessions.iter(search: "signup").each do |session|
  puts "#{session[:id]} #{session[:latest_decision][:verdict]}"
end

Visitor fingerprints

fingerprint = client.fingerprints.get("vid_0123456789abcdefghjkmnpqrs")
puts fingerprint[:id]

Teams

team = client.teams.get("team_0123456789abcdefghjkmnpqrs")
updated = client.teams.update("team_0123456789abcdefghjkmnpqrs", name: "New Name")

puts updated[:name]

Team API keys

created = client.teams.api_keys.create("team_0123456789abcdefghjkmnpqrs", name: "Production", environment: "live")
client.teams.api_keys.revoke("team_0123456789abcdefghjkmnpqrs", created[:id])

Error handling

begin
  client.sessions.list(limit: 999)
rescue Tripwire::Server::ApiError => error
  warn "#{error.status} #{error.code} #{error.message}"
end

Support

If you need help integrating Tripwire, start with tripwirejs.com/docs.

About

Official Tripwire Ruby server SDK

Resources

License

Stars

Watchers

Forks

Contributors