Skip to content

Commit

Permalink
Merge 99b91a5 into 2f98c9e
Browse files Browse the repository at this point in the history
  • Loading branch information
ConfigCat committed Apr 9, 2020
2 parents 2f98c9e + 99b91a5 commit 4f232be
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 63 deletions.
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -25,13 +25,13 @@ gem install configcat
require 'configcat'
```

### 3. Go to <a href="https://app.configcat.com/connect" target="_blank">Connect your application</a> tab to get your *API Key*:
![API-KEY](https://raw.githubusercontent.com/ConfigCat/ruby-sdk/master/media/readme01.png "API-KEY")
### 3. Go to <a href="https://app.configcat.com/sdkkey" target="_blank">Connect your application</a> tab to get your *SDK Key*:
![SDK-KEY](https://raw.githubusercontent.com/ConfigCat/ruby-sdk/master/media/readme01.png "SDK-KEY")

### 4. Create a *ConfigCat* client instance:

```ruby
configcat_client = ConfigCat.create_client("#YOUR-API-KEY#")
configcat_client = ConfigCat.create_client("#YOUR-SDK-KEY#")
```
> We strongly recommend using the *ConfigCat Client* as a Singleton object in your application.
Expand Down Expand Up @@ -71,8 +71,8 @@ end
## Polling Modes
The ConfigCat SDK supports 3 different polling mechanisms to acquire the setting values from ConfigCat. After latest setting values are downloaded, they are stored in the internal cache then all requests are served from there. Read more about Polling Modes and how to use them at [ConfigCat Docs](https://configcat.com/docs/sdk-reference/python/).

## Support
If you need help how to use this SDK feel free to to contact the ConfigCat Staff on https://configcat.com. We're happy to help.
## Need help?
https://configcat.com/support

## Contributing
Contributions are welcome.
Expand Down
36 changes: 18 additions & 18 deletions lib/configcat.rb
Expand Up @@ -10,16 +10,16 @@ class << self
attr_accessor :logger
end

def ConfigCat.create_client(api_key)
def ConfigCat.create_client(sdk_key)
#
# Create an instance of ConfigCatClient and setup Auto Poll mode with default options
#
# :param api_key: ConfigCat ApiKey to access your configuration.
# :param sdk_key: ConfigCat SDK Key to access your configuration.
#
return create_client_with_auto_poll(api_key)
return create_client_with_auto_poll(sdk_key)
end

def ConfigCat.create_client_with_auto_poll(api_key,
def ConfigCat.create_client_with_auto_poll(sdk_key,
poll_interval_seconds: 60,
max_init_wait_time_seconds: 5,
on_configuration_changed_callback: nil,
Expand All @@ -32,7 +32,7 @@ def ConfigCat.create_client_with_auto_poll(api_key,
#
# Create an instance of ConfigCatClient and setup Auto Poll mode with custom options
#
# :param api_key: ConfigCat ApiKey to access your configuration.
# :param sdk_key: ConfigCat SDK Key to access your configuration.
# :param poll_interval_seconds: The client's poll interval in seconds. Default: 60 seconds.
# :param on_configuration_changed_callback: You can subscribe to configuration changes with this callback
# :param max_init_wait_time_seconds: maximum waiting time for first configuration fetch in polling mode.
Expand All @@ -44,16 +44,16 @@ def ConfigCat.create_client_with_auto_poll(api_key,
# :param proxy_user: username for proxy authentication
# :param proxy_pass: password for proxy authentication
#
if api_key === nil
raise ConfigCatClientException, "API Key is required."
if sdk_key === nil
raise ConfigCatClientException, "SDK Key is required."
end
if poll_interval_seconds < 1
poll_interval_seconds = 1
end
if max_init_wait_time_seconds < 0
max_init_wait_time_seconds = 0
end
return ConfigCatClient.new(api_key,
return ConfigCatClient.new(sdk_key,
poll_interval_seconds: poll_interval_seconds,
max_init_wait_time_seconds: max_init_wait_time_seconds,
on_configuration_changed_callback: on_configuration_changed_callback,
Expand All @@ -66,7 +66,7 @@ def ConfigCat.create_client_with_auto_poll(api_key,
proxy_pass: proxy_pass)
end

def ConfigCat.create_client_with_lazy_load(api_key,
def ConfigCat.create_client_with_lazy_load(sdk_key,
cache_time_to_live_seconds: 60,
config_cache_class: nil,
base_url: nil,
Expand All @@ -77,7 +77,7 @@ def ConfigCat.create_client_with_lazy_load(api_key,
#
# Create an instance of ConfigCatClient and setup Lazy Load mode with custom options
#
# :param api_key: ConfigCat ApiKey to access your configuration.
# :param sdk_key: ConfigCat SDK Key to access your configuration.
# :param cache_time_to_live_seconds: The cache TTL.
# :param config_cache_class: If you want to use custom caching instead of the client's default InMemoryConfigCache,
# You can provide an implementation of ConfigCache.
Expand All @@ -87,13 +87,13 @@ def ConfigCat.create_client_with_lazy_load(api_key,
# :param proxy_user: username for proxy authentication
# :param proxy_pass: password for proxy authentication
#
if api_key === nil
raise ConfigCatClientException, "API Key is required."
if sdk_key === nil
raise ConfigCatClientException, "SDK Key is required."
end
if cache_time_to_live_seconds < 1
cache_time_to_live_seconds = 1
end
return ConfigCatClient.new(api_key,
return ConfigCatClient.new(sdk_key,
poll_interval_seconds: 0,
max_init_wait_time_seconds: 0,
on_configuration_changed_callback: nil,
Expand All @@ -106,7 +106,7 @@ def ConfigCat.create_client_with_lazy_load(api_key,
proxy_pass: proxy_pass)
end

def ConfigCat.create_client_with_manual_poll(api_key,
def ConfigCat.create_client_with_manual_poll(sdk_key,
config_cache_class: nil,
base_url: nil,
proxy_address:nil,
Expand All @@ -116,7 +116,7 @@ def ConfigCat.create_client_with_manual_poll(api_key,
#
# Create an instance of ConfigCatClient and setup Manual Poll mode with custom options
#
# :param api_key: ConfigCat ApiKey to access your configuration.
# :param sdk_key: ConfigCat SDK Key to access your configuration.
# :param config_cache_class: If you want to use custom caching instead of the client's default InMemoryConfigCache,
# You can provide an implementation of ConfigCache.
# :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
Expand All @@ -125,10 +125,10 @@ def ConfigCat.create_client_with_manual_poll(api_key,
# :param proxy_user: username for proxy authentication
# :param proxy_pass: password for proxy authentication
#
if api_key === nil
raise ConfigCatClientException, "API Key is required."
if sdk_key === nil
raise ConfigCatClientException, "SDK Key is required."
end
return ConfigCatClient.new(api_key,
return ConfigCatClient.new(sdk_key,
poll_interval_seconds: 0,
max_init_wait_time_seconds: 0,
on_configuration_changed_callback: nil,
Expand Down
2 changes: 1 addition & 1 deletion lib/configcat/autopollingcachepolicy.rb
Expand Up @@ -81,7 +81,7 @@ def force_refresh()
@_initialized = true
end
rescue Exception => e
ConfigCat.logger.error("Double-check your API KEY at https://app.configcat.com/apikey.")
ConfigCat.logger.error("Double-check your SDK Key at https://app.configcat.com/sdkkey.")
ConfigCat.logger.error "threw exception #{e.class}:'#{e}'"
ConfigCat.logger.error "stacktrace: #{e.backtrace}"
end
Expand Down
14 changes: 7 additions & 7 deletions lib/configcat/configcatclient.rb
Expand Up @@ -8,7 +8,7 @@

module ConfigCat
class ConfigCatClient
def initialize(api_key,
def initialize(sdk_key,
poll_interval_seconds:60,
max_init_wait_time_seconds:5,
on_configuration_changed_callback:nil,
Expand All @@ -19,10 +19,10 @@ def initialize(api_key,
proxy_port:nil,
proxy_user:nil,
proxy_pass:nil)
if api_key === nil
raise ConfigCatClientException, "API Key is required."
if sdk_key === nil
raise ConfigCatClientException, "SDK Key is required."
end
@_api_key = api_key
@_sdk_key = sdk_key

if config_cache_class
@_config_cache = config_cache_class.new()
Expand All @@ -31,14 +31,14 @@ def initialize(api_key,
end

if poll_interval_seconds > 0
@_config_fetcher = CacheControlConfigFetcher.new(api_key, "p", base_url, proxy_address, proxy_port, proxy_user, proxy_pass)
@_config_fetcher = CacheControlConfigFetcher.new(sdk_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)
@_config_fetcher = CacheControlConfigFetcher.new(sdk_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)
@_config_fetcher = CacheControlConfigFetcher.new(sdk_key, "m", base_url, proxy_address, proxy_port, proxy_user, proxy_pass)
@_cache_policy = ManualPollingCachePolicy.new(@_config_fetcher, @_config_cache)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/configcat/configfetcher.rb
Expand Up @@ -32,8 +32,8 @@ def is_not_modified()
end

class CacheControlConfigFetcher < ConfigFetcher
def initialize(api_key, mode, base_url=nil, proxy_address=nil, proxy_port=nil, proxy_user=nil, proxy_pass=nil)
@_api_key = api_key
def initialize(sdk_key, mode, base_url=nil, proxy_address=nil, proxy_port=nil, proxy_user=nil, proxy_pass=nil)
@_sdk_key = sdk_key
@_etag = ""
@_headers = {"User-Agent" => ((("ConfigCat-Ruby/") + mode) + ("-")) + VERSION, "X-ConfigCat-UserAgent" => ((("ConfigCat-Ruby/") + mode) + ("-")) + VERSION, "Content-Type" => "application/json"}
if !base_url.equal?(nil)
Expand All @@ -51,7 +51,7 @@ def initialize(api_key, mode, base_url=nil, proxy_address=nil, proxy_port=nil, p
# Returns the FetchResponse object contains configuration json Dictionary
def get_configuration_json()
ConfigCat.logger.debug "Fetching configuration from ConfigCat"
uri = URI.parse((((@_base_url + ("/")) + BASE_PATH) + @_api_key) + BASE_EXTENSION)
uri = URI.parse((((@_base_url + ("/")) + BASE_PATH) + @_sdk_key) + BASE_EXTENSION)
headers = @_headers
headers["If-None-Match"] = @_etag unless @_etag.empty?
request = Net::HTTP::Get.new(uri.request_uri, headers)
Expand Down
2 changes: 1 addition & 1 deletion lib/configcat/lazyloadingcachepolicy.rb
Expand Up @@ -52,7 +52,7 @@ def force_refresh()
end
end
rescue StandardError => e
ConfigCat.logger.error("Double-check your API KEY at https://app.configcat.com/apikey.")
ConfigCat.logger.error("Double-check your SDK Key at https://app.configcat.com/sdkkey.")
ConfigCat.logger.error "threw exception #{e.class}:'#{e}'"
ConfigCat.logger.error "stacktrace: #{e.backtrace}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/configcat/manualpollingcachepolicy.rb
Expand Up @@ -32,7 +32,7 @@ def force_refresh()
end
end
rescue StandardError => e
ConfigCat.logger.error("Double-check your API KEY at https://app.configcat.com/apikey.")
ConfigCat.logger.error("Double-check your SDK Key at https://app.configcat.com/sdkkey.")
ConfigCat.logger.error "threw exception #{e.class}:'#{e}'"
ConfigCat.logger.error "stacktrace: #{e.backtrace}"
end
Expand Down
Binary file modified media/readme01.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion samples/consolesample.rb
@@ -1,6 +1,6 @@
require 'configcat'

# Initialize the ConfigCatClient with an API Key.
# Initialize the ConfigCatClient with an SDK Key.
client = ConfigCat.create_client("PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A")

# In the project there is a 'keySampleText' setting with the following rules:
Expand Down
2 changes: 1 addition & 1 deletion samples/consolesample2.rb
@@ -1,6 +1,6 @@
require 'configcat'

# Initializing the ConfigCatClient with an API Key.
# Initializing the ConfigCatClient with an SDK Key.
client = ConfigCat.create_client("PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ")

# Setting the log level to Info to show detailed feature flag evaluation.
Expand Down
2 changes: 1 addition & 1 deletion spec/configcat/configcatclient_spec.rb
Expand Up @@ -3,7 +3,7 @@
require_relative 'mocks'

RSpec.describe ConfigCat::ConfigCatClient do
it "test_without_api_key" do
it "test_without_sdk_key" do
expect {
ConfigCatClient.new(nil)
}.to raise_error(ConfigCatClientException)
Expand Down

0 comments on commit 4f232be

Please sign in to comment.