Ruby SDK


The recommended way to install the Unimatrix SDK for Ruby is to use the gem package manager, which is available on RubyGems.

Run the following command to add uni-sdk as a dependency to your project:

gem install uni-sdk

If you are installing via Bundler, add this line to your application's Gemfile:

gem 'uni-sdk'


The following example shows how to use the Unimatrix Ruby SDK to interact with Unimatrix services.

Initialize a client

require 'uni-sdk'

client ='your access key id', 'your access key secret') # if using simple auth mode, just pass in the first parameter

or you can configure your credentials by environment variables:

export UNIMTX_ACCESS_KEY_ID=your_access_key_id
export UNIMTX_ACCESS_KEY_SECRET=your_access_key_secret

Send SMS

Send a text message to a single recipient.

require 'uni-sdk'

client =

  resp = client.messages.send({
    to: '+1206880xxxx', # in E.164 format
    text: 'Your verification code is 2048.'
rescue Uni::UniError => e
  puts 'Exception: ' + e.message

Send a message using a template with variables.

  to: '+1650253xxxx',
  signature: 'Unimatrix',
  templateId: 'pub_verif_en_basic2',
  templateData: {
    code: '2048'

Send OTP

Send a one-time passcode (OTP) to a recipient. The following example will send a automatically generated verification code to the user.

require 'uni-sdk'

client =

resp = client.otp.send({
  to: '+1206880xxxx'

Verify OTP

Verify the one-time passcode (OTP) that a user provided. The following example will check whether the user-provided verification code is correct.

require 'uni-sdk'

client =

resp = client.otp.verify({
  to: '+1206880xxxx',
  code: '123456' # the code user provided
puts resp.valid