diff --git a/README.md b/README.md index 3970f6bc..0f1515f6 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ Argument | Description | Required? | Type | Default Value| `app_name` | Name of your program. | Y | String | N/A | `instance_id` | Identifier for the running instance of program. Important so you can trace back to where metrics are being collected from. **Highly recommended be be set.** | N | String | random UUID | `environment` | Environment the program is running on. Could be for example `prod` or `dev`. Not yet in use. | N | String | `default` | +`project_name` | Name of the project to retrieve features from. If not set, all feature flags will be retrieved. | N | String | nil | `refresh_interval` | How often the unleash client should check with the server for configuration changes. | N | Integer | 15 | `metrics_interval` | How often the unleash client should send metrics to server. | N | Integer | 10 | `disable_client` | Disables all communication with the Unleash server, effectively taking it *offline*. If set, `is_enabled?` will always answer with the `default_value` and configuration validation is skipped. Defeats the entire purpose of using unleash, but can be useful in when running tests. | N | Boolean | `false` | diff --git a/lib/unleash/configuration.rb b/lib/unleash/configuration.rb index ced7026c..d78e5f43 100644 --- a/lib/unleash/configuration.rb +++ b/lib/unleash/configuration.rb @@ -8,6 +8,7 @@ class Configuration :app_name, :environment, :instance_id, + :project_name, :custom_http_headers, :disable_client, :disable_metrics, @@ -52,15 +53,17 @@ def http_headers end def fetch_toggles_url - self.url + '/client/features' + project_param = (self.project_name.nil? ? "" : "?project=#{self.project_name}") + + "#{self.url}/client/features#{project_param}" end def client_metrics_url - self.url + '/client/metrics' + "#{self.url}/client/metrics" end def client_register_url - self.url + '/client/register' + "#{self.url}/client/register" end private @@ -76,6 +79,7 @@ def set_defaults self.environment = 'default' self.url = nil self.instance_id = SecureRandom.uuid + self.project_name = nil self.disable_client = false self.disable_metrics = false self.refresh_interval = 15 diff --git a/spec/unleash/configuration_spec.rb b/spec/unleash/configuration_spec.rb index f9edf473..d5387582 100644 --- a/spec/unleash/configuration_spec.rb +++ b/spec/unleash/configuration_spec.rb @@ -23,6 +23,7 @@ expect(config.retry_limit).to eq(1) expect(config.backup_file).to_not be_nil + expect(config.project_name).to be_nil expect{ config.validate! }.to raise_error(ArgumentError) end @@ -61,6 +62,11 @@ expect(config.client_register_url).to eq('https://testurl/api/client/register') end + it "should build the correct unleash features endpoint when project_name is used" do + config = Unleash::Configuration.new(url: 'https://testurl/api', app_name: 'test-app', project_name: 'test-project') + expect(config.fetch_toggles_url).to eq('https://testurl/api/client/features?project=test-project') + end + it "should allow hashes for custom_http_headers via yield" do Unleash.configure do |config| config.url = 'http://test-url/'