ft_gem 1.0.9 → 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ft.rb +1 -0
  3. metadata +2 -4
  4. data/helpers/ft_helper.rb +0 -28
  5. data/lib/ft_gem.rb +0 -66
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef07ad0ca02827f968070f4899ed429ab0d7819fb23fec326502e7993c512022
4
- data.tar.gz: e0df3efb5bb0d83fc62215d3616c36f8ce3a1269ea231d867d7d6a3f93b6fad6
3
+ metadata.gz: 840c4754c69387e81fcdcc5ac899976f09b7d3a5a06bb3c48765e91936bb34cf
4
+ data.tar.gz: f4d602196bdfe7973dd021f7ea8639f756e16d5184f4278fd8d6e4da5fb55ec1
5
5
  SHA512:
6
- metadata.gz: ac1a94ec1c55a9fa603e6ed339a847a1f4ba89bb28c8a90a7c815c354f3c2d80ba7a5151b3e4b8bf49a36da4f7dd33b91060f5e500cca61f0e5db974d0a1460d
7
- data.tar.gz: c7700e94f3c31c99490d10357b0b9d0c8cd9e002c5cc31a0b9da38264877a223bfe199fcd46c9a5643cf855ba233ba022e9fa01a611a5c0ca206c12c03ba2287
6
+ metadata.gz: 5ed119754417344da93de612bc9bf3278867eae947558bfede7e2d210b88ab6e843844df4bf44553f57cf971bdc0eb643e17abd49ce8b23d89c62ebac2eccf81
7
+ data.tar.gz: 8ac51bac3386cff3dfb423cd097dfe181d46f9cc56aae7929feae8a242bdbdd674edb1a7dee84955df3b27bd7341316109b2f48316caf935c0ea2aa4b6bcaba6
data/lib/ft.rb ADDED
@@ -0,0 +1 @@
1
+ require 'ft_gem.rb'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ft_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murray Catto
@@ -30,8 +30,7 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - helpers/ft_helper.rb
34
- - lib/ft_gem.rb
33
+ - lib/ft.rb
35
34
  homepage:
36
35
  licenses: []
37
36
  metadata: {}
@@ -39,7 +38,6 @@ post_install_message:
39
38
  rdoc_options: []
40
39
  require_paths:
41
40
  - lib
42
- - helpers
43
41
  required_ruby_version: !ruby/object:Gem::Requirement
44
42
  requirements:
45
43
  - - ">="
data/helpers/ft_helper.rb DELETED
@@ -1,28 +0,0 @@
1
- module FtHelper
2
- class <<self
3
- def status(name:)
4
- toggle = fetch(name: name)
5
- toggle['feature_toggle']['toggle_percentage'].to_i == 100
6
- rescue StandardError => e
7
- puts "FTApiGem error #{e}"
8
- puts 'Method: api_feature_toggle_status'
9
- false
10
- end
11
-
12
- private
13
-
14
- def fetch(name:)
15
- Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
16
- JSON.parse(HTTP.headers(authentication_header).get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", params: { name: name }).body.to_s)
17
- end
18
- rescue StandardError => e
19
- puts "FTApiGem error #{e}"
20
- puts 'Method: api_fetch_feature_toggle'
21
- nil
22
- end
23
-
24
- def authentication_header
25
- { Authorization: "Bearer #{MumsnetJWT.tokenify}" }
26
- end
27
- end
28
- end
data/lib/ft_gem.rb DELETED
@@ -1,66 +0,0 @@
1
- module FTGem
2
- TOGGLE_COOKIE_NAME = 'mnft'.freeze
3
-
4
- def feature_toggle_status(name:)
5
- cookies[TOGGLE_COOKIE_NAME] = '' if cookies[TOGGLE_COOKIE_NAME].nil?
6
- add_feature_toggle(name: name) unless cookies[TOGGLE_COOKIE_NAME].include?("#{name} ")
7
- update_feature_toggle(name: name) if cookies[TOGGLE_COOKIE_NAME].include?("#{name} ")
8
- toggles = cookies[TOGGLE_COOKIE_NAME].split('|')
9
- index = toggles.index { |toggle| toggle.include?("#{name} ") }
10
- client_percentage = toggles[index].split(' ')[1]
11
- toggle_percentage = toggles[index].split(' ')[2]
12
- client_percentage.to_i <= toggle_percentage.to_i
13
- rescue StandardError
14
- false
15
- end
16
-
17
- def add_feature_toggle(name:)
18
- data = Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
19
- JSON.parse(HTTP.headers(authentication_header).get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", params: { name: name }).body.to_s)
20
- end
21
- toggle_percentage = data['feature_toggle']['toggle_percentage']
22
- client_percentage = data['feature_toggle']['client_percentage']
23
- cookies[TOGGLE_COOKIE_NAME] = "#{cookies[TOGGLE_COOKIE_NAME]}|#{name} #{client_percentage} #{toggle_percentage}"
24
- rescue StandardError
25
- nil
26
- end
27
-
28
- def update_feature_toggle(name:)
29
- data = Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
30
- JSON.parse(HTTP.headers(authentication_header).get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", params: { name: name }).body.to_s)
31
- end
32
- toggle_percentage = data['feature_toggle']['toggle_percentage']
33
- toggles = cookies[TOGGLE_COOKIE_NAME].split('|')
34
- index = toggles.index { |toggle| toggle.include?("#{name} ") }
35
- client_percentage = toggles[index].split(' ')[1]
36
- toggles[index] = "#{name} #{client_percentage} #{toggle_percentage}"
37
- cookies[TOGGLE_COOKIE_NAME] = toggles.join('|')
38
- rescue StandardError
39
- nil
40
- end
41
-
42
- def api_feature_toggle_status(name:)
43
- toggle = api_fetch_feature_toggle(name: name)
44
- toggle['feature_toggle']['toggle_percentage'].to_i == 100
45
- rescue StandardError => e
46
- puts "FTApiGem error #{e}"
47
- puts 'Method: api_feature_toggle_status'
48
- false
49
- end
50
-
51
- def api_fetch_feature_toggle(name:)
52
- Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
53
- JSON.parse(HTTP.headers(authentication_header).get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", params: { name: name }).body.to_s)
54
- end
55
- rescue StandardError => e
56
- puts "FTApiGem error #{e}"
57
- puts 'Method: api_fetch_feature_toggle'
58
- nil
59
- end
60
-
61
- private
62
-
63
- def authentication_header
64
- { Authorization: "Bearer #{MumsnetJWT.tokenify}" }
65
- end
66
- end