class Itly::Plugin::Iteratively

Iteratively plugin class for Itly SDK

Automatically loaded at runtime in any new Itly object

Constants

VERSION

Attributes

api_key[R]
client[R]
disabled[R]
logger[R]
url[R]

Public Class Methods

new(api_key:, options:) click to toggle source

Instantiate a new Plugin::Iteratively

@param [String] api_key: specify the api key @param [Itly::Plugin::Iteratively::Options] options: options object. See Itly::Plugin::Iteratively::Options

Calls superclass method
# File lib/itly/plugin/iteratively/iteratively.rb, line 21
def initialize(api_key:, options:)
  super()
  @api_key = api_key
  @url = options.url
  @disabled = options.disabled

  @client_options = {
    flush_queue_size: options.flush_queue_size,
    batch_size: options.batch_size,
    flush_interval_ms: options.flush_interval_ms,
    max_retries: options.max_retries,
    retry_delay_min: options.retry_delay_min,
    retry_delay_max: options.retry_delay_max,
    omit_values: options.omit_values,
    branch: options.branch,
    version: options.version
  }
end

Public Instance Methods

flush() click to toggle source
# File lib/itly/plugin/iteratively/iteratively.rb, line 103
def flush
  @client.flush
end
id() click to toggle source

Get the plugin ID

@return [String] plugin id

# File lib/itly/plugin/iteratively/iteratively.rb, line 116
def id
  'iteratively'
end
load(options:) click to toggle source

Initialize IterativelyApi client

The plugin is automatically disabled in Production

@param [Itly::PluginOptions] options: plugin options

Calls superclass method
# File lib/itly/plugin/iteratively/iteratively.rb, line 47
def load(options:)
  super
  # Get options
  @logger = options.logger

  # Log
  logger&.info "#{id}: load()"

  # Disabled
  @disabled = options.environment == Itly::Options::Environment::PRODUCTION if @disabled.nil?

  if @disabled
    logger&.info "#{id}: plugin is disabled!"
    return
  end

  # Client
  @client_options.merge! url: @url, api_key: @api_key, logger: @logger
  @client = Itly::Plugin::Iteratively::Client.new(**@client_options)
end
post_group(user_id:, group_id:, properties:, validation_results:) click to toggle source
Calls superclass method
# File lib/itly/plugin/iteratively/iteratively.rb, line 79
def post_group(user_id:, group_id:, properties:, validation_results:)
  super
  return unless enabled?

  # Log
  log = Itly::Loggers.vars_to_log(
    user_id: user_id, group_id: group_id, properties: properties, validation_results: validation_results
  )
  logger&.info "#{id}: post_group(#{log})"

  client_track Itly::Plugin::Iteratively::TrackType::GROUP, properties, validation_results
end
post_identify(user_id:, properties:, validation_results:) click to toggle source
Calls superclass method
# File lib/itly/plugin/iteratively/iteratively.rb, line 68
def post_identify(user_id:, properties:, validation_results:)
  super
  return unless enabled?

  # Log
  log = Itly::Loggers.vars_to_log user_id: user_id, properties: properties, validation_results: validation_results
  logger&.info "#{id}: post_identify(#{log})"

  client_track Itly::Plugin::Iteratively::TrackType::IDENTIFY, properties, validation_results
end
post_track(user_id:, event:, validation_results:) click to toggle source
Calls superclass method
# File lib/itly/plugin/iteratively/iteratively.rb, line 92
def post_track(user_id:, event:, validation_results:)
  super
  return unless enabled?

  # Log
  log = Itly::Loggers.vars_to_log user_id: user_id, event: event, validation_results: validation_results
  logger&.info "#{id}: post_track(#{log})"

  client_track Itly::Plugin::Iteratively::TrackType::TRACK, event, validation_results
end
shutdown(force: false) click to toggle source
# File lib/itly/plugin/iteratively/iteratively.rb, line 107
def shutdown(force: false)
  @client.shutdown force: force
end

Private Instance Methods

client_track(type, event_or_properties, validations) click to toggle source
# File lib/itly/plugin/iteratively/iteratively.rb, line 126
def client_track(type, event_or_properties, validations)
  event = event_or_properties.is_a?(Itly::Event) ? event_or_properties : nil
  properties = event_or_properties.is_a?(Hash) ? event_or_properties : nil
  validation = (validations || []).reject(&:valid).first
  @client.track type: type, event: event, properties: properties, validation: validation
end
enabled?() click to toggle source
# File lib/itly/plugin/iteratively/iteratively.rb, line 122
def enabled?
  !@disabled
end