Class: Bandiera::Client
- Inherits:
-
Object
- Object
- Bandiera::Client
- Defined in:
- lib/bandiera/client.rb,
lib/bandiera/client/errors.rb,
lib/bandiera/client/version.rb
Overview
Client class for communicating with a Bandiera server.
Defined Under Namespace
Classes: Error, ResponseError, TimeoutError
Constant Summary collapse
- VERSION =
'3.1.0'.freeze
Instance Attribute Summary collapse
-
#client_name ⇒ String
The client name passed along with HTTP requests.
-
#logger ⇒ Logger
readonly
The logger object in use.
-
#timeout ⇒ Float
The HTTP timeout value (seconds) for requests.
Instance Method Summary collapse
-
#cache_strategy=(_) ⇒ Object
deprecated
Deprecated.
This functionality was deprecated/removed in 3.0.0
-
#get_all(params = {}, http_opts = {}) ⇒ Hash
Get the active/inactive state for all feature flags known on the Bandiera server.
-
#get_feature(group, feature, params = {}, http_opts = {}) ⇒ Boolean
(also: #enabled?)
Get the active/inactive state for a single feature flag.
-
#get_features_for_group(group, params = {}, http_opts = {}) ⇒ Hash
Get the active/inactive state for all feature flags in a group.
-
#initialize(base_uri = 'http://localhost', logger = Logger.new($stdout), client_name = nil) ⇒ Client
constructor
Builds a new instance of Bandiera::Client.
Constructor Details
#initialize(base_uri = 'http://localhost', logger = Logger.new($stdout), client_name = nil) ⇒ Client
Builds a new instance of Bandiera::Client
28 29 30 31 32 33 34 |
# File 'lib/bandiera/client.rb', line 28 def initialize(base_uri = 'http://localhost', logger = Logger.new($stdout), client_name = nil) @base_uri = base_uri @base_uri << '/api' unless @base_uri.match(/\/api$/) @logger = logger @timeout = 0.2 # 0.4s (0.2 + 0.2) default timeout @client_name = client_name end |
Instance Attribute Details
#client_name ⇒ String
The client name passed along with HTTP requests
15 16 17 |
# File 'lib/bandiera/client.rb', line 15 def client_name @client_name end |
#logger ⇒ Logger (readonly)
The logger object in use
15 16 17 |
# File 'lib/bandiera/client.rb', line 15 def logger @logger end |
#timeout ⇒ Float
The HTTP timeout value (seconds) for requests
15 16 17 |
# File 'lib/bandiera/client.rb', line 15 def timeout @timeout end |
Instance Method Details
#cache_strategy=(_) ⇒ Object
This functionality was deprecated/removed in 3.0.0
37 38 39 40 |
# File 'lib/bandiera/client.rb', line 37 def cache_strategy=(_) warn 'The caching features in Bandiera::Client have been removed as of v3.0.0, please consider using using ' \ 'the Bandiera::Middleware class shipped as part of the "bandiera-client" gem.' end |
#get_all(params = {}, http_opts = {}) ⇒ Hash
Get the active/inactive state for all feature flags known on the Bandiera server
93 94 95 96 97 98 99 100 101 |
# File 'lib/bandiera/client.rb', line 93 def get_all(params = {}, http_opts = {}) path = '/v2/all' default_response = {} error_msg_prefix = "[Bandiera::Client#get_all] '#{params}'" logger.debug("[Bandiera::Client#get_all] calling #{path} with params: #{params}") get_and_handle_exceptions(path, params, http_opts, default_response, error_msg_prefix) end |
#get_feature(group, feature, params = {}, http_opts = {}) ⇒ Boolean Also known as: enabled?
Get the active/inactive state for a single feature flag
53 54 55 56 57 58 59 60 61 |
# File 'lib/bandiera/client.rb', line 53 def get_feature(group, feature, params = {}, http_opts = {}) path = "/v2/groups/#{group}/features/#{feature}" default_response = false error_msg_prefix = "[Bandiera::Client#get_feature] '#{group} / #{feature} / #{params}'" logger.debug("[Bandiera::Client#get_feature] calling #{path} with params: #{params}") get_and_handle_exceptions(path, params, http_opts, default_response, error_msg_prefix) end |
#get_features_for_group(group, params = {}, http_opts = {}) ⇒ Hash
Get the active/inactive state for all feature flags in a group
75 76 77 78 79 80 81 82 83 |
# File 'lib/bandiera/client.rb', line 75 def get_features_for_group(group, params = {}, http_opts = {}) path = "/v2/groups/#{group}/features" default_response = {} error_msg_prefix = "[Bandiera::Client#get_features_for_group] '#{group} / #{params}'" logger.debug("[Bandiera::Client#get_features_for_group] calling #{path} with params: #{params}") get_and_handle_exceptions(path, params, http_opts, default_response, error_msg_prefix) end |