Class: FtShared

Inherits:
Object
  • Object
show all
Defined in:
lib/ft_gem/shared/ft_shared.rb

Instance Method Summary collapse

Instance Method Details

#all_togglesObject



11
12
13
14
15
16
17
18
# File 'lib/ft_gem/shared/ft_shared.rb', line 11

def all_toggles
  Rails.cache.fetch('all-feature-toggles', expires_in: 1.minute) do
    JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/",{headers:authentication_header}).to_s)['data']
  end
rescue StandardError => e
  Rails.logger.error "FtHelper::all_toggles error #{e.backtrace}"
  {}
end

#authentication_headerObject



20
21
22
# File 'lib/ft_gem/shared/ft_shared.rb', line 20

def authentication_header
  { Authorization: "Bearer #{MumsnetJWT.tokenify}" }
end

#fetch(name:) ⇒ Object



2
3
4
5
6
7
8
9
# File 'lib/ft_gem/shared/ft_shared.rb', line 2

def fetch(name:)
  Rails.cache.fetch("feature-toggle-#{name}", expires_in: 1.minute) do
    JSON.parse(HTTParty.get("#{ENV['SITE_URL']}/service/ft/api/v1/feature-toggles/status", {query: { name: name },headers:authentication_header}).to_s)['data']
  end
rescue StandardError => e
  Rails.logger.error "FtHelper::fetch error #{e.backtrace}"
  nil
end