feature_flag_client 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/README.md +15 -7
- data/lib/feature_flag_client/client.rb +21 -2
- data/lib/feature_flag_client/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7065c7ae5de763c0b60757abd3acd69d954cfbcd061fc7111dc1eaa2528b07a7
|
4
|
+
data.tar.gz: 4bbf3c3ea64cfe1e0d930b7c8354b5e1d9d7d9bb14ac79f6d64976c7554e38d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f46c05adc2f1ab77e7346bdaafe93dcb9a45c24cd02776c8eba35271eb39aa2d60a0bf38ad98c813ff611c50d4a79c49881fe339145968959fcfc0d3cecbd31
|
7
|
+
data.tar.gz: bb6dca6a4596fd467c59738befcf6966cdc5b7665e0caee51139bf6dbe29197c7931aa3e8c3306ab9dda6c4bbc480cecd18d9bdbc3799f3682464c616d352fcc
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
feature_flag_client (0.
|
4
|
+
feature_flag_client (0.3.0)
|
5
5
|
httparty (~> 0.17.3)
|
6
6
|
mini_cache (~> 1.1)
|
7
7
|
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
multi_xml (>= 0.5.2)
|
20
20
|
mime-types (3.3.1)
|
21
21
|
mime-types-data (~> 3.2015)
|
22
|
-
mime-types-data (3.
|
22
|
+
mime-types-data (3.2020.1104)
|
23
23
|
mini_cache (1.1.0)
|
24
24
|
multi_xml (0.6.0)
|
25
25
|
parallel (1.19.2)
|
data/README.md
CHANGED
@@ -24,23 +24,31 @@ Or install it yourself as:
|
|
24
24
|
require 'feature_flag_client'
|
25
25
|
|
26
26
|
# In some initializer
|
27
|
-
FeatureFlagClient::
|
27
|
+
FeatureFlagClient::Client.configure do |config|
|
28
28
|
# Main resource API to get feature flags
|
29
|
-
config.api_base_url = 'https://api
|
29
|
+
config.api_base_url = 'https://yeahrnb59i.execute-api.eu-west-1.amazonaws.com/dev/api/v1'
|
30
30
|
|
31
31
|
# Featureflag service Auth api to get access token
|
32
|
-
config.auth_url = 'https://api
|
32
|
+
config.auth_url = 'https://yeahrnb59i.execute-api.eu-west-1.amazonaws.com/dev/auth/token'
|
33
33
|
|
34
34
|
# client id and secret to get access token
|
35
|
-
config.client_id = '
|
36
|
-
config.client_secret = '
|
35
|
+
config.client_id = 'xxxx'
|
36
|
+
config.client_secret = 'xxxxxxxxxxxxxxxxxxxx' # store this in a secret manager
|
37
37
|
end
|
38
38
|
|
39
39
|
# Elsewhere in the code
|
40
40
|
client = FeatureFlagClient.new
|
41
41
|
product_name = 'cool product'
|
42
|
-
client.features('cool product')
|
43
|
-
# => {"
|
42
|
+
features = client.features('cool product')
|
43
|
+
# => #<FeatureFlagClient::FeatureCollection:0x00007fb1981a32f8 @features={"qr-logo"=>#<OpenStruct name="qr-logo", enabled=true, createdAt="2020-12-15T14:07:50.274Z", updatedAt="2020-12-15T15:28:46.162Z">, "qr code 2"=>#<OpenStruct name="qr code 2", enabled=false, createdAt="2020-12-15T15:28:52.065Z", updatedAt="2020-12-15T15:28:52.066Z">}>
|
44
|
+
|
45
|
+
features.feature('qr-logo').enabled
|
46
|
+
# => true
|
47
|
+
|
48
|
+
# When looking for a non-existing feature
|
49
|
+
features.feature('non-existing')
|
50
|
+
# => nil
|
51
|
+
|
44
52
|
```
|
45
53
|
|
46
54
|
## Development
|
@@ -52,12 +52,31 @@ module FeatureFlagClient
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
class FeatureCollection
|
56
|
+
attr_reader :features
|
57
|
+
|
58
|
+
def initialize(_features)
|
59
|
+
p _features
|
60
|
+
@features = _features
|
61
|
+
end
|
62
|
+
|
63
|
+
def feature(name)
|
64
|
+
features[name]
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_json(*_args)
|
68
|
+
features.keys.each_with_object({}) do |feature_name, result|
|
69
|
+
result[feature_name] = feature(feature_name).marshal_dump
|
70
|
+
end.to_json
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
55
74
|
# Api Client class to fetch the features
|
56
75
|
class Client
|
57
76
|
include FeatureFlagClient::Version
|
58
77
|
|
59
78
|
CACHE_KEY = 'features'
|
60
|
-
CACHE_TTL =
|
79
|
+
CACHE_TTL = 60
|
61
80
|
|
62
81
|
def self.config
|
63
82
|
@config ||= FeatureFlagClient::Configuration.new
|
@@ -84,7 +103,7 @@ module FeatureFlagClient
|
|
84
103
|
|
85
104
|
raise ClientError, response.error unless response.ok?
|
86
105
|
|
87
|
-
cache.set("#{CACHE_KEY}_#{product_name}", response.parsed, expires_in: CACHE_TTL)
|
106
|
+
cache.set("#{CACHE_KEY}_#{product_name}", FeatureCollection.new(response.parsed), expires_in: CACHE_TTL)
|
88
107
|
end
|
89
108
|
|
90
109
|
cache.get("#{CACHE_KEY}_#{product_name}")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: feature_flag_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ardeshir Eshghi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|