ft_gem 3.1.0 → 3.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 882b46bd6292e36ab8cd057adcd6982091a0bb50549c038955466bcd547ea134
4
- data.tar.gz: 00516c790a74ec6d5b03036ac9784371f25da4e70bd532d6c8b522cf91199e31
3
+ metadata.gz: f59d9f1f380088f670d59c8d4d1717a201c3fe01469b06869e0782c1ae10caf7
4
+ data.tar.gz: c9f1ecb7b7e2138a8452d939d7560de5dcc5d1fa21a297ffab725d52b05fd4a3
5
5
  SHA512:
6
- metadata.gz: b680e623e2eb1268c119bd0a059c2a0a5f25a7763ac58e7682fba4dbe8c3a7ec46d02b291dbf002145e140c2907b3ba326aac0c44dd253f72e9481a1523714b0
7
- data.tar.gz: 5aadadf5af0047d30584a4a70e4e819539f934fb2d09fbad5b012c5181daa3e614944df5990d9de5438bfe7b31834e5b1c99a6bbef0062188948b91fb76fde48
6
+ metadata.gz: 06e2149714a5b1d095275f98ff5e448c6f436b441a608e43b12ef7d82e0f9fbf687c3a4d7f9c504187d0ca0cddb1e89d78f8a475dd2533ea5c044d798210f3b7
7
+ data.tar.gz: 54f5a746a6c7fb7ec73b89d37827a33d4aeefd6253c0bec17f0dcbf8e95d0e98d01b2712c7c3135b64a4433eed6b391d76415838b30ffdca0cddb9d41a38bc14
@@ -5,7 +5,7 @@ module FtGem
5
5
  TOGGLE_COOKIE_NAME = 'mnft'.freeze
6
6
  require 'base64'
7
7
 
8
- def feature_toggle_status(name:, url: nil)
8
+ def feature_toggle_status(name:, user_id: nil, url: nil)
9
9
  toggles = FtShared.new.all_toggles
10
10
  update_feature_toggles(toggles: toggles)
11
11
  decoded_cookie = Base64.decode64(cookies[TOGGLE_COOKIE_NAME])
@@ -14,7 +14,11 @@ module FtGem
14
14
  client_percentage = calc_client_percentage(decoded_cookie: decoded_cookie, toggle_name: name)
15
15
  toggle_percentage = toggles[index.to_i]['attributes']['percentage']
16
16
  whitelisted = FtShared.new.whitelisted?(url: url, whitelist_urls: toggles[index.to_i]['attributes']['whitelist-urls'])
17
- client_percentage.to_i <= toggle_percentage.to_i && whitelisted
17
+ if user_id.present? && toggles[index.to_i]['attributes']['status'] == "amber" && toggles[index.to_i]['attributes']['beta-users'] != "" && toggles[index.to_i]['attributes']['beta-users'].split(",").include?(user_id.to_s)
18
+ return true
19
+ else
20
+ return client_percentage.to_i <= toggle_percentage.to_i && whitelisted
21
+ end
18
22
  rescue StandardError => e
19
23
  Rails.logger.error "FtGem::feature_toggle_status error #{e.backtrace}"
20
24
  false
@@ -29,7 +33,7 @@ module FtGem
29
33
  new_cookie.push("#{toggle['attributes']['name']}:#{client_percentage}")
30
34
  end
31
35
  cookies.delete TOGGLE_COOKIE_NAME, domain: ENV['COOKIE_DOMAIN']
32
- cookies[TOGGLE_COOKIE_NAME] = { value: Base64.encode64(new_cookie.join(',')).to_s, secure: true }
36
+ cookies[TOGGLE_COOKIE_NAME] = { value: Base64.strict_encode64(new_cookie.join(',')).to_s, secure: true }
33
37
  rescue StandardError => e
34
38
  Rails.logger.error "FTApiGem::update_feature_toggles error #{e.backtrace}"
35
39
  nil
@@ -1,19 +1,21 @@
1
1
  class FtShared
2
2
  def fetch(name:)
3
+ http_response = ''
3
4
  Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
4
- JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", query: { name: name }, headers: authentication_header).to_json)['data']
5
+ http_response = HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", query: { name: name }, headers: authentication_header)
6
+ JSON.parse(http_response.to_json)['data']
5
7
  end
6
8
  rescue StandardError => e
7
- Rails.logger.error "FtHelper::fetch error #{e.backtrace}"
9
+ Rails.logger.error "FtHelper::fetch error for #{name}\nerror: #{e.message}\nhttp_response: #{http_response}"
8
10
  nil
9
11
  end
10
12
 
11
13
  def all_toggles
12
14
  Rails.cache.fetch('all-feature-toggles', expires_in: 1.minute) do
13
- JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/", headers: authentication_header).to_json)['data']
15
+ JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles", headers: authentication_header).to_json)['data']
14
16
  end
15
17
  rescue StandardError => e
16
- Rails.logger.error "FtHelper::all_toggles error #{e.backtrace}"
18
+ Rails.logger.error "FtHelper::all_toggles error #{e.message}"
17
19
  {}
18
20
  end
19
21
 
@@ -7,7 +7,7 @@ module FtGem
7
7
  whitelisted = FtShared.new.whitelisted?(url: url, whitelist_urls: toggle['attributes']['whitelist-urls'])
8
8
  toggle['attributes']['percentage'].to_i == 100 && whitelisted
9
9
  rescue StandardError => e
10
- Rails.logger.error "FtHelper::status error #{e.backtrace}"
10
+ Rails.logger.error "FtHelper::status error #{e.message}"
11
11
  false
12
12
  end
13
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ft_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Murray Catto
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumsnet_jwt
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description:
42
- email:
41
+ description:
42
+ email:
43
43
  executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
@@ -48,10 +48,10 @@ files:
48
48
  - lib/ft_gem/controllers/helpers.rb
49
49
  - lib/ft_gem/shared/ft_shared.rb
50
50
  - lib/ft_gem/view/helpers.rb
51
- homepage:
51
+ homepage:
52
52
  licenses: []
53
53
  metadata: {}
54
- post_install_message:
54
+ post_install_message:
55
55
  rdoc_options: []
56
56
  require_paths:
57
57
  - lib
@@ -66,8 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubygems_version: 3.0.3
70
- signing_key:
69
+ rubygems_version: 3.0.8
70
+ signing_key:
71
71
  specification_version: 4
72
72
  summary: Client side feature toggle
73
73
  test_files: []