Skip to content

Repository files navigation

Whop Ruby Library

fern shield

The Whop SDK gives you typed access to the Whop API. Pass your API key to the client explicitly — the SDK reads no environment variables, so a client built without a key sends unauthenticated requests and the API answers 401.

Table of Contents

MCP Server

Use the Whop MCP Server to enable AI assistants to interact with this API, allowing them to explore endpoints, make test requests, and use documentation to help integrate this SDK into your application.

Add to Cursor Install in VS Code

Note: You may need to set environment variables in your MCP client.

Documentation

API reference documentation is available here.

Installation

To use this gem, install via Bundler by adding the following to your application's Gemfile:

gem "whop_sdk"

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

require "whop_sdk"

client = Whop_sdk::Client.new(token: "<token>")

client.access_tokens.create

Advanced concepts

BaseModel

All parameter and response objects inherit from WhopSDK::Internal::Type::BaseModel, which provides several conveniences, including:

  1. All fields, including unknown ones, are accessible with obj[:prop] syntax, and can be destructured with obj => {prop: prop} or pattern-matching syntax.

  2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.

  3. Both instances and the classes themselves can be pretty-printed.

  4. Helpers such as #to_h, #deep_to_h, #to_json, and #to_yaml.

Making custom or undocumented requests

Undocumented properties

You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:

Note: the extra_ parameters of the same name overrides the documented parameters.

page =
  whop.payments.list(
    company_id: "biz_xxxxxxxxxxxxxx",
    request_options: {
      extra_query: {my_query_parameter: value},
      extra_body: {my_body_parameter: value},
      extra_headers: {"my-header": value}
    }
  )

puts(page[:my_undocumented_property])

Undocumented request params

If you want to explicitly send an extra param, you can do so with the extra_query, extra_body, and extra_headers under the request_options: parameter when making a request, as seen in the examples above.

Undocumented endpoints

To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using client.request, like so:

response = client.request(
  method: :post,
  path: '/undocumented/endpoint',
  query: {"dog": "woof"},
  headers: {"useful-header": "interesting-value"},
  body: {"hello": "world"}
)

Concurrency & connection pooling

The WhopSDK::Client instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.

Each instance of WhopSDK::Client has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.

When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.

Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.

Sorbet

This library provides comprehensive RBI definitions, and has no dependency on sorbet-runtime.

You can provide typesafe request parameters like so:

whop.payments.list(company_id: "biz_xxxxxxxxxxxxxx")

Or, equivalently:

# Hashes work, but are not typesafe:
whop.payments.list(company_id: "biz_xxxxxxxxxxxxxx")

# You can also splat a full Params class:
params = WhopSDK::PaymentListParams.new(company_id: "biz_xxxxxxxxxxxxxx")
whop.payments.list(**params)

Enums

Since this library does not depend on sorbet-runtime, it cannot provide T::Enum instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:

# :b2b_app
puts(WhopSDK::AppType::B2B_APP)

# Revealed type: `T.all(WhopSDK::AppType, Symbol)`
T.reveal_type(WhopSDK::AppType::B2B_APP)

Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:

# Using the enum constants preserves the tagged type information:
whop.apps.update(
  app_type: WhopSDK::AppType::B2B_APP,
  # …
)

# Literal values are also permissible:
whop.apps.update(
  app_type: :b2b_app,
  # …
)

Versioning

This package follows SemVer conventions. As the library is in initial development and has a major version of 0, APIs may change at any time.

This package considers improvements to the (non-runtime) *.rbi and *.rbs type definitions to be non-breaking changes.

Requirements

Ruby 3.2.0 or higher.

Environments

This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.

Environments

require "whop_sdk"

whop_sdk = Whop_sdk::Client.new(
    base_url: Whop_sdk::Environment::DEFAULT
)

Custom URL

require "whop_sdk"

client = Whop_sdk::Client.new(
    base_url: "https://example.com"
)

Errors

Failed API calls will raise errors that can be rescued from granularly.

require "whop_sdk"

client = Whop_sdk::Client.new(
    base_url: "https://example.com"
)

begin
    result = client.access_tokens.create
rescue Whop_sdk::Errors::TimeoutError
    puts "API didn't respond before our timeout elapsed"
rescue Whop_sdk::Errors::ServiceUnavailableError
    puts "API returned status 503, is probably overloaded, try again later"
rescue Whop_sdk::Errors::ServerError
    puts "API returned some other 5xx status, this is probably a bug"
rescue Whop_sdk::Errors::ResponseError => e
    puts "API returned an unexpected status other than 5xx: #{e.code} #{e.message}"
rescue Whop_sdk::Errors::ApiError => e
    puts "Some other error occurred when calling the API: #{e.message}"
end

Advanced

Retries

The SDK is instrumented with automatic retries. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Error)

The retryStatusCodes configuration controls which 5XX status codes are retried:

  • legacy (default): Retries 408, 429, 500, 502, 503, 504, 521, 522, 524
  • recommended: Retries 408, 429, 502, 503, 504 only (excludes 500 Internal Server Error to avoid retrying non-idempotent failures)

Use the max_retries option to configure this behavior.

require "whop_sdk"

client = Whop_sdk::Client.new(
    base_url: "https://example.com",
    max_retries: 3  # Configure max retries (default is 2)
)

Timeouts

The SDK defaults to a 60 second timeout. Use the timeout option to configure this behavior.

require "whop_sdk"

response = client.access_tokens.create(
    ...,
    timeout: 30  # 30 second timeout
)

Additional Headers

If you would like to send additional headers as part of the request, use the additional_headers request option.

require "whop_sdk"

response = client.access_tokens.create(
    ...,
    request_options: {
        additional_headers: {
            "X-Custom-Header" => "custom-value"
        }
    }
)

Additional Query Parameters

If you would like to send additional query parameters as part of the request, use the additional_query_parameters request option.

require "whop_sdk"

response = client.access_tokens.create(
    ...,
    request_options: {
        additional_query_parameters: {
            "custom_param" => "custom-value"
        }
    }
)

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

About

Ruby SDK to interact with the Whop API

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages