flipper-api 0.11.0.beta4 → 0.11.0.beta5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flipper/api.rb +5 -5
- data/lib/flipper/api/middleware.rb +3 -2
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/api/json_params_spec.rb +16 -16
- data/spec/flipper/api/v1/actions/actors_gate_spec.rb +2 -2
- data/spec/flipper/api_spec.rb +24 -0
- metadata +4 -5
- data/lib/flipper/api/actor.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f47344a8b6c5e5aa22f885dca16202c8335bf7f
|
4
|
+
data.tar.gz: 38dcc1ca7f51ac4c0301ef80ddc08a610adf7dd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67c8a531a6ca084ad8e25a238f58e50f1f8db3db7233ac46bdf1affb53ca8e88e8546f138642bdbf426cec23c2e564fad51b1f867e30b4b8414280682b00318f
|
7
|
+
data.tar.gz: 05e52fd77c85f8bee42ec27985e8f926ae65565e6e9b5a3b3bbfcbf01c54acedcd2ecddf26ebe536d17617db35e496f8a23d012390d437c1e86a0af4126e411f
|
data/lib/flipper/api.rb
CHANGED
@@ -4,20 +4,20 @@ require 'flipper/middleware/setup_env'
|
|
4
4
|
require 'flipper/middleware/memoizer'
|
5
5
|
require 'flipper/api/middleware'
|
6
6
|
require 'flipper/api/json_params'
|
7
|
-
require 'flipper/api/actor'
|
8
7
|
|
9
8
|
module Flipper
|
10
9
|
module Api
|
11
10
|
CONTENT_TYPE = 'application/json'.freeze
|
12
11
|
|
13
|
-
def self.app(flipper = nil)
|
12
|
+
def self.app(flipper = nil, options = {})
|
13
|
+
env_key = options.fetch(:env_key, 'flipper')
|
14
14
|
app = ->(_) { [404, { 'Content-Type'.freeze => CONTENT_TYPE }, ['{}'.freeze]] }
|
15
15
|
builder = Rack::Builder.new
|
16
16
|
yield builder if block_given?
|
17
|
-
builder.use Flipper::Middleware::SetupEnv, flipper
|
18
|
-
builder.use Flipper::Middleware::Memoizer
|
19
17
|
builder.use Flipper::Api::JsonParams
|
20
|
-
builder.use Flipper::
|
18
|
+
builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key
|
19
|
+
builder.use Flipper::Middleware::Memoizer, env_key: env_key
|
20
|
+
builder.use Flipper::Api::Middleware, env_key: env_key
|
21
21
|
builder.run app
|
22
22
|
klass = self
|
23
23
|
builder.define_singleton_method(:inspect) { klass.inspect } # pretty rake routes output
|
@@ -9,8 +9,9 @@ end
|
|
9
9
|
module Flipper
|
10
10
|
module Api
|
11
11
|
class Middleware
|
12
|
-
def initialize(app)
|
12
|
+
def initialize(app, options = {})
|
13
13
|
@app = app
|
14
|
+
@env_key = options.fetch(:env_key, 'flipper')
|
14
15
|
|
15
16
|
@action_collection = ActionCollection.new
|
16
17
|
@action_collection.add Api::V1::Actions::PercentageOfTimeGate
|
@@ -33,7 +34,7 @@ module Flipper
|
|
33
34
|
if action_class.nil?
|
34
35
|
@app.call(env)
|
35
36
|
else
|
36
|
-
flipper = env.fetch(
|
37
|
+
flipper = env.fetch(@env_key)
|
37
38
|
action_class.run(flipper, request)
|
38
39
|
end
|
39
40
|
end
|
data/lib/flipper/version.rb
CHANGED
@@ -15,67 +15,67 @@ RSpec.describe Flipper::Api::JsonParams do
|
|
15
15
|
describe 'json post request' do
|
16
16
|
it 'adds request body to params' do
|
17
17
|
response = post '/',
|
18
|
-
JSON.generate(flipper_id: '
|
18
|
+
JSON.generate(flipper_id: 'User;2'),
|
19
19
|
'CONTENT_TYPE' => 'application/json'
|
20
20
|
|
21
21
|
params = JSON.parse(response.body)
|
22
|
-
expect(params).to eq('flipper_id' => '
|
22
|
+
expect(params).to eq('flipper_id' => 'User;2')
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'handles request bodies with multiple params' do
|
26
26
|
response = post '/',
|
27
|
-
JSON.generate(flipper_id: '
|
27
|
+
JSON.generate(flipper_id: 'User;2', language: 'ruby'),
|
28
28
|
'CONTENT_TYPE' => 'application/json'
|
29
29
|
|
30
30
|
params = JSON.parse(response.body)
|
31
|
-
expect(params).to eq('flipper_id' => '
|
31
|
+
expect(params).to eq('flipper_id' => 'User;2', 'language' => 'ruby')
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'handles request bodies and single query string params' do
|
35
35
|
response = post '/?language=ruby',
|
36
|
-
JSON.generate(flipper_id: '
|
36
|
+
JSON.generate(flipper_id: 'User;2'),
|
37
37
|
'CONTENT_TYPE' => 'application/json'
|
38
38
|
|
39
39
|
params = JSON.parse(response.body)
|
40
|
-
expect(params).to eq('flipper_id' => '
|
40
|
+
expect(params).to eq('flipper_id' => 'User;2', 'language' => 'ruby')
|
41
41
|
end
|
42
42
|
|
43
43
|
it 'handles request bodies and multiple query string params' do
|
44
44
|
response = post '/?language=ruby&framework=rails',
|
45
|
-
JSON.generate(flipper_id: '
|
45
|
+
JSON.generate(flipper_id: 'User;2'),
|
46
46
|
'CONTENT_TYPE' => 'application/json'
|
47
47
|
|
48
48
|
params = JSON.parse(response.body)
|
49
|
-
expect(params).to eq('flipper_id' => '
|
49
|
+
expect(params).to eq('flipper_id' => 'User;2', 'language' => 'ruby', 'framework' => 'rails')
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'favors request body params' do
|
53
53
|
response = post '/?language=javascript',
|
54
|
-
JSON.generate(flipper_id: '
|
54
|
+
JSON.generate(flipper_id: 'User;2', language: 'ruby'),
|
55
55
|
'CONTENT_TYPE' => 'application/json'
|
56
56
|
|
57
57
|
params = JSON.parse(response.body)
|
58
|
-
expect(params).to eq('flipper_id' => '
|
58
|
+
expect(params).to eq('flipper_id' => 'User;2', 'language' => 'ruby')
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
62
|
describe 'url-encoded request' do
|
63
63
|
it 'handles params the same as a json request' do
|
64
|
-
response = post '/', flipper_id: '
|
64
|
+
response = post '/', flipper_id: 'User;2'
|
65
65
|
params = JSON.parse(response.body)
|
66
|
-
expect(params).to eq('flipper_id' => '
|
66
|
+
expect(params).to eq('flipper_id' => 'User;2')
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'handles single query string params' do
|
70
|
-
response = post '/?language=ruby', flipper_id: '
|
70
|
+
response = post '/?language=ruby', flipper_id: 'User;2'
|
71
71
|
params = JSON.parse(response.body)
|
72
|
-
expect(params).to eq('flipper_id' => '
|
72
|
+
expect(params).to eq('flipper_id' => 'User;2', 'language' => 'ruby')
|
73
73
|
end
|
74
74
|
|
75
75
|
it 'handles multiple query string params' do
|
76
|
-
response = post '/?language=ruby&framework=rails', flipper_id: '
|
76
|
+
response = post '/?language=ruby&framework=rails', flipper_id: 'User;2'
|
77
77
|
params = JSON.parse(response.body)
|
78
|
-
expect(params).to eq('flipper_id' => '
|
78
|
+
expect(params).to eq('flipper_id' => 'User;2', 'language' => 'ruby', 'framework' => 'rails')
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -2,7 +2,7 @@ require 'helper'
|
|
2
2
|
|
3
3
|
RSpec.describe Flipper::Api::V1::Actions::ActorsGate do
|
4
4
|
let(:app) { build_api(flipper) }
|
5
|
-
let(:actor) { Flipper::
|
5
|
+
let(:actor) { Flipper::Actor.new('1') }
|
6
6
|
|
7
7
|
describe 'enable' do
|
8
8
|
before do
|
@@ -23,7 +23,7 @@ RSpec.describe Flipper::Api::V1::Actions::ActorsGate do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
describe 'disable' do
|
26
|
-
let(:actor) { Flipper::
|
26
|
+
let(:actor) { Flipper::Actor.new('1') }
|
27
27
|
|
28
28
|
before do
|
29
29
|
flipper[:my_feature].enable_actor(actor)
|
data/spec/flipper/api_spec.rb
CHANGED
@@ -43,6 +43,30 @@ RSpec.describe Flipper::Api do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
context 'when initialized with env_key' do
|
47
|
+
let(:app) { build_api(flipper, env_key: 'flipper_api') }
|
48
|
+
|
49
|
+
it 'uses provided env key instead of default' do
|
50
|
+
flipper[:a].enable
|
51
|
+
flipper[:b].disable
|
52
|
+
|
53
|
+
default_env_flipper = build_flipper
|
54
|
+
default_env_flipper[:env_a].enable
|
55
|
+
default_env_flipper[:env_b].disable
|
56
|
+
|
57
|
+
params = {}
|
58
|
+
env = {
|
59
|
+
'flipper' => default_env_flipper,
|
60
|
+
'flipper_api' => flipper,
|
61
|
+
}
|
62
|
+
get '/features', params, env
|
63
|
+
|
64
|
+
expect(last_response.status).to eq(200)
|
65
|
+
feature_names = json_response.fetch('features').map { |feature| feature.fetch('key') }
|
66
|
+
expect(feature_names).to eq(%w(a b))
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
46
70
|
context "when request does not match any api routes" do
|
47
71
|
let(:app) { build_api(flipper) }
|
48
72
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.0.
|
4
|
+
version: 0.11.0.beta5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -36,14 +36,14 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.11.0.
|
39
|
+
version: 0.11.0.beta5
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 0.11.0.
|
46
|
+
version: 0.11.0.beta5
|
47
47
|
description: Rack middleware that provides an API for the flipper gem.
|
48
48
|
email:
|
49
49
|
- nunemaker@gmail.com
|
@@ -56,7 +56,6 @@ files:
|
|
56
56
|
- lib/flipper/api.rb
|
57
57
|
- lib/flipper/api/action.rb
|
58
58
|
- lib/flipper/api/action_collection.rb
|
59
|
-
- lib/flipper/api/actor.rb
|
60
59
|
- lib/flipper/api/error.rb
|
61
60
|
- lib/flipper/api/error_response.rb
|
62
61
|
- lib/flipper/api/json_params.rb
|
data/lib/flipper/api/actor.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module Flipper
|
2
|
-
module Api
|
3
|
-
# Internal: Shim for turning a string flipper id into something that responds to
|
4
|
-
# flipper_id for Flipper::Types::Actor.
|
5
|
-
class Actor
|
6
|
-
attr_reader :flipper_id
|
7
|
-
|
8
|
-
def initialize(flipper_id)
|
9
|
-
@flipper_id = flipper_id
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|