Class: ConfigCat::ConfigCatClient

Inherits:
Object
  • Object
show all
Defined in:
lib/configcat/configcatclient.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key, poll_interval_seconds: 60, max_init_wait_time_seconds: 5, on_configuration_changed_callback: nil, cache_time_to_live_seconds: 60, config_cache_class: nil, base_url: nil, proxy_address: nil, proxy_port: nil, proxy_user: nil, proxy_pass: nil) ⇒ ConfigCatClient

Returns a new instance of ConfigCatClient.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/configcat/configcatclient.rb', line 11

def initialize(api_key,
               poll_interval_seconds:60,
               max_init_wait_time_seconds:5,
               on_configuration_changed_callback:nil,
               cache_time_to_live_seconds:60,
               config_cache_class:nil,
               base_url:nil,
               proxy_address:nil,
               proxy_port:nil,
               proxy_user:nil,
               proxy_pass:nil)
  if api_key === nil
    raise ConfigCatClientException, "API Key is required."
  end
  @_api_key = api_key

  if config_cache_class
    @_config_cache = config_cache_class.new()
  else
    @_config_cache = InMemoryConfigCache.new()
  end

  if poll_interval_seconds > 0
    @_config_fetcher = CacheControlConfigFetcher.new(api_key, "p", base_url, proxy_address, proxy_port, proxy_user, proxy_pass)
    @_cache_policy = AutoPollingCachePolicy.new(@_config_fetcher, @_config_cache, poll_interval_seconds, max_init_wait_time_seconds, on_configuration_changed_callback)
  else
    if cache_time_to_live_seconds > 0
      @_config_fetcher = CacheControlConfigFetcher.new(api_key, "l", base_url, proxy_address, proxy_port, proxy_user, proxy_pass)
      @_cache_policy = LazyLoadingCachePolicy.new(@_config_fetcher, @_config_cache, cache_time_to_live_seconds)
    else
      @_config_fetcher = CacheControlConfigFetcher.new(api_key, "m", base_url, proxy_address, proxy_port, proxy_user, proxy_pass)
      @_cache_policy = ManualPollingCachePolicy.new(@_config_fetcher, @_config_cache)
    end
  end
end

Instance Method Details

#force_refreshObject



63
64
65
# File 'lib/configcat/configcatclient.rb', line 63

def force_refresh()
  @_cache_policy.force_refresh()
end

#get_all_keysObject



55
56
57
58
59
60
61
# File 'lib/configcat/configcatclient.rb', line 55

def get_all_keys()
  config = @_cache_policy.get()
  if config === nil
    return []
  end
  return config.keys
end

#get_value(key, default_value, user = nil) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/configcat/configcatclient.rb', line 47

def get_value(key, default_value, user=nil)
  config = @_cache_policy.get()
  if config === nil
    return default_value
  end
  return RolloutEvaluator.evaluate(key, user, default_value, config)
end

#stopObject



67
68
69
70
# File 'lib/configcat/configcatclient.rb', line 67

def stop()
  @_cache_policy.stop()
  @_config_fetcher.close()
end