Skip to navigation

Ruby guide

This page walks through the whole Ruby SDK in the order you would use it. Each step starts with the shortest code that works, then shows the other ways to write it.

Download the Ruby SDK if you have not done so yet.

Requirements

SupportedRecommended
Ruby2.7 to 4.03.3 or newer
GemsNone outside the standard library

Ed25519 uses OpenSSL when your Ruby supports it, and a built-in implementation otherwise, so older Ruby builds work without extra setup. On Linux and macOS, pass your own system_id and storage when you create the client, as shown in Options.

Add the SDK to your project

Unzip the download into a folder in your project, for example authlyx, and require it:

require_relative "authlyx/lib/authlyx"

With Bundler, point your Gemfile at the folder instead and require "authlyx":

gem "authlyx", path: "authlyx"

Create the client

app = AuthlyX.new("YOUR_APP_KEY", "1.0.0")

The first value is your app’s AppKey. Find it in the dashboard under your application’s credentials. The second is the version of the program you are building. AuthlyX compares it with the versions you allow in the dashboard, so raise it each time you ship a new build. See Allowed Versions.

Create one client for the whole program and call app.close when it exits.

Two ways to call the SDK

Plain calls

Without a block, a call waits for the reply and returns a Result. init always returns one, even without internet. Other calls raise AuthlyX::Error when AuthlyX refuses or cannot be reached:

begin
app.login("YOUR_LICENSE_KEY")
puts "Signed in"
rescue AuthlyX::Error => error
puts "#{error.code}: #{error.message}"
end

Blocks

With a block, the call runs on its own thread and the block receives the Result. A failure arrives as a failed Result instead of an exception:

app.login("YOUR_LICENSE_KEY") do |result|
puts result.ok? ? "Signed in" : result.message
end

Use blocks in a GUI so the window keeps responding. Calls are processed one at a time, so you can make them from any thread.

Start the SDK

started = app.init
unless started.ok?
puts started.message
exit 1
end
puts started.message if started.code == "OFFLINE_MODE"

init connects to AuthlyX, checks that this version is allowed and loads your app’s settings. It must succeed before anything else.

CodeSuccessMeaning
APP_INITIALIZEDYesConnected. Continue to sign-in.
OFFLINE_MODEYesNo internet, but this PC has saved offline access.
NETWORK_...NoNo internet and nothing saved. Offer to try again.
UPDATE_REQUIREDNoThis version is older than the one set in your dashboard.
VERSION_MISMATCHNoThis version is newer than the dashboard version and is not allowed.

Sign in

app.login("YOUR_LICENSE_KEY")
app.login("YOUR_USERNAME", "YOUR_PASSWORD")
app.device_login

These are three ways to sign in. Use the one that matches the access type you created in the dashboard. license_login is the same as login with one value. Device login signs in the current Windows user with no form, and only works for devices you approved first; see Device login.

Create an account, change the password, add time

app.register_user("YOUR_USERNAME", "YOUR_PASSWORD", "YOUR_LICENSE_KEY")
app.change_password("CURRENT_PASSWORD", "NEW_PASSWORD")
app.redeem_license("NEW_LICENSE_KEY")

register_user creates the account with a license and signs it in. redeem_license adds a license’s time to the signed-in account.

Read the account

username = app.user_data.Username
plan = app.user_data["Plan"]
expiry = app.user_data["ExpiryDate"]
features = app.user_data["features"]
video_quality = app.user_data["featureValues"]["videoQuality"]

Read fields by name or with []. user_data is empty until someone signs in, and user_data.to_h returns every field. userData is the same method. The fields are listed in User Data.

Features and metadata

Features come from the plan and the account. Some are on/off, some carry a value such as "high" or 90. Metadata is extra information attached to accounts. See Features and metadata.

enable_export if Array(app.user_data["features"]).include?("exportPdf")
check = app.check_feature("exportPdf")
p check.data

get_features lists every feature and get_feature returns one. For metadata, use get_all_metadata, get_metadata and check_metadata.

Save metadata

app.set_metadata("display_name", "Alex")
app.set_metadata("launch_count", 12)

The value can be text, a number, a boolean, an array or a hash.

Cloud variables

url = app.get_variable("download_url").data
app.update_variable("maintenance", "false")

For get_variable, data is the value itself. See Cloud variables.

