Class: Gxapi::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gxapi/base.rb

Constant Summary collapse

TIMEOUT =
2.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_key) ⇒ Base

the cache_key

Parameters:

  • user_key (String)

    identifier for our user - this is used in



11
12
13
14
# File 'lib/gxapi/base.rb', line 11

def initialize(user_key)
  @user_key = user_key
  @interface = GoogleAnalytics.new
end

Instance Attribute Details

#user_keyObject (readonly)

Returns the value of attribute user_key.



6
7
8
# File 'lib/gxapi/base.rb', line 6

def user_key
  @user_key
end

Instance Method Details

#envObject

get the Gxapi.env



17
18
19
# File 'lib/gxapi/base.rb', line 17

def env
  Gxapi.env
end

#get_experimentsArray<Ostruct>

get all experiments

Returns:



25
26
27
# File 'lib/gxapi/base.rb', line 25

def get_experiments
  @interface.get_experiments
end

#get_variant(experiment_name, override = nil) ⇒ Celluloid::Future

return a variant value

Examples:

variant = @gxapi.get_variant("my_experiment")
variant.value =>
  # Ostruct.new(experiment_id: "x", index: 1, name: "name")

Returns:

  • (Celluloid::Future)


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gxapi/base.rb', line 38

def get_variant(experiment_name, override = nil)
  Celluloid::Future.new do
    # allows us to override and get back a variant
    # easily that conforms to the api
    if override.nil?
      self.get_variant_value(experiment_name)
    else
      Ostruct.new(self.default_values.merge(name: override))
    end
  end
end

#reload_experimentsBoolean

reload the experiment cache from the remote

Returns:

  • (Boolean)

    true



54
55
56
57
# File 'lib/gxapi/base.rb', line 54

def reload_experiments
  @interface.reload_experiments
  true
end