Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add api token to getting started example #49

Merged
merged 2 commits into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 22 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,29 @@ Or install it yourself as:

## Configure

It is **required** to configure the `url` of the unleash server and `app_name` with the name of the runninng application. Please substitute the sample `'http://unleash.herokuapp.com/api'` for the url of your own instance.
It is **required** to configure:
- `url` of the unleash server
- `app_name` with the name of the runninng application.
- `custom_http_headers` with `{'Authorization': '<API token>'}` when using Unleash v4.0.0 and later.

It is **highly recommended** to configure the `instance_id` parameter as well.
Please substitute the example `'http://unleash.herokuapp.com/api'` for the url of your own instance.

It is **highly recommended** to configure:
- `instance_id` parameter with a unique identifier for the running instance.


```ruby
Unleash.configure do |config|
config.url = 'http://unleash.herokuapp.com/api'
config.app_name = 'my_ruby_app'
config.app_name = 'my_ruby_app'
config.url = 'http://unleash.herokuapp.com/api'
config.custom_http_headers = {'Authorization': '<API token>'}
end
```

or instantiate the client with the valid configuration:

```ruby
UNLEASH = Unleash::Client.new(url: 'http://unleash.herokuapp.com/api', app_name: 'my_ruby_app')
UNLEASH = Unleash::Client.new(url: 'http://unleash.herokuapp.com/api', app_name: 'my_ruby_app', custom_http_headers: {'Authorization': '<API token>'})
```

#### List of Arguments
Expand All @@ -65,7 +72,7 @@ Argument | Description | Required? | Type | Default Value|
`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` |
`disable_metrics` | Disables sending metrics to Unleash server. | N | Boolean | `false` |
`custom_http_headers` | Custom headers to send to Unleash. | N | Hash | {} |
`custom_http_headers` | Custom headers to send to Unleash. As of Unleash v4.0.0, the `Authorization` header is required. For example: `{'Authorization': '<API token>'}` | N | Hash | {} |
`timeout` | How long to wait for the connection to be established or wait in reading state (open_timeout/read_timeout) | N | Integer | 30 |
`retry_limit` | How many consecutive failures in connecting to the Unleash server are allowed before giving up. Use `Float::INFINITY` if you would like it to never give up. | N | Numeric | 5 |
`backup_file` | Filename to store the last known state from the Unleash server. Best to not change this from the default. | N | String | `Dir.tmpdir + "/unleash-#{app_name}-repo.json` |
Expand All @@ -81,7 +88,7 @@ For in a more in depth look, please see `lib/unleash/configuration.rb`.
require 'unleash'
require 'unleash/context'

@unleash = Unleash::Client.new(url: 'http://unleash.herokuapp.com/api', app_name: 'my_ruby_app')
@unleash = Unleash::Client.new(app_name: 'my_ruby_app', url: 'http://unleash.herokuapp.com/api', custom_http_headers: {'Authorization': '<API token>'})

feature_name = "AwesomeFeature"
unleash_context = Unleash::Context.new
Expand All @@ -102,8 +109,8 @@ Put in `config/initializers/unleash.rb`:

```ruby
Unleash.configure do |config|
config.url = 'http://unleash.herokuapp.com/api'
config.app_name = Rails.application.class.parent.to_s
config.url = 'http://unleash.herokuapp.com/api'
# config.instance_id = "#{Socket.gethostname}"
config.logger = Rails.logger
config.environment = Rails.env
Expand All @@ -123,9 +130,10 @@ on_worker_boot do
# ...

Unleash.configure do |config|
config.url = 'http://unleash.herokuapp.com/api'
config.app_name = Rails.application.class.parent.to_s
config.app_name = Rails.application.class.parent.to_s
config.environment = Rails.env
config.url = 'http://unleash.herokuapp.com/api'
config.custom_http_headers = {'Authorization': '<API token>'}
end
Rails.configuration.unleash = Unleash::Client.new
end
Expand All @@ -143,11 +151,12 @@ The initializer in `config/initializers/unleash.rb` should look like:
PhusionPassenger.on_event(:starting_worker_process) do |forked|
if forked
Unleash.configure do |config|
config.url = 'http://unleash.herokuapp.com/api'
config.app_name = Rails.application.class.parent.to_s
config.app_name = Rails.application.class.parent.to_s
# config.instance_id = "#{Socket.gethostname}"
config.logger = Rails.logger
config.logger = Rails.logger
config.environment = Rails.env
config.url = 'http://unleash.herokuapp.com/api'
config.custom_http_headers = {'Authorization': '<API token>'}
end

UNLEASH = Unleash::Client.new
Expand Down
4 changes: 3 additions & 1 deletion examples/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

# Unleash.configure do |config|
# config.url = 'http://unleash.herokuapp.com/api'
# config.custom_http_headers = {'Authorization': '943ca9171e2c884c545c5d82417a655fb77cec970cc3b78a8ff87f4406b495d0'}
# config.app_name = 'simple-test'
# config.refresh_interval = 2
# config.metrics_interval = 2
Expand All @@ -17,7 +18,8 @@
# or:

@unleash = Unleash::Client.new(
url: 'https://app.unleash-hosted.com/demo/api',
url: 'http://unleash.herokuapp.com/api',
custom_http_headers: {'Authorization': '943ca9171e2c884c545c5d82417a655fb77cec970cc3b78a8ff87f4406b495d0'},
app_name: 'simple-test',
instance_id: 'local-test-cli',
refresh_interval: 2,
Expand Down