Scripts

script = app.get_script("welcome_message")
revision = app.get_script("welcome_message", 3)

The second value is an optional revision. The SDK checks the script’s signature before returning it. It does not run the script. See Scripts.

Logs and webhooks

app.log("User opened settings")
app.send_webhook("setup.completed", { "step" => 3 })

See Logs and Webhooks.

Staying signed in

After sign-in the SDK checks in with AuthlyX on a background thread (a heartbeat) at the interval the server sets, and refreshes features and metadata each time. If you ban, pause or expire the account, the next heartbeat ends the session.

show_login_screen unless app.access?

To be told when the session ends or the connection changes, pass procs when you create the client:

app = AuthlyX.new(
"YOUR_APP_KEY", "1.0.0",
on_session_invalidated: ->(error) { puts "Signed out: #{error.message}" },
on_connection: ->(state) { puts "Connection: #{state}" }
)

on_connection receives online, disconnected, untrusted or disposed. Both can run on the background thread, so keep them short. To check right away, call app.check_session; app.on_resume does the same and is meant for when your app wakes from sleep. To run the heartbeat yourself, pass heartbeat: :manual and call check_session from your own timer. More in Sessions and heartbeats.

Offline access

app.login(license_key)
app.save_offline_access

Later, without internet, init succeeds with OFFLINE_MODE, and the user signs in with the same license key or username and password. The SDK checks them against the saved permit and the sign-in succeeds with the code OFFLINE_ACCESS. app.offline_access? tells you whether this PC has a valid saved permit. Signing out deletes it. See Offline access.

Updates

When this version is not allowed, init fails with UPDATE_REQUIRED or VERSION_MISMATCH and the SDK shows a Windows message box with the new version, release notes and a button to open your download page. To show your own window, pass update_prompt: false and read the details:

started = app.init
if %w[UPDATE_REQUIRED VERSION_MISMATCH].include?(started.code)
update = (started.data || {})["update"] || {}
puts started.message, update["version"], update["url"], update["notes"]
end

See Automatic updates.

Sign out and shut down

app.logout
app.close

logout ends the session, clears user_data and deletes saved offline access on this PC. close stops the background work; call it when your program exits. A closed client cannot be used again.

Results and errors

MemberMeaning
result.ok?, result.success?Whether the call succeeded
result.codeA stable code such as APP_INITIALIZED
result.messageA message you can show to the user
result.dataThe response data as hashes and values
result.request_idThe server request ID, for support

AuthlyX::Error has code, message, kind, status, request_id and data. kind is server, network, security or storage. network means the SDK could not reach AuthlyX or confirm the answer; do not treat it as a ban. All codes are listed in Errors.

Options

Options are keyword arguments. Every option is optional on Windows.

OptionDefaultMeaning
system_idWindows user SIDRequired on Linux and macOS
storageAuthlyX::WindowsProtectedStoreWhere the installation key and offline access are saved. Required on Linux and macOS.
request_timeout8.0Seconds allowed for each call, including retries
retry_limit2Retries for temporary network and server errors, from 0 to 5
heartbeat:server:manual leaves session checks to you
update_prompttrueShows the Windows update box
ca_bundlenoneA CA bundle file for HTTPS, if your Ruby has none configured
on_connectionnoneCalled with the connection state
on_session_invalidatednoneCalled with the AuthlyX::Error that ended the session

On Linux, for example:

app = AuthlyX.new(
"YOUR_APP_KEY", "1.0.0",
system_id: File.read("/etc/machine-id").strip,
storage: AuthlyX::FileStore.new("/var/lib/your-app/authlyx")
)

FileStore writes files readable only by the current user. MemoryStore keeps nothing after the process ends. You can also pass any object with load, save and delete methods.

A complete program

require_relative "authlyx/lib/authlyx"
app = AuthlyX.new("YOUR_APP_KEY", "1.0.0")
started = app.init
unless started.ok?
puts started.message
exit 1
end
print "License key: "
license_key = $stdin.gets.to_s.strip
begin
app.login(license_key)
puts "Signed in. Plan: #{app.user_data['Plan']}"
app.logout
rescue AuthlyX::Error => error
puts error.message
exit 1
ensure
app.close
end

The example on GitHub is a fuller console app with a menu for every feature. Each method also has its own page with every language side by side under SDK methods.