Skip to main content

DevCycle Ruby Server SDK

Welcome to the the DevCycle Ruby SDK, initially generated via the DevCycle Bucketing API.

The SDK is available as a package on RubyGems. It is also open source and can be viewed on Github.

RubyGems GitHub

Installation

Install the gem

gem install devcycle-ruby-server-sdk

Getting Started

Please follow the installation procedure and then run the following code:

# Load the gem
require 'devcycle-server-sdk'

# Setup authorization
DevCycle.configure do |config|
# Configure API key authorization
config.api_key['bearerAuth'] = 'YOUR API KEY'
end

api_instance = DevCycle::DVCClient.new
user_data = DevCycle::UserData.new({user_id: 'user_id_example'}) # UserData |

begin
#Get all features for user data
result = api_instance.all_features(user_data)
p result
rescue DevCycle::ApiError => e
puts "Exception when calling DVCClient->all_features: #{e}"
end

Usage

Configure SDK

# Load the gem
require 'devcycle-server-sdk'

# Setup authorization
DevCycle.configure do |config|
# Configure API key authorization
config.api_key['bearerAuth'] = 'YOUR API KEY'
end

api_instance = DevCycle::DVCClient.new
user_data = DevCycle::UserData.new({user_id: 'user_id_example'}) # UserData |

Getting all Features

begin
#Get all features for user data
result = api_instance.all_features(user_data)
p result
rescue DevCycle::ApiError => e
puts "Exception when calling DVCClient->all_features: #{e}"
end

Get and use Variable by key

begin
# Get value of given variable by key, using default value if segmentation is not passed or variable does not exit
result = api_instance.variable("variable-key", user_data, true)
p "Received value for #{result.key}: #{result.value}"
rescue DevCycle::ApiError => e
puts "Exception when calling DVCClient->variable: #{e}"
end

Getting all Variables

begin
#Get all variables for user data
result = api_instance.all_variables(user_data)
p result
rescue DevCycle::ApiError => e
puts "Exception when calling DVCClient->all_variables: #{e}"
end

Track Events


event_data = DevCycle::Event.new({
type: "my-event",
target: "some_event_target",
value: 12,
meta_data: {
myKey: "my-value"
}
})

begin
# Post events for given user data
result = api_instance.track(user_data, event_data)
p result
rescue DevCycle::ApiError => e
puts "Exception when calling DVCClient->track: #{e}"
end

Override Logger

To provide a custom logger, override the logger property of the SDK configuration.

DevCycle.configure do |config|
# Configure API key authorization
config.api_key['bearerAuth'] = 'YOUR API KEY'

# Override the default logger
config.logger = MyLogger
end

Troubleshooting

To see a detailed log of the requests being made to the DevCycle API, enable SDK debug logging:

DevCycle.configure do |config|
# Configure API key authorization
config.api_key['bearerAuth'] = 'YOUR API KEY'

# Enable detailed debug logs of requests being sent to the DevCycle API
config.debugging = true
end

EdgeDB

EdgeDB allows you to save user data to our EdgeDB storage so that you don't have to pass in all the user data every time you identify a user. Read more about EdgeDB.

To get started, contact us at [email protected] to enable EdgeDB for your project.

Once you have EdgeDB enabled in your project, pass in the enableEdgeDB option to turn on EdgeDB mode for the SDK:

# Load the gem
require 'devcycle-server-sdk'

# Setup authorization
DevCycle.configure do |config|
# Configure API key authorization
config.api_key['bearerAuth'] = 'YOUR API KEY'
config.enable_edge_db = true
end

api_instance = DevCycle::DVCClient.new
user_data = DevCycle::UserData.new({
user_id: 'test_user',
email: '[email protected]',
country: 'CA'
})

This will send a request to our EdgeDB API to save the custom data under the user test_user.

In the example, Email and Country are associated to the user test_user. In your next identify call for the same user_id, you may omit any of the data you've sent already as it will be pulled from the EdgeDB storage when segmenting to experiments and features.

Documentation for Models

UserData

User data is provided to most SDK requests to identify the user / context of the feature evaluation

NameTypeDescriptionNotes
user_idStringUnique id to identify the user
emailStringUser's email used to identify the user on the dashboard / target audiences[optional]
nameStringUser's name used to identify the user on the dashboard / target audiences[optional]
languageStringUser's language in ISO 639-1 format[optional]
countryStringUser's country in ISO 3166 alpha-2 format[optional]
app_versionStringApp Version of the running application[optional]
app_buildStringApp Build number of the running application[optional]
custom_dataObjectUser's custom data to target the user with, data will be logged to DevCycle for use in dashboard.[optional]
private_custom_dataObjectUser's custom data to target the user with, data will not be logged to DevCycle only used for feature bucketing.[optional]
created_dateFloatDate the user was created, Unix epoch timestamp format[optional]
last_seen_dateFloatDate the user was created, Unix epoch timestamp format[optional]
platformStringPlatform the Client SDK is running on[optional]
platform_versionStringVersion of the platform the Client SDK is running on[optional]
device_modelStringUser's device model[optional]
sdk_typeStringDevCycle SDK type[optional]
sdk_versionStringDevCycle SDK Version[optional]

Event

Event data is provided to track calls to log events to DevCycle

NameTypeDescriptionNotes
typeStringCustom event type
targetStringCustom event target / subject of event. Contextual to event type[optional]
dateFloatUnix epoch time the event occurred according to client[optional]
valueFloatValue for numerical events. Contextual to event type[optional]
meta_dataObjectExtra JSON metadata for event. Contextual to event type[optional]

Variable

Variable objects are returned by the SDK when calling variable or all_variables.

NameTypeDescriptionNotes
_idStringunique database id
keyStringUnique key by Project, can be used in the SDK / API to reference by 'key' rather than _id.
typeStringVariable type
valueObjectVariable value can be a string, number, boolean, or JSON

Feature

Feature objects are returned by the SDK when calling all_features

NameTypeDescriptionNotes
_idStringunique database id
keyStringUnique key by Project, can be used in the SDK / API to reference by 'key' rather than _id.
typeStringFeature type
_variationStringBucketed feature variation
eval_reasonStringEvaluation reasoning[optional]

About this Package

This SDK is automatically generated by the OpenAPI Generator project:

  • API version: 1.0.0
  • Package version: 1.0.0
  • Build package: org.openapitools.codegen.languages.RubyClientCodegen