Polar::Client
Extend Client class with webhooks API accessor
Constants
Constructors
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
)
Instance methods
Access the benefit_grants API
@return [Api::BenefitGrants] The benefit_grants API client
Access the checkout_links API
@return [Api::CheckoutLinks] The checkout_links API client
Access the custom_fields API
@return [Api::CustomFields] The custom_fields API client
Access the customer_meters API
@return [Api::CustomerMeters] The customer_meters API client
Access the customer_portal API
@return [Api::CustomerPortal::Base] The customer_portal API client
Access the customer_seats API
@return [Api::CustomerSeats] The customer_seats API client
Access the customer_sessions API
@return [Api::CustomerSessions] The customer_sessions API client
Access the license_keys API
@return [Api::LicenseKeys] The license_keys API client
Access the organizations API
@return [Api::Organizations] The organizations API client
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.
Access the subscriptions API
@return [Api::Subscriptions] The subscriptions API client