Skip to Content
SDKsRuby

Ruby SDK

A Ruby client built on Faraday. It requires Ruby 3.1 or later.

# Gemfile gem "license_manager"

RubyGems  · GitHub  · API Reference 

How it works

The SDK has one class per section of the API Reference , like LicenseManager::LicensesApi or LicenseManager::CustomersApi, and one method per endpoint, named after it: Create a license is create_license. Each method takes the path parameters and the body as arguments, and the optional parameters as a hash, in snake case, and returns the response as a model.

The API Reference lists every endpoint with its parameters and response: the SDK’s methods take and return the same ones.

Authentication

Configure the credentials once, for every call:

require "license_manager" LicenseManager.configure do |config| # With an API key, from your backend: config.api_key["x-api-key"] = ENV.fetch("LICENSEMANAGER_API_KEY") # Or with a token scoped to a customer, license or machine: config.access_token = token end licenses = LicenseManager::LicensesApi.new

Never ship an API key in your application: anyone could extract it. Keep it on your servers.

Examples

Create a license after a sale, and email its key to the customer:

license = licenses.create_license( "x7Kp2QaZ", LicenseManager::CreateLicense.new(email: "jane@example.com", send_key: true), )

Validate a key from your application, which needs no credentials:

license_token = LicenseManager::LicensesApi.new.validate_key( "x7Kp2QaZ", LicenseManager::ValidateKey.new( key: "7KQ2M-X9ZPA-H4TRC-WN6EY-B3JDF", fingerprint: "4c:32:75:8f:9a:1e", version: "1.4.2", ), ) # license_token.license is the signed license token.

List the licenses of a product, one page at a time:

page = licenses.list_licenses("x7Kp2QaZ", page: 2, page_size: 50, sort: "-createdAt") # page.data holds the licenses, page.pagination the totals.

Errors

A failed request raises a LicenseManager::ApiError, holding the status and the body with the error’s stable code:

begin licenses.get_license("l3Nv8KwB") rescue LicenseManager::ApiError => error # The body is { "error": { "code", "message" } }. puts error.code, error.response_body end