Bandiera::Client (Ruby)

This is a client for talking to the Bandiera feature flagging service from a Ruby application.

This client is compatible with the v2 Bandiera API.

Gem version Build status Dependencies MIT licensed

Ruby Support:

This client has been tested against the latest MRI and JRuby builds.

Usage

Add the following to your Gemfile:

gem 'bandiera-client'

Then interact with a Bandiera server like so:

require 'bandiera/client'

client = Bandiera::Client.new('http://bandiera-demo.herokuapp.com')
params = {}

if client.enabled?('pubserv', 'show-new-search', params)
  # show the new experimental search function
end

The client.enabled? command takes two main arguments - the 'feature group', and the 'feature name'. This is because in Bandiera, features are organised into groups as it is intented as a service for multiple applications to use at the same time - this organisation allows separation of feature flags that are intended for different audiences.

client.enabled? also takes an optional params hash, this is for use with some of the more advanced features in Bandiera - user group and percentage based flags. It is in this params hash you pass in your user_group and user_id, i.e.:

client.enabled?('pubserv', 'show-new-search',
  { user_id: '1234567', user_group: 'Administrators' })

For more information on these advanced features, please see the Bandiera wiki:

https://github.com/springernature/bandiera/wiki/How-Feature-Flags-Work#feature-flags-in-bandiera

Performance

Using the client.enabled? method all over your codebase isn't the most efficient way of working with Bandiera as every time you call enabled? you will make a HTTP request to the Bandiera server.

One way of working more efficiently is using the Direct API Access methods, to fetch all the feature flags for a given group (or even all of the feature flags in the Bandiera server) in one request. You can then hold these as you please in your application and call on the values when needed.

Another approach is to use the Bandiera::Middleware class supplied in this gem. This can be used in conjunction with other middlewares for identifying your currently logged in user and assigning them a UUID to enable all of the most advanced features in Bandiera very simply.

See the blog post on cruft.io for more information on how Bandiera::Client is used at Nature.

# Direct API Access

If you'd prefer not to use the enabled? method for featching feature flag values, the following methods are available...

Get features for all groups:

client.get_all(params)
  # gives:
  # {
  #   'group1' => {
  #     'feature1' => true,
  #     'feature2' => false
  #   },
  #   'group2' => {
  #     'feature1' => false
  #   },
  # }

Get features for a group:

client.get_features_for_group('pubserv', params)
  # gives:
  # {
  #   'feature1' => true,
  #   'feature2' => false
  # }

Get an individual feature:

client.get_feature('pubserv', 'show-article-metrics', params)
  # gives: true/false

As with the enabled? method the params hash is for passing in your user_group and user_id values if you are using some of the more advanced features in Bandiera.

Development

  1. Fork this repo.
  2. Run bundle install

License

© 2014 Springer Nature. Bandiera::Client (Ruby) is licensed under the MIT License.