reviewed 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/faraday/global_params.rb +18 -0
- data/lib/reviewed/article.rb +0 -4
- data/lib/reviewed/client.rb +1 -1
- data/lib/reviewed/version.rb +1 -1
- data/lib/reviewed.rb +3 -1
- data/spec/article_spec.rb +0 -12
- data/spec/faraday/global_params_spec.rb +33 -0
- data/spec/reviewed_spec.rb +13 -0
- metadata +5 -5
- data/lib/faraday/branches.rb +0 -19
- data/spec/faraday/branches_spec.rb +0 -62
@@ -0,0 +1,18 @@
|
|
1
|
+
module Faraday
|
2
|
+
class GlobalParams < Faraday::Middleware
|
3
|
+
|
4
|
+
def call(env)
|
5
|
+
params = Reviewed.global_params
|
6
|
+
|
7
|
+
if params && params.is_a?(Hash)
|
8
|
+
path = env[:url].path
|
9
|
+
query = env[:url].query || {}
|
10
|
+
env[:url].query = Faraday::Utils.build_query(query.merge(params))
|
11
|
+
end
|
12
|
+
|
13
|
+
@app.call(env)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Faraday.register_middleware :request, global_params: Faraday::GlobalParams
|
data/lib/reviewed/article.rb
CHANGED
data/lib/reviewed/client.rb
CHANGED
@@ -48,7 +48,7 @@ module Reviewed
|
|
48
48
|
@connection ||= ::Faraday.new(url: url) do |faraday|
|
49
49
|
faraday.response :mashify
|
50
50
|
faraday.response :json
|
51
|
-
faraday.request :
|
51
|
+
faraday.request :global_params
|
52
52
|
faraday.request :url_encoded
|
53
53
|
faraday.adapter Faraday.default_adapter
|
54
54
|
end
|
data/lib/reviewed/version.rb
CHANGED
data/lib/reviewed.rb
CHANGED
@@ -2,7 +2,7 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
|
2
2
|
|
3
3
|
require 'faraday'
|
4
4
|
require 'faraday_middleware'
|
5
|
-
require 'faraday/
|
5
|
+
require 'faraday/global_params'
|
6
6
|
require 'active_support/inflector'
|
7
7
|
require 'active_support/core_ext'
|
8
8
|
require 'active_model'
|
@@ -29,6 +29,8 @@ module Reviewed
|
|
29
29
|
|
30
30
|
class << self
|
31
31
|
|
32
|
+
attr_accessor :global_params
|
33
|
+
|
32
34
|
def client
|
33
35
|
@client ||= Reviewed::Client.new
|
34
36
|
end
|
data/spec/article_spec.rb
CHANGED
@@ -2,18 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Reviewed::Article do
|
4
4
|
|
5
|
-
describe 'accessors' do
|
6
|
-
|
7
|
-
after(:each) do
|
8
|
-
Reviewed::Article.branch = nil
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'global params' do
|
12
|
-
Reviewed::Article.branch = 'test'
|
13
|
-
Reviewed::Article.branch.should eql('test')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
5
|
describe 'associations' do
|
18
6
|
|
19
7
|
describe 'pages' do
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Faraday::GlobalParams do
|
4
|
+
|
5
|
+
class FauxApp
|
6
|
+
def call(env)
|
7
|
+
return env
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:faraday) { Faraday::GlobalParams.new(FauxApp.new) }
|
12
|
+
let(:env) { { url: URI.parse("http://www.the-guide-staging.com/api/v1/articles") } }
|
13
|
+
|
14
|
+
context 'branch present' do
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
Reviewed.stub!(:global_params).and_return( foo: "bar" )
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'adds the branch to the query params' do
|
21
|
+
out = faraday.call(env)
|
22
|
+
out[:url].query.should eql("foo=bar")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'no branch present' do
|
27
|
+
|
28
|
+
it 'does not add the branch to the query params' do
|
29
|
+
out = faraday.call(env)
|
30
|
+
out[:url].query.should be_nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/reviewed_spec.rb
CHANGED
@@ -2,6 +2,19 @@ require 'spec_helper.rb'
|
|
2
2
|
|
3
3
|
describe Reviewed do
|
4
4
|
|
5
|
+
describe 'accessors' do
|
6
|
+
|
7
|
+
after(:each) do
|
8
|
+
Reviewed.global_params = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'global params' do
|
12
|
+
Reviewed.global_params = { foo: 'bar' }
|
13
|
+
Reviewed.global_params.should eql( { foo: 'bar' } )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
|
5
18
|
describe '.client' do
|
6
19
|
|
7
20
|
it 'returns a Reviewed::Client' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reviewed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-11-
|
13
|
+
date: 2012-11-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -186,7 +186,7 @@ files:
|
|
186
186
|
- LICENSE
|
187
187
|
- README.md
|
188
188
|
- Rakefile
|
189
|
-
- lib/faraday/
|
189
|
+
- lib/faraday/global_params.rb
|
190
190
|
- lib/reviewed.rb
|
191
191
|
- lib/reviewed/article.rb
|
192
192
|
- lib/reviewed/attachment.rb
|
@@ -212,7 +212,7 @@ files:
|
|
212
212
|
- spec/collection_spec.rb
|
213
213
|
- spec/configurable_spec.rb
|
214
214
|
- spec/embeddable_spec.rb
|
215
|
-
- spec/faraday/
|
215
|
+
- spec/faraday/global_params_spec.rb
|
216
216
|
- spec/fixtures/vcr/article/attachments.yml
|
217
217
|
- spec/fixtures/vcr/article/find_page.yml
|
218
218
|
- spec/fixtures/vcr/article/products.yml
|
@@ -266,7 +266,7 @@ test_files:
|
|
266
266
|
- spec/collection_spec.rb
|
267
267
|
- spec/configurable_spec.rb
|
268
268
|
- spec/embeddable_spec.rb
|
269
|
-
- spec/faraday/
|
269
|
+
- spec/faraday/global_params_spec.rb
|
270
270
|
- spec/fixtures/vcr/article/attachments.yml
|
271
271
|
- spec/fixtures/vcr/article/find_page.yml
|
272
272
|
- spec/fixtures/vcr/article/products.yml
|
data/lib/faraday/branches.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Faraday
|
2
|
-
class Branches < Faraday::Middleware
|
3
|
-
|
4
|
-
def call(env)
|
5
|
-
path = env[:url].path
|
6
|
-
branch = Reviewed::Article.branch
|
7
|
-
|
8
|
-
if path =~ /#{Reviewed::Article.resource_url}/ && branch
|
9
|
-
query = env[:url].query || {}
|
10
|
-
branch = Reviewed::Article.branch
|
11
|
-
env[:url].query = Faraday::Utils.build_query(query.merge(branch: branch))
|
12
|
-
end
|
13
|
-
|
14
|
-
@app.call(env)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
Faraday.register_middleware :request, branches: Faraday::Branches
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper.rb'
|
2
|
-
|
3
|
-
describe Faraday::Branches do
|
4
|
-
|
5
|
-
class FauxApp
|
6
|
-
def call(env)
|
7
|
-
return env
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
let(:faraday) { Faraday::Branches.new(FauxApp.new) }
|
12
|
-
|
13
|
-
context 'Articles' do
|
14
|
-
|
15
|
-
let(:env) { { url: URI.parse("http://www.the-guide-staging.com/api/v1/articles") } }
|
16
|
-
|
17
|
-
context 'branch present' do
|
18
|
-
|
19
|
-
before(:each) do
|
20
|
-
Reviewed::Article.stub!(:branch).and_return("test")
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'adds the branch to the query params' do
|
24
|
-
out = faraday.call(env)
|
25
|
-
out[:url].query.should eql("branch=test")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
context 'no branch present' do
|
30
|
-
|
31
|
-
it 'does not add the branch to the query params' do
|
32
|
-
out = faraday.call(env)
|
33
|
-
out[:url].query.should be_nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'Others' do
|
39
|
-
|
40
|
-
let(:env) { { url: URI.parse("http://www.the-guide-staging.com/api/v1/products") } }
|
41
|
-
|
42
|
-
context 'branch present' do
|
43
|
-
|
44
|
-
before(:each) do
|
45
|
-
Reviewed::Article.stub!(:branch).and_return("test")
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'adds the branch to the query params' do
|
49
|
-
out = faraday.call(env)
|
50
|
-
out[:url].query.should eql(nil)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'no branch present' do
|
55
|
-
|
56
|
-
it 'does not add the branch to the query params' do
|
57
|
-
out = faraday.call(env)
|
58
|
-
out[:url].query.should be_nil
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|