rollout-ui 0.2.0 → 0.3.0

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: e342dafb4fb3a868d96da458d3227d4d177d168a28e640d3ba6eb4e85caa3393
4
- data.tar.gz: f7d5778665b1da78012854c306b1df04797fe924fa5733d68de3bd1428ce8c84
3
+ metadata.gz: 46ae18c9e6daeba114f85ef7608108c76095761a97446d570da01f7412f80183
4
+ data.tar.gz: f38e59a3c048cd04074b9d85bb708c1aa8d07d6b94c1b1ba0e66bf616d0fdae9
5
5
  SHA512:
6
- metadata.gz: b91d583fecd5e7b9ba6d0d1adfddec7e5a8894e943d80c9c258bb7399d40fc1687cdbe0b72129b111e5c3dfb162d1fc445784660e09c37adeaa8f95165956658
7
- data.tar.gz: cf24e7f1bb6b083bad9fd4e30f1838cef1b746f662eb3b94f5de28beb69485f2729a38f302b30a3b807505a22259eb951564ef24bf25bb075af56206b2b57ab2
6
+ metadata.gz: 1fa46d7b3ed9372bd46059d5f0513d8ba18964c97787ad8b552df5e82f4ce2a378d31d6407d095d586df948897c07dd890c99359ac548624f10c83308fcfc368
7
+ data.tar.gz: 9286a654951b7f8462bd8e8742d351f23dda33afe8097245bb339ad15314ccafe8a84614448c8c2c393fdf4cfc721f533d600b0ebd11d051469394895e4fa072
data/README.md CHANGED
@@ -58,6 +58,15 @@ Rails.application.routes.draw do
58
58
  end
59
59
  ```
60
60
 
61
+ ## API Endpoints
62
+
63
+ The index and show routes can also respond with JSON data instead of HTML when the request's `Accept` header is
64
+ `application/json`
65
+
66
+ The index route also accepts query parameters to filter by user or group:
67
+ `/admin/rollout?user=someone`
68
+ `/admin/rollout?group=developers`
69
+
61
70
  ## Logging
62
71
 
63
72
  To get the most out of **rollout-ui**, we recommend you to turn on logging
@@ -84,5 +84,29 @@ module Rollout::UI
84
84
  value
85
85
  end
86
86
  end
87
+
88
+ def json_request?
89
+ request.env['HTTP_ACCEPT'] == 'application/json'
90
+ end
91
+
92
+ # Filters features by user and group if those params are provided
93
+ def filtered_features(rollout, feature_names)
94
+ feature_names.select do |feature_name|
95
+ feature = rollout.get(feature_name)
96
+ user_match = params[:user].nil? || feature.users.member?(params[:user])
97
+ group_match = params[:group].nil? || feature.groups.member?(params[:group].to_sym)
98
+ user_match && group_match
99
+ end
100
+ end
101
+
102
+ # Returns a hash of feature data to be rendered as json
103
+ def feature_to_hash(feature)
104
+ {
105
+ data: feature.data,
106
+ groups: feature.groups,
107
+ name: feature.name,
108
+ percentage: feature.percentage
109
+ }
110
+ end
87
111
  end
88
112
  end
@@ -1,5 +1,5 @@
1
1
  class Rollout
2
2
  module UI
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -1,4 +1,5 @@
1
1
  require "sinatra"
2
+ require "sinatra/json"
2
3
  require "rollout"
3
4
 
4
5
  require "rollout/ui/version"
@@ -15,8 +16,15 @@ module Rollout::UI
15
16
  get '/' do
16
17
  @rollout = config.get(:instance)
17
18
  @features = @rollout.features.sort_by(&:downcase)
18
-
19
- slim :'features/index'
19
+ if json_request?
20
+ json(
21
+ filtered_features(@rollout, @features).map do |feature|
22
+ feature_to_hash(@rollout.get(feature))
23
+ end
24
+ )
25
+ else
26
+ slim :'features/index'
27
+ end
20
28
  end
21
29
 
22
30
  get '/features/new' do
@@ -31,7 +39,11 @@ module Rollout::UI
31
39
  @rollout = config.get(:instance)
32
40
  @feature = @rollout.get(params[:feature_name])
33
41
 
34
- slim :'features/show'
42
+ if json_request?
43
+ json(feature_to_hash(@feature))
44
+ else
45
+ slim :'features/show'
46
+ end
35
47
  end
36
48
 
37
49
  post '/features/:feature_name' do
@@ -24,10 +24,13 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency 'rollout', '~> 2.5'
26
26
  spec.add_dependency 'sinatra', '~> 2.0'
27
+ spec.add_dependency 'sinatra-contrib', '~> 2.1'
27
28
  spec.add_dependency 'slim', '~> 4.0'
28
29
 
29
- spec.add_development_dependency 'bundler', '~> 1.17'
30
+ spec.add_development_dependency 'bundler', '>= 1.17'
30
31
  spec.add_development_dependency 'rake', '~> 10.0'
31
32
  spec.add_development_dependency 'rspec', '~> 3.0'
32
33
  spec.add_development_dependency 'rerun', '~> 0.13'
34
+ spec.add_development_dependency 'rack-test'
35
+ spec.add_development_dependency 'pry'
33
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollout-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - FetLife
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-22 00:00:00.000000000 Z
11
+ date: 2020-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rollout
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sinatra-contrib
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.1'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: slim
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -56,14 +70,14 @@ dependencies:
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "~>"
73
+ - - ">="
60
74
  - !ruby/object:Gem::Version
61
75
  version: '1.17'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "~>"
80
+ - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '1.17'
69
83
  - !ruby/object:Gem::Dependency
@@ -108,6 +122,34 @@ dependencies:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: '0.13'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rack-test
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
111
153
  description: ''
112
154
  email:
113
155
  - dev@fetlife.com