Back to SDKsView on GitHub
Ruby SDK
Ruby SDK with Rails integration, Faraday client, and webhook helpers.
gem install coverkitInstallation
Gemfile
gem 'coverkit'Command line
gem install coverkitQuick Start
require 'coverkit'
# Configure the client
Coverkit.configure do |config|
config.api_key = ENV['COVERKIT_API_KEY']
config.environment = :production # or :sandbox
end
# Create a quote
quote = Coverkit::Quote.create(
product: 'shipping_protection',
coverage: {
item_value: 15000, # $150.00 in cents
shipping_method: 'ground'
},
customer: {
email: 'customer@example.com'
}
)
puts "Quote ID: #{quote.id}"
puts "Premium: $#{quote.premium / 100.0}"
# Bind the quote to create a policy
policy = Coverkit::Policy.create(
quote_id: quote.id,
payment: {
method: 'stripe',
token: 'tok_visa'
}
)
puts "Policy ID: #{policy.id}"
puts "Status: #{policy.status}" # "active"Rails Integration
# config/initializers/coverkit.rb
Coverkit.configure do |config|
config.api_key = Rails.application.credentials.coverkit_api_key
config.environment = Rails.env.production? ? :production : :sandbox
end
# app/controllers/quotes_controller.rb
class QuotesController < ApplicationController
def create
quote = Coverkit::Quote.create(quote_params)
render json: { quote_id: quote.id, premium: quote.premium }
rescue Coverkit::Error => e
render json: { error: e.message }, status: :unprocessable_entity
end
private
def quote_params
params.require(:quote).permit(:product, coverage: {}, customer: {})
end
endFeatures
Rails Integration
First-class Rails support with generators and helpers.
Faraday Client
Built on Faraday for flexible HTTP configuration.
Webhook Verification
Easy webhook signature verification.
Test Helpers
RSpec matchers and factory helpers.
Webhook Handling
# app/controllers/webhooks_controller.rb
class WebhooksController < ApplicationController
skip_before_action :verify_authenticity_token
def coverkit
payload = request.body.read
signature = request.headers['Coverkit-Signature']
event = Coverkit::Webhook.construct_event(
payload,
signature,
ENV['COVERKIT_WEBHOOK_SECRET']
)
case event.type
when 'policy.created'
handle_policy_created(event.data)
when 'claim.submitted'
handle_claim_submitted(event.data)
end
head :ok
rescue Coverkit::SignatureVerificationError
head :bad_request
end
end