This repository contains a Ruby gem, turnkey_client
to interact with the Turnkey API.
To install turnkey_client
, install it with bundler:
bundle add turnkey_client
Then require
it in Ruby files to use it:
require "turnkey_client"
client = TurnkeyClient.configure do |c|
c.api_public_key = "your API public key"
c.api_private_key = "your API private key"
end
response = TurnkeyClient::SessionsApi.new(client).get_whoami({ organization_id: "your organization ID"})
puts response
See the examples folder if you're looking for a complete sample project
- Whoami: example showcasing API request signing in its simplest form
- Signing: example showcasing wallet creation and ETH message signing
To use in Rails we recommend creating a new config/initializers/turnkey.rb
file:
require 'turnkey_client'
TURNKEY_CLIENT = TurnkeyClient.configure do |config|
c.api_public_key = "your API public key"
c.api_private_key = "your API private key"
end
You can then use this in your controller or models with:
require 'turnkey_client'
TurnkeyClient::SessionsApi.new(TURNKEY_CLIENT).get_whoami({ organization_id: "your organization ID"})
We use a swagger spec and Swagger Codegen to generate turnkey_client
. To update this gem:
- Update the swagger spec in
turnkey_client_inputs
- Bump
gemVersion
inconfig.json
- Run
make
We use custom templates to insert custom functionality, namely:
- added
openssl
as a dependency to load API keys - added functionality to insert
X-Stamp
headers to requests for authentication - modified
configure
function to require a valid P256 public/private key pair at initialization time
If you want to tweak something related to codegen itself, head (here), make the desired change, and re-generate turnkey_client
If you want to update templates with upstream this is a bit harder but possible: these templates were downloaded from this folder (this is a permalink to the right git SHA). You can see all the changes made to these by looking at the history of changes in the templates folder: https://github.com/tkhq/ruby-sdk/commits/main/turnkey_client_inputs/templates.
On Mac, Ruby will come installed automatically. However, the default version might not be compatible with certain gems, nor will it allow you to modify the default gems directory. To set up Ruby, there are many options: rbenv, rvm, asdf, chruby, etc. For example, rbenv can be set up by following the instructions here.
We use Rubocop for linting. To install:
$ gem install rubocop
And run:
$ rubocop
To build and release:
$ cd turnkey_client
$ gem build turnkey_client.gemspec
$ gem push turnkey_client-x.y.z.gem