Skip to content

Commit

Permalink
#38 - feat: Add support for filtering toggles on project
Browse files Browse the repository at this point in the history
  • Loading branch information
rarruda committed Mar 12, 2021
1 parent 491420f commit e97b3e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -59,6 +59,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` |
Expand Down
10 changes: 7 additions & 3 deletions lib/unleash/configuration.rb
Expand Up @@ -8,6 +8,7 @@ class Configuration
:app_name,
:environment,
:instance_id,
:project_name,
:custom_http_headers,
:disable_client,
:disable_metrics,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions spec/unleash/configuration_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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/'
Expand Down

0 comments on commit e97b3e8

Please sign in to comment.