Skip to content

About

Ruby SDK to interact with the Whop API

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

Whop Ruby Library

The Whop SDK gives you typed access to the Whop API from Ruby.

Table of Contents

Requirements

Ruby 3.3 or higher.

Installation

Add the gem to your application's Gemfile:

gem "whop_sdk"

Or install it directly:

gem install whop_sdk

Usage

require "whop_sdk"

client = Whop_sdk::Client.new(token: ENV.fetch("WHOP_API_KEY"))

product = client.products.retrieve(id: "prod_xxxxxxxxxxxxx")
puts product.title

token: is required, and the SDK reads no environment variables itself: pass your API key, or any other access token, explicitly. Keep business API keys on your server.

The client also takes:

  • max_retries: how many times a failed request is retried (default 2, see Retries and timeouts).
  • idempotency_key: an Idempotency-Key header sent with every request the client makes.
  • api_version_date: the Api-Version-Date header. It defaults to the API version this SDK was generated against, so leave it unset unless you have a reason to pin another version.

Environments

The client calls production by default. To call the sandbox, pass the environment:

client = Whop_sdk::Client.new(
  token: ENV.fetch("WHOP_API_KEY"),
  environment: Whop_sdk::Environment::SANDBOX
)

An environment names both of Whop's hosts: the API, and the vault host that receives card details. To send every request to one URL instead, for example a proxy, pass base_url::

client = Whop_sdk::Client.new(token: ENV.fetch("WHOP_API_KEY"), base_url: "https://proxy.example.com/api/v1")

Pagination

List methods return an Enumerable that fetches the next page as you iterate:

client.products.list(account_id: "biz_xxxxxxxxxxxxx").each do |product|
  puts product.id
end

Pass first: to set the page size. To work a page at a time, iterate pages; each page is the list response, with data and page_info:

client.products.list(account_id: "biz_xxxxxxxxxxxxx", first: 50).pages.each do |page|
  puts page.data.size
end

Errors

A response with an error status raises a subclass of Whop_sdk::Errors::ResponseError, which carries the status as code:

Status Error
401 Whop_sdk::Errors::UnauthorizedError
403 Whop_sdk::Errors::ForbiddenError
404 Whop_sdk::Errors::NotFoundError
other 4xx Whop_sdk::Errors::ClientError
503 Whop_sdk::Errors::ServiceUnavailableError
other 5xx Whop_sdk::Errors::ServerError
3xx Whop_sdk::Errors::RedirectError
begin
  client.products.retrieve(id: "prod_xxxxxxxxxxxxx")
rescue Whop_sdk::Errors::NotFoundError
  puts "No such product"
rescue Whop_sdk::Errors::ResponseError => e
  puts "The API answered #{e.code}: #{e.message}"
end

Every SDK error descends from Whop_sdk::Errors::ApiError.

Retries and timeouts

A request that gets a 408, 429, 500, 502, 503, 504, 521, 522 or 524 is retried up to max_retries times (default 2), with exponential backoff and jitter, honoring a Retry-After header:

client = Whop_sdk::Client.new(token: ENV.fetch("WHOP_API_KEY"), max_retries: 4)

Each request times out after 60 seconds.

Request options

Every method takes request_options: for that one call:

client.products.list(
  account_id: "biz_xxxxxxxxxxxxx",
  request_options: {
    additional_headers: {"Idempotency-Key" => "my-key"},
    additional_query_parameters: {"my_param" => "value"}
  }
)
  • additional_headers: extra headers. They can replace Api-Version-Date and Idempotency-Key, but not the other headers the client sets, such as Authorization.
  • additional_query_parameters: extra query parameters.
  • base_url: a URL for this call alone.

Verifying webhooks

WhopSDK::Helpers::VerifyWebhook.unwrap checks the signature Whop sends with every webhook delivery and returns the parsed body, a Hash with symbol keys:

event = WhopSDK::Helpers::VerifyWebhook.unwrap(
  body,
  headers: {
    "webhook-id" => webhook_id,
    "webhook-timestamp" => webhook_timestamp,
    "webhook-signature" => webhook_signature
  },
  key: ENV.fetch("WHOP_WEBHOOK_SECRET")
)
puts event[:type]

Pass the raw request body exactly as received (a re-serialized body fails verification), a Hash of the request's headers (only webhook-id, webhook-timestamp and webhook-signature are read, in any case), and the endpoint's ws_ signing secret exactly as Whop shows it. A missing or mismatched signature, or a timestamp outside the tolerance window, raises StandardWebhooks::WebhookVerificationError.

Verifying user tokens

An app that Whop embeds receives an x-whop-user-token header naming the signed-in user. WhopSDK::Helpers::VerifyUserToken.verify_user_token! verifies it against Whop's public signing keys and returns who it is:

payload = WhopSDK::Helpers::VerifyUserToken.verify_user_token!(
  user_token,
  app_id: "app_xxxxxxxxxxxxx"
)
puts payload.user_id

It takes the token itself, or a Hash of the request's headers to read x-whop-user-token from. It raises when the token is missing, invalid, or issued for another app, and caches Whop's signing keys in the process.

Authenticating with OIDC

A workload in GitHub Actions or Google Cloud can trade its OIDC identity token for a short-lived Whop access token instead of holding an API key:

token = WhopSDK::Helpers::Oidc.access_token(
  role_id: "aurl_xxxxxxxxxxxxx",
  identity_token: WhopSDK::Helpers::Oidc.github_actions_identity_token
)
client = Whop_sdk::Client.new(token: token)

The token lasts an hour by default (expires_at: sets up to three). In GitHub Actions the job needs permissions: id-token: write; on Google Cloud use WhopSDK::Helpers::Oidc.google_cloud_identity_token. A failed exchange raises WhopSDK::Helpers::Oidc::Error.

Live reads

Some reads can be watched: their client carries watch and wait_for beside the read, taking exactly the read's arguments. watch yields the answer now and again each time it changes:

client.stats.time_series.watch(metric: "gmv", from: "2026-11-01", to: "2026-11-30") do |series|
  puts series.data.points.size
end

Without a block it returns a stream you can iterate and close from any thread. wait_for returns the first answer that satisfies until:, or raises Whop_sdk::Live::WaitForTimeoutError after timeout: seconds:

series = client.stats.time_series.wait_for(
  metric: "gmv", from: "2026-11-01", to: "2026-11-30",
  until: ->(series) { series.data.points.size == 30 },
  timeout: 120
)

A dropped connection reconnects on its own; on_disconnect: is called with each drop.

Reference

Every method is listed in reference.md, and the API itself is documented at docs.whop.com.

Contributing

This library is generated from the Whop API's OpenAPI document, and every release replaces this repository's contents, so changes made here directly cannot be merged. Open an issue to report a problem or ask for a change.

About

Ruby SDK to interact with the Whop API

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages