Getting started with Ruby
The source code of the Ruby SDK is hosted here: https://github.com/clerkinc/clerk-sdk-ruby
Add this line to your application's Gemfile
gem 'clerk-sdk-ruby', require: "clerk"
And then execute:
$ bundle install
Or install it yourself as:
$ gem install clerk-sdk-ruby
Quick Start
First, you need to get an API key for a Clerk instance.
This is done on the API Keys page.
Then you can instantiate a Clerk::SDK
instance and access all Backend API endpoints. Here's a quick example:
.env1
Configuration
The SDK can be configured in three ways: environment variables, configuration singleton and constructor arguments. The priority goes like this:
- Constructor arguments
- Configuration object
- Environment variables
If an argument is not provided, the configuration object is looked up, which falls back to the associated environment variable. Here's an example with all supported configuration settings their environment variable equivalents:
1Clerk.configure do |c|2c.secret_key = "your_secret_key" # if omitted: ENV["CLERK_SECRET_KEY"] - API calls will fail if unset3c.base_url = "https://..." # if omitted: "https://api.clerk.dev/v1/"4c.logger = Logger.new(STDOUT) # if omitted, no logging5c.middleware_cache_store = Rails.cache # if omitted: no caching6end
You can customize each instance of the Clerk::SDK
object by passing keyword arguments to the constructor:
1clerk = Clerk::SDK.new(2secret_key: "X",3base_url: "Y",4logger: Logger.new()5)
Refer to the Faraday documentation for details.
Environment variables
Here's a list of all environment variables the SDK uses:
Variable name | Usage |
---|---|
CLERK_API_BASE
|
Overrides the default API base URL: https://api.clerk.dev/v1/ |
CLERK_API_KEY
|
The Secret key of your instance (required) |
CLERK_SIGN_IN_URL
|
Rails view helper: clerk_sign_in_url
|
CLERK_SIGN_IN_UP
|
Rails view helper: clerk_sign_up_url
|
CLERK_USER_PROFILE_URL
|
Rails view helper: clerk_user_profile_url
|