Easy Labs Ruby SDK
Idiomatic Ruby client for the Easy Labs API. Mirrors
the @easylabs/node JavaScript SDK
feature surface — same resource model, same wire shapes, same webhook
verifier.
Install
# Gemfile
gem "easylabs", "~> 0.1"
bundle install
# or, without bundler:
gem install easylabs
Quickstart
require "easylabs"
client = EasyLabs::Client.new(api_key: ENV.fetch("EASY_API_KEY"))
customer = client.customers.create(
first_name: "Ada",
last_name: "Lovelace",
email: "ada@example.com"
)
puts customer[:id] # => "cust_..."
Use a sk_test_… key to hit the sandbox automatically.
Webhook verification
require "easylabs"
post "/webhooks/easy" do
event = EasyLabs::Webhooks.construct_event(
payload: request.body.read,
signature: request.headers["X-Easy-Webhook-Signature"],
secret: ENV.fetch("EASY_WEBHOOK_SECRET")
)
case event[:type]
when "payment.created" then handle_payment_created(event[:data])
when "subscription.paused" then handle_subscription_paused(event[:data])
end
status 204
end
EasyLabs::Webhooks::EVENT_TYPES contains every event the API can emit.
Error handling
begin
client.subscriptions.cancel("sub_xyz")
rescue EasyLabs::RateLimitError => e
sleep e.retry_after_seconds || 1
retry
rescue EasyLabs::AuthenticationError => e
# api key is bad
rescue EasyLabs::Error => e
# everything else
end
Every exception under EasyLabs::Error exposes #status, #code,
#details, #retry_after_seconds, and #raw.
Resources
client.customers, client.payment_instruments, client.transfers,
client.disputes, client.settlements, client.products,
client.product_prices, client.orders, client.subscriptions,
client.checkout, client.payment_links, client.embedded_checkout,
client.webhooks, client.invoices, client.coupons,
client.promotion_codes, client.authorizations, client.analytics,
client.compliance_forms, client.dunning_config,
client.revenue_recovery_automations.
Development
bin/setup # bundle install
bundle exec rspec
bundle exec rubocop
bundle exec rake build # build gem into pkg/
Pull requests welcome at https://github.com/itseasyco/easy-sdk-ruby.
License
MIT — see LICENSE.