class

Polar::Client

Inherits Reference < Object

Extend Client class with webhooks API accessor

Constants

Log = ::Log.for(self)

Constructors

new(access_token : String | Nil = nil, server_url : String | Nil = nil, max_retries : Int32 = 3, initial_retry_delay : Float64 = 1.0, max_retry_delay : Float64 = 60.0)

Initialize a new Polar API client

@param access_token [String?] API access token (falls back to POLAR_ACCESS_TOKEN env var) @param server_url [String?] API server URL (falls back to POLAR_SERVER_URL env var or https://api.polar.sh) @param max_retries [Int32] Maximum number of retry attempts (default: 3) @param initial_retry_delay [Float64] Initial delay for exponential backoff in seconds (default: 1.0) @param max_retry_delay [Float64] Maximum delay between retries in seconds (default: 60.0)

@raise [Exception] If access_token is not provided and POLAR_ACCESS_TOKEN is not set

Example:

# Use environment variables (recommended)
client = Polar::Client.new

# Explicit credentials with custom retry configuration
client = Polar::Client.new(
  access_token: "polar_at_...",
  server_url: "https://sandbox.polar.sh",
  max_retries: 5,
  initial_retry_delay: 2.0
)
Source

Instance methods

access_token

Your Polar.sh API access token

Source
benefit_grants

Access the benefit_grants API

@return [Api::BenefitGrants] The benefit_grants API client

Source
benefits

Access the benefits API

@return [Api::Benefits] The benefits API client

Source
checkouts

Access the checkouts API

@return [Api::Checkouts] The checkouts API client

Source
custom_fields

Access the custom_fields API

@return [Api::CustomFields] The custom_fields API client

Source
customer_meters

Access the customer_meters API

@return [Api::CustomerMeters] The customer_meters API client

Source
customer_portal

Access the customer_portal API

@return [Api::CustomerPortal::Base] The customer_portal API client

Source
customer_seats

Access the customer_seats API

@return [Api::CustomerSeats] The customer_seats API client

Source
customer_sessions

Access the customer_sessions API

@return [Api::CustomerSessions] The customer_sessions API client

Source
customers

Access the customers API

@return [Api::Customers] The customers API client

Source
discounts

Access the discounts API

@return [Api::Discounts] The discounts API client

Source
events

Access the events API

@return [Api::Events] The events API client

Source
files

Access the files API

@return [Api::Files] The files API client

Source
initial_retry_delay

Initial delay for exponential backoff (in seconds)

Source
license_keys

Access the license_keys API

@return [Api::LicenseKeys] The license_keys API client

Source
max_retries

Maximum number of retry attempts for failed requests

Source
max_retry_delay

Maximum delay between retries (in seconds)

Source
meters

Access the meters API

@return [Api::Meters] The meters API client

Source
metrics

Access the metrics API

@return [Api::Metrics] The metrics API client

Source
oauth2

Access the oauth2 API

@return [Api::Oauth2::Base] The oauth2 API client

Source
orders

Access the orders API

@return [Api::Orders] The orders API client

Source
organizations

Access the organizations API

@return [Api::Organizations] The organizations API client

Source
payments

Access the payments API

@return [Api::Payments] The payments API client

Source
products

Access the products API

@return [Api::Products] The products API client

Source
refunds

Access the refunds API

@return [Api::Refunds] The refunds API client

Source
request(method : String, path : String, body : String | Nil = nil) : String

Make an HTTP request to the Polar API with retry logic

This is an internal method used by all API clients. It handles:

  • Authentication via Bearer token
  • JSON content type headers
  • Automatic redirect following (up to 10 redirects)
  • Retry with exponential backoff for transient errors
  • Rate limiting with Retry-After header respect
  • Error response mapping to typed exceptions

@param method [String] HTTP method (GET, POST, PUT, PATCH, DELETE) @param path [String] API path (e.g., "/v1/organizations") @param body [String?] Optional request body as JSON string

@return [String] Response body as JSON string

@raise [ResourceNotFoundError] on HTTP 404 @raise [NotPermittedError] on HTTP 403 @raise [HTTPValidationError] on HTTP 422 @raise [PolarError] on other HTTP errors

Note: This method is primarily for internal use by generated API clients. End users typically won't call this directly.

Source
server_url

The Polar.sh API server URL (without trailing slash)

Source
subscriptions

Access the subscriptions API

@return [Api::Subscriptions] The subscriptions API client

Source
wallets

Access the wallets API

@return [Api::Wallets] The wallets API client

Source
webhooks

Access the webhooks API

@return [Api::Webhooks] The webhooks API client

Source