Class: Optimizely::OdpConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/optimizely/odp/odp_config.rb

Constant Summary collapse

ODP_CONFIG_STATE =
Helpers::Constants::ODP_CONFIG_STATE

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil, api_host = nil, segments_to_check = []) ⇒ OdpConfig

Contains configuration used for ODP integration.

Parameters:

  • api_host (defaults to: nil)
    • The host URL for the ODP audience segments API (optional).

  • api_key (defaults to: nil)
    • The public API key for the ODP account from which the audience segments will be fetched (optional).

  • segments_to_check (defaults to: [])
    • An array of all ODP segments used in the current datafile (associated with api_host/api_key).



30
31
32
33
34
35
36
# File 'lib/optimizely/odp/odp_config.rb', line 30

def initialize(api_key = nil, api_host = nil, segments_to_check = [])
  @api_key = api_key
  @api_host = api_host
  @segments_to_check = segments_to_check
  @mutex = Mutex.new
  @odp_state = @api_host.nil? || @api_key.nil? ? ODP_CONFIG_STATE[:UNDETERMINED] : ODP_CONFIG_STATE[:INTEGRATED]
end

Instance Method Details

#api_hostObject

Returns the api host for odp connections

Returns:

    • The api host.



66
67
68
# File 'lib/optimizely/odp/odp_config.rb', line 66

def api_host
  @mutex.synchronize { @api_host.clone }
end

#api_keyObject

Returns the api key for odp connections

Returns:

    • The api key.



74
75
76
# File 'lib/optimizely/odp/odp_config.rb', line 74

def api_key
  @mutex.synchronize { @api_key.clone }
end

#odp_stateObject

Returns the state of odp integration (UNDETERMINED, INTEGRATED, NOT_INTEGRATED)

Returns:

    • string



98
99
100
# File 'lib/optimizely/odp/odp_config.rb', line 98

def odp_state
  @mutex.synchronize { @odp_state }
end

#segments_to_checkObject

Returns An array of qualified segments for this user

Returns:

    • An array of segments names.



82
83
84
# File 'lib/optimizely/odp/odp_config.rb', line 82

def segments_to_check
  @mutex.synchronize { @segments_to_check.clone }
end

#segments_to_check=(segments_to_check) ⇒ Object

Replace qualified segments with provided segments

Parameters:

  • segments
    • An array of segment names



90
91
92
# File 'lib/optimizely/odp/odp_config.rb', line 90

def segments_to_check=(segments_to_check)
  @mutex.synchronize { @segments_to_check = segments_to_check.clone }
end

#update(api_key = nil, api_host = nil, segments_to_check = []) ⇒ Object

Replaces the existing configuration

Parameters:

  • api_host (defaults to: nil)
    • The host URL for the ODP audience segments API (optional).

  • api_key (defaults to: nil)
    • The public API key for the ODP account from which the audience segments will be fetched (optional).

  • segments_to_check (defaults to: [])
    • An array of all ODP segments used in the current datafile (associated with api_host/api_key).

Returns:

    • True if the provided values were different than the existing values.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/optimizely/odp/odp_config.rb', line 46

def update(api_key = nil, api_host = nil, segments_to_check = [])
  updated = false
  @mutex.synchronize do
    @odp_state = api_host.nil? || api_key.nil? ? ODP_CONFIG_STATE[:NOT_INTEGRATED] : ODP_CONFIG_STATE[:INTEGRATED]

    if @api_key != api_key || @api_host != api_host || @segments_to_check != segments_to_check
      @api_key = api_key
      @api_host = api_host
      @segments_to_check = segments_to_check
      updated = true
    end
  end

  updated
end