Class: Itly::Plugin::Iteratively

Inherits:
Itly::Plugin show all
Defined in:
lib/itly/plugin/iteratively/iteratively.rb,
lib/itly/plugin/iteratively/client.rb,
lib/itly/plugin/iteratively/options.rb,
lib/itly/plugin/iteratively/version.rb,
lib/itly/plugin/iteratively/track_type.rb,
lib/itly/plugin/iteratively/track_model.rb

Overview

Iteratively plugin class for Itly SDK

Automatically loaded at runtime in any new Itly object

Defined Under Namespace

Modules: TrackType Classes: Client, Options, TrackModel

Constant Summary collapse

VERSION =
'0.1.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key:, options:) ⇒ Iteratively

Instantiate a new Plugin::Iteratively

Parameters:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



13
14
15
# File 'lib/itly/plugin/iteratively/iteratively.rb', line 13

def api_key
  @api_key
end

#clientObject (readonly)

Returns the value of attribute client.



13
14
15
# File 'lib/itly/plugin/iteratively/iteratively.rb', line 13

def client
  @client
end

#disabledObject (readonly)

Returns the value of attribute disabled.



13
14
15
# File 'lib/itly/plugin/iteratively/iteratively.rb', line 13

def disabled
  @disabled
end

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/itly/plugin/iteratively/iteratively.rb', line 13

def logger
  @logger
end

#urlObject (readonly)

Returns the value of attribute url.



13
14
15
# File 'lib/itly/plugin/iteratively/iteratively.rb', line 13

def url
  @url
end

Instance Method Details

#flushObject



103
104
105
# File 'lib/itly/plugin/iteratively/iteratively.rb', line 103

def flush
  @client.flush
end

#idString

Get the plugin ID

Returns:

  • (String)

    plugin id



116
117
118
# File 'lib/itly/plugin/iteratively/iteratively.rb', line 116

def id
  'iteratively'
end

#load(options:) ⇒ Object

Initialize IterativelyApi client

The plugin is automatically disabled in Production

Parameters:

  • options: (Itly::PluginOptions)

    plugin options



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# 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:) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
# 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:) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# 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:) ⇒ Object



92
93
94
95
96
97
98
99
100
101
# 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) ⇒ Object



107
108
109
# File 'lib/itly/plugin/iteratively/iteratively.rb', line 107

def shutdown(force: false)
  @client.shutdown force: force
end