module Flagger

Constants

VERSION

Public Class Methods

get_payload(codename, *entity) click to toggle source

Returns the payload associated with the treatment assigned to the entity

# File lib/flagger.rb, line 85
def Flagger.get_payload(codename, *entity)
  request = entity.empty? ? "{\"codename\": \"#{codename}\"}" : "{\"codename\": \"#{codename}\", \"entity\":#{entity[0].to_json}}"
  ResponseParser::parse_error FlaggerNative::FlagGetPayload(request)
end
get_variation(codename, *entity) click to toggle source

Returns the variation assigned to the entity in a multivariate flag

# File lib/flagger.rb, line 79
def Flagger.get_variation(codename, *entity)
  request = entity.empty? ? "{\"codename\": \"#{codename}\"}" : "{\"codename\": \"#{codename}\", \"entity\":#{entity[0].to_json}}"
  ResponseParser::parse_error FlaggerNative::FlagGetVariation(request)
end
init(*args) click to toggle source

init method gets FlaggerConfiguration, establishes and maintains SSE connections and initializes Ingester init must be called only once, at the start of your application. Your program must wait for init to finish before using any other Flagger methods

# File lib/flagger.rb, line 13
def Flagger.init(*args)
    case args.size
      when 1
          request = {
              apiKey: args[0][:api_key],
              sdkName: "ruby",
              sdkVersion: Flagger::VERSION,
              sourceURL: args[0][:source_url],
              backupSourceURL: args[0][:backup_source_url],
              sseURL: args[0][:sse_url],
              ingestionURL: args[0][:ingestion_url],
              logLevel: args[0][:log_level],
          }.compact.to_json
          ResponseParser::parse_error(FlaggerNative::Init(request))
      when 2
          request = {
                  apiKey: args[0],
                  sdkName: "ruby",
                  sdkVersion: Flagger::VERSION,
                  sourceURL: args[1][:source_url],
                  backupSourceURL: args[1][:backup_source_url],
                  sseURL: args[1][:sse_url],
                  ingestionURL: args[1][:ingestion_url],
                  logLevel: args[1][:log_level],
              }.compact.to_json
          ResponseParser::parse_error(FlaggerNative::Init(request))
    else
      raise "Invalid number of arguments, expected 1 or 2"
    end
end
is_enabled(codename, *entity) click to toggle source

Determines if flag is enabled for entity.

# File lib/flagger.rb, line 67
def Flagger.is_enabled(codename, *entity)
  request = entity.empty? ? "{\"codename\": \"#{codename}\"}" : "{\"codename\": \"#{codename}\", \"entity\":#{entity[0].to_json}}"
  ResponseParser::parse_error FlaggerNative::FlagIsEnabled(request)
end
is_sampled(codename, *entity) click to toggle source

Determines if entity is within the targeted subpopulations

# File lib/flagger.rb, line 73
def Flagger.is_sampled(codename, *entity)
  request = entity.empty? ? "{\"codename\": \"#{codename}\"}" : "{\"codename\": \"#{codename}\", \"entity\":#{entity[0].to_json}}"
  ResponseParser::parse_error FlaggerNative::FlagIsSampled(request)
end
publish(entity) click to toggle source

Explicitly notify Airship about an Entity

# File lib/flagger.rb, line 45
def Flagger.publish(entity)
  request = "{\"entity\": #{entity.to_json} }"
  ResponseParser::parse_error(FlaggerNative::Publish(request))
end
set_entity(entity) click to toggle source

set_entity stores an entity in Flagger, which allows omission of entity in other API methods.

If you don't provide any entity to Flagger:

  • flag functions always resolve with the default variation

  • track method doesn't record an event

# File lib/flagger.rb, line 62
def Flagger.set_entity(entity)
  ResponseParser::parse_error(FlaggerNative::SetEntity("{\"entity\":#{entity.to_json}}"))
end
shutdown(timeout) click to toggle source

shutdown ingests data(if any), stop ingester and closes SSE connection. shutdown waits to finish current ingestion request, but no longer than a timeoutMillis. returns true if closed by timeout

# File lib/flagger.rb, line 93
def Flagger.shutdown(timeout)
  request = "{\"timeout\": #{timeout}}"
  ResponseParser::parse_error FlaggerNative::Shutdown(request)
end
track(name, event_properties, *entity) click to toggle source

Simple event tracking API. Entity is an optional parameter if it was set before.

# File lib/flagger.rb, line 51
def Flagger.track(name, event_properties, *entity)
  request = entity.empty? ? "{\"event\":{\"name\":\"#{name}\", \"eventProperties\": #{event_properties.to_json}}"
                : "{\"event\":{\"name\":\"#{name}\", \"eventProperties\": #{event_properties.to_json}, \"entity\":#{entity[0].to_json}}}"
  ResponseParser::parse_error(FlaggerNative::Track(request))
end