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 =
3600
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
76 77 78 |
# File 'lib/feature_flag_client/client.rb', line 76 def initialize validate_config end |
Class Method Details
.api_session ⇒ Object
70 71 72 73 74 |
# File 'lib/feature_flag_client/client.rb', line 70 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
62 63 64 |
# File 'lib/feature_flag_client/client.rb', line 62 def self.config @config ||= FeatureFlagClient::Configuration.new end |
.configure {|config| ... } ⇒ Object
66 67 68 |
# File 'lib/feature_flag_client/client.rb', line 66 def self.configure yield(config) if block_given? end |
Instance Method Details
#api_session ⇒ Object
101 102 103 |
# File 'lib/feature_flag_client/client.rb', line 101 def api_session config.api_session || self.class.api_session end |
#cache ⇒ Object
97 98 99 |
# File 'lib/feature_flag_client/client.rb', line 97 def cache @cache ||= MiniCache::Store.new end |
#features(product_name) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/feature_flag_client/client.rb', line 80 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}", response.parsed, expires_in: CACHE_TTL) end cache.get("#{CACHE_KEY}_#{product_name}") end |
#version ⇒ Object
93 94 95 |
# File 'lib/feature_flag_client/client.rb', line 93 def version VERSION end |