Class: FeatureFlagClient::Client
- Inherits:
-
Object
- Object
- FeatureFlagClient::Client
- Includes:
- Version
- Defined in:
- lib/feature_flag_client/client.rb
Overview
Api Client class to fetch the features
Constant Summary collapse
- CACHE_KEY =
'features'
- CACHE_TTL =
60
Constants included from Version
Class Method Summary collapse
Instance Method Summary collapse
- #api_session ⇒ Object
- #cache ⇒ Object
- #features(product_name) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #version ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
95 96 97 |
# File 'lib/feature_flag_client/client.rb', line 95 def initialize validate_config end |
Class Method Details
.api_session ⇒ Object
89 90 91 92 93 |
# File 'lib/feature_flag_client/client.rb', line 89 def self.api_session @api_session ||= Session.new(client_id: config.client_id, client_secret: config.client_secret) do |s| s.auth_service_url = config.auth_url end end |
.config ⇒ Object
81 82 83 |
# File 'lib/feature_flag_client/client.rb', line 81 def self.config @config ||= FeatureFlagClient::Configuration.new end |
.configure {|config| ... } ⇒ Object
85 86 87 |
# File 'lib/feature_flag_client/client.rb', line 85 def self.configure yield(config) if block_given? end |
Instance Method Details
#api_session ⇒ Object
120 121 122 |
# File 'lib/feature_flag_client/client.rb', line 120 def api_session config.api_session || self.class.api_session end |
#cache ⇒ Object
116 117 118 |
# File 'lib/feature_flag_client/client.rb', line 116 def cache @cache ||= MiniCache::Store.new end |
#features(product_name) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/feature_flag_client/client.rb', line 99 def features(product_name) if cache.get("#{CACHE_KEY}_#{product_name}").nil? url = "#{config.api_base_url}#{features_pathname}" response = Response.from_raw(perform_request_with_query(url, productName: product_name)) raise ClientError, response.error unless response.ok? cache.set("#{CACHE_KEY}_#{product_name}", FeatureCollection.new(response.parsed), expires_in: CACHE_TTL) end cache.get("#{CACHE_KEY}_#{product_name}") end |
#version ⇒ Object
112 113 114 |
# File 'lib/feature_flag_client/client.rb', line 112 def version VERSION end |