summaryrefslogtreecommitdiff
path: root/lib/api/features.rb
blob: cff0ba2ddff3f29fd0df2a0a0fe0c5ab24c8a9d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module API
  class Features < Grape::API
    before { authenticated_as_admin! }

    resource :features do
      desc 'Get a list of all features' do
        success Entities::Feature
      end
      get do
        features = Feature.all

        present features, with: Entities::Feature, current_user: current_user
      end

      desc 'Set the gate value for the given feature' do
        success Entities::Feature
      end
      params do
        requires :value, type: String, desc: '`true` or `false` to enable/disable, an integer for percentage of time'
      end
      post ':name' do
        feature = Feature.get(params[:name])

        if %w(0 false).include?(params[:value])
          feature.disable
        elsif params[:value] == 'true'
          feature.enable
        else
          feature.enable_percentage_of_time(params[:value].to_i)
        end

        present feature, with: Entities::Feature, current_user: current_user
      end
    end
  end
end