Skip to content

Commit

Permalink
remove deprecated code (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
kp-cat committed Jun 5, 2023
1 parent af91eb9 commit f463e76
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 292 deletions.
160 changes: 0 additions & 160 deletions lib/configcat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,164 +24,4 @@ def ConfigCat.get(sdk_key, options = nil)
def ConfigCat.close_all
ConfigCatClient.close_all
end

def ConfigCat.create_client(sdk_key, data_governance: DataGovernance::GLOBAL)
#
# Create an instance of ConfigCatClient and setup Auto Poll mode with default options
#
# :param sdk_key: ConfigCat SDK Key to access your configuration.
# :param data_governance:
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
# https://app.configcat.com/organization/data-governance
# (Only Organization Admins have access)
#
return create_client_with_auto_poll(sdk_key, data_governance: data_governance)
end

# Create an instance of ConfigCatClient and setup Auto Poll mode with custom options
#
# :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.
# :param config_cache: If you want to use custom caching instead of the client's default,
# 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
# :param proxy_address: Proxy address
# :param proxy_port: Proxy port
# :param proxy_user: username for proxy authentication
# :param proxy_pass: password for proxy authentication
# :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
# :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
# :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
# :param data_governance:
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
# https://app.configcat.com/organization/data-governance
# (Only Organization Admins have access)
def ConfigCat.create_client_with_auto_poll(sdk_key,
poll_interval_seconds: 60,
max_init_wait_time_seconds: 5,
on_configuration_changed_callback: nil,
config_cache: nil,
base_url: nil,
proxy_address: nil,
proxy_port: nil,
proxy_user: nil,
proxy_pass: nil,
open_timeout_seconds: 10,
read_timeout_seconds: 30,
flag_overrides: nil,
data_governance: DataGovernance::GLOBAL)
options = ConfigCatOptions.new(
base_url: base_url,
polling_mode: PollingMode.auto_poll(poll_interval_seconds: poll_interval_seconds, max_init_wait_time_seconds: max_init_wait_time_seconds),
config_cache: config_cache,
proxy_address: proxy_address,
proxy_port: proxy_port,
proxy_user: proxy_user,
proxy_pass: proxy_pass,
open_timeout_seconds: open_timeout_seconds,
read_timeout_seconds: read_timeout_seconds,
flag_overrides: flag_overrides,
data_governance: data_governance
)
ConfigCat.logger.warn('create_client_with_auto_poll is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
client = ConfigCatClient.get(sdk_key, options)
client.hooks.add_on_config_changed(on_configuration_changed_callback) if on_configuration_changed_callback
return client
end

# Create an instance of ConfigCatClient and setup Lazy Load mode with custom options
#
# :param sdk_key: ConfigCat SDK Key to access your configuration.
# :param cache_time_to_live_seconds: The cache TTL.
# :param config_cache: If you want to use custom caching instead of the client's default,
# 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
# :param proxy_address: Proxy address
# :param proxy_port: Proxy port
# :param proxy_user: username for proxy authentication
# :param proxy_pass: password for proxy authentication
# :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
# :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
# :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
# :param data_governance:
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
# https://app.configcat.com/organization/data-governance
# (Only Organization Admins have access)
def ConfigCat.create_client_with_lazy_load(sdk_key,
cache_time_to_live_seconds: 60,
config_cache: nil,
base_url: nil,
proxy_address: nil,
proxy_port: nil,
proxy_user: nil,
proxy_pass: nil,
open_timeout_seconds: 10,
read_timeout_seconds: 30,
flag_overrides: nil,
data_governance: DataGovernance::GLOBAL)
options = ConfigCatOptions.new(
base_url: base_url,
polling_mode: PollingMode.lazy_load(cache_refresh_interval_seconds: cache_time_to_live_seconds),
config_cache: config_cache,
proxy_address: proxy_address,
proxy_port: proxy_port,
proxy_user: proxy_user,
proxy_pass: proxy_pass,
open_timeout_seconds: open_timeout_seconds,
read_timeout_seconds: read_timeout_seconds,
flag_overrides: flag_overrides,
data_governance: data_governance
)
ConfigCat.logger.warn('create_client_with_lazy_load is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
client = ConfigCatClient.get(sdk_key, options)
return client
end

# Create an instance of ConfigCatClient and setup Manual Poll mode with custom options
#
# :param sdk_key: ConfigCat SDK Key to access your configuration.
# :param config_cache: If you want to use custom caching instead of the client's default,
# 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
# :param proxy_address: Proxy address
# :param proxy_port: Proxy port
# :param proxy_user: username for proxy authentication
# :param proxy_pass: password for proxy authentication
# :param open_timeout_seconds: The number of seconds to wait for the server to make the initial connection. Default: 10 seconds.
# :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
# :param flag_overrides: A FlagOverrides implementation used to override feature flags & settings.
# :param data_governance:
# Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard:
# https://app.configcat.com/organization/data-governance
# (Only Organization Admins have access)
def ConfigCat.create_client_with_manual_poll(sdk_key,
config_cache: nil,
base_url: nil,
proxy_address: nil,
proxy_port: nil,
proxy_user: nil,
proxy_pass: nil,
open_timeout_seconds: 10,
read_timeout_seconds: 30,
flag_overrides: nil,
data_governance: DataGovernance::GLOBAL)
options = ConfigCatOptions.new(
base_url: base_url,
polling_mode: PollingMode.manual_poll(),
config_cache: config_cache,
proxy_address: proxy_address,
proxy_port: proxy_port,
proxy_user: proxy_user,
proxy_pass: proxy_pass,
open_timeout_seconds: open_timeout_seconds,
read_timeout_seconds: read_timeout_seconds,
flag_overrides: flag_overrides,
data_governance: data_governance
)
ConfigCat.logger.warn('create_client_with_manual_poll is deprecated. Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead')
client = ConfigCatClient.get(sdk_key, options)
return client
end
end
46 changes: 0 additions & 46 deletions lib/configcat/configcatclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,52 +145,6 @@ def get_all_keys
return settings.keys
end

# Gets the Variation ID (analytics) of a feature flag or setting based on it's key.
#
# :param key [String] the identifier of the feature flag or setting.
# :param default_variation_id in case of any failure, this value will be returned.
# :param user [User] the user object to identify the caller.
# :return the variation ID.
def get_variation_id(key, default_variation_id, user = nil)
ConfigCat.logger.warn("get_variation_id is deprecated and will be removed in a future major version. " \
"Please use [get_value_details] instead.")

settings, fetch_time = _get_settings()
if settings === nil
message = "Config JSON is not present when evaluating setting '#{key}'. Returning the `default_variation_id` parameter that you specified in your application: '#{default_variation_id}'."
@log.error(1000, message)
@hooks.invoke_on_flag_evaluated(EvaluationDetails.from_error(key, nil, error: message,
variation_id: default_variation_id))
return default_variation_id
end
details = _evaluate(key, user, nil, default_variation_id, settings, fetch_time)
return details.variation_id
end

# Gets the Variation IDs (analytics) of all feature flags or settings.
#
# :param user [User] the user object to identify the caller.
# :return list of variation IDs
def get_all_variation_ids(user = nil)
ConfigCat.logger.warn("get_all_variation_ids is deprecated and will be removed in a future major version. " \
"Please use [get_value_details] instead.")

settings, _ = _get_settings()
if settings === nil
@log.error(1000, "Config JSON is not present. Returning empty list.")
return []
end

variation_ids = []
for key in settings.keys
variation_id = get_variation_id(key, nil, user)
if !variation_id.equal?(nil)
variation_ids.push(variation_id)
end
end
return variation_ids
end

# Gets the key of a setting, and it's value identified by the given Variation ID (analytics)
#
# :param variation_id [String] variation ID
Expand Down
63 changes: 4 additions & 59 deletions spec/configcat/configcatclient_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,51 +211,6 @@ def details_by_key(all_details, key)
client.close
end

it "test_default_user_get_variation_id" do
client = ConfigCatClient.get('test', ConfigCatOptions.new(polling_mode: PollingMode.manual_poll,
config_cache: ConfigCacheMock.new))
user1 = User.new("test@test1.com")
user2 = User.new("test@test2.com")

client.set_default_user(user1)
expect(client.get_variation_id("testStringKey", "")).to eq("id1")
expect(client.get_variation_id("testStringKey", "", user2)).to eq("id2")

client.clear_default_user
expect(client.get_variation_id("testStringKey", "")).to eq("id")

client.close
end

it "test_default_user_get_all_variation_ids" do
client = ConfigCatClient.get('test', ConfigCatOptions.new(polling_mode: PollingMode.manual_poll,
config_cache: ConfigCacheMock.new))
user1 = User.new("test@test1.com")
user2 = User.new("test@test2.com")

client.set_default_user(user1)
result = client.get_all_variation_ids
expect(result.length).to eq(3)
expect(result).to include('id1')
expect(result).to include('fakeId1')
expect(result).to include('fakeId2')

result = client.get_all_variation_ids(user2)
expect(result.length).to eq(3)
expect(result).to include('id2')
expect(result).to include('fakeId1')
expect(result).to include('fakeId2')

client.clear_default_user
result = client.get_all_variation_ids
expect(result.length).to eq(3)
expect(result).to include('id')
expect(result).to include('fakeId1')
expect(result).to include('fakeId2')

client.close
end

it "test_online_offline" do
stub_request = WebMock.stub_request(:get, Regexp.new('https://.*')).to_return(status: 200, body: TEST_OBJECT_JSON, headers: {})

Expand Down Expand Up @@ -309,32 +264,22 @@ def details_by_key(all_details, key)
it "test_get_variation_id" do
client = ConfigCatClient.get("test", ConfigCatOptions.new(polling_mode: PollingMode.manual_poll,
config_cache: ConfigCacheMock.new))
expect(client.get_variation_id("key1", nil)).to eq "fakeId1"
expect(client.get_variation_id("key2", nil)).to eq "fakeId2"
expect(client.get_value_details("key1", nil).variation_id).to eq "fakeId1"
expect(client.get_value_details("key2", nil).variation_id).to eq "fakeId2"
client.close()
end

it "test_get_variation_id_not_found" do
client = ConfigCatClient.get("test", ConfigCatOptions.new(polling_mode: PollingMode.manual_poll,
config_cache: ConfigCacheMock.new))
expect(client.get_variation_id("nonexisting", "default_variation_id")).to eq "default_variation_id"
expect(client.get_value_details("nonexisting", "default_value").variation_id).to be_nil
client.close()
end

it "test_get_variation_id_empty_config" do
client = ConfigCatClient.get("test", ConfigCatOptions.new(polling_mode: PollingMode.manual_poll,
config_cache: ConfigCacheMock.new))
expect(client.get_variation_id("nonexisting", "default_variation_id")).to eq "default_variation_id"
client.close()
end

it "test_get_all_variation_ids" do
client = ConfigCatClient.get("test", ConfigCatOptions.new(polling_mode: PollingMode.manual_poll,
config_cache: ConfigCacheMock.new))
result = client.get_all_variation_ids()
expect(result.size).to eq 3
expect(result.include?("fakeId1")).to eq true
expect(result.include?("fakeId2")).to eq true
expect(client.get_value_details("nonexisting", "default_value").variation_id).to be_nil
client.close()
end

Expand Down
Loading

0 comments on commit f463e76

Please sign in to comment.