faraday_middleware-escher 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -2
- data/VERSION +1 -1
- data/faraday_middleware-escher.gemspec +0 -2
- data/lib/faraday/middleware/escher.rb +8 -0
- data/lib/{faraday_middleware/escher/base_middleware.rb → faraday/middleware/escher/base.rb} +1 -1
- data/lib/{faraday_middleware → faraday/middleware}/escher/request_signer.rb +2 -2
- data/lib/faraday/middleware/escher/response_validator.rb +2 -0
- data/lib/faraday_middleware/escher.rb +14 -7
- data/spec/escher/{base_middleware_spec.rb → base_spec.rb} +8 -8
- data/spec/escher/request_signer_spec.rb +25 -40
- data/spec/spec_helper.rb +20 -0
- metadata +7 -20
- data/lib/faraday_middleware/escher/response_validator.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5baa8d8b8657adbefc20cd4ea7f580589d25be4
|
4
|
+
data.tar.gz: 2fc9ae873439e82ff218edd1a6b57c0490cdf1bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 148dfca784d915c177d7f1f6c70c4a16fb967c0c05c4d2584a504390deff9dfa7f4fda15aa2a30fa1440ad91f787103f22075ec3d358e5fecea3b53acaefd6c1
|
7
|
+
data.tar.gz: 6c303e8fb87111d00ba302d2437dbf728ffccfd3d73eeaf0e4f0041e6d8c642d95e3a18744ebedbeb6d155664c79edbfad9b354b31370e0f0f81856d833f4f3a
|
data/README.md
CHANGED
@@ -28,7 +28,7 @@ The FaradayMiddleware::Escher::RequestSigner will help you sign your requests be
|
|
28
28
|
require 'faraday_middleware/escher'
|
29
29
|
conn = Faraday.new do |builder|
|
30
30
|
|
31
|
-
builder.use
|
31
|
+
builder.use Faraday::Middleware::Escher::RequestSigner, credential_scope: 'example/credential/scope' do
|
32
32
|
{api_key_id: 'EscherExample', api_secret: 'TheBeginningOfABeautifulFriendship'}
|
33
33
|
end
|
34
34
|
|
@@ -38,7 +38,10 @@ The FaradayMiddleware::Escher::RequestSigner will help you sign your requests be
|
|
38
38
|
|
39
39
|
```
|
40
40
|
|
41
|
-
|
41
|
+
|
42
|
+
### Response Validator
|
43
|
+
|
44
|
+
coming soon! @wip
|
42
45
|
|
43
46
|
## Contributing
|
44
47
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -1,8 +1,8 @@
|
|
1
|
-
class
|
1
|
+
class Faraday::Middleware::Escher::RequestSigner < Faraday::Middleware::Escher::Base
|
2
2
|
|
3
3
|
def call(env)
|
4
4
|
|
5
|
-
escher = Escher::Auth.new(@escher_credential_scope, @escher_options)
|
5
|
+
escher = ::Escher::Auth.new(@escher_credential_scope, @escher_options)
|
6
6
|
|
7
7
|
uri_path = env[:url].path
|
8
8
|
endpoint = uri_path.empty? ? '/' : uri_path
|
@@ -1,7 +1,14 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
require 'faraday_middleware
|
6
|
-
|
7
|
-
end
|
1
|
+
#backwardCompatibility
|
2
|
+
require 'faraday/middleware/escher'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'faraday_middleware'
|
6
|
+
rescue LoadError
|
7
|
+
end
|
8
|
+
|
9
|
+
unless defined?(FaradayMiddleware)
|
10
|
+
module FaradayMiddleware
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
FaradayMiddleware::Escher ||= ::Faraday::Middleware::Escher
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
-
describe FaradayMiddleware::Escher::
|
2
|
+
describe FaradayMiddleware::Escher::Base do
|
3
3
|
|
4
4
|
let(:app){double('app')}
|
5
5
|
|
@@ -8,16 +8,16 @@ describe FaradayMiddleware::Escher::BaseMiddleware do
|
|
8
8
|
let(:api_secret){'superSecret'}
|
9
9
|
|
10
10
|
let(:options){
|
11
|
-
|
12
11
|
{
|
13
|
-
|
14
|
-
|
15
|
-
host: host
|
12
|
+
host: host,
|
13
|
+
credential_scope: 'test/test/test'
|
16
14
|
}
|
17
|
-
|
18
15
|
}
|
19
16
|
|
20
|
-
|
17
|
+
let(:key_db){{api_key_id: 'EscherExample', api_secret: 'TheBeginningOfABeautifulFriendship'}}
|
18
|
+
|
19
|
+
|
20
|
+
subject{ self.described_class.new(app,options) {key_db} }
|
21
21
|
|
22
22
|
before do
|
23
23
|
allow(Socket).to receive(:gethostname).and_return(host)
|
@@ -26,7 +26,7 @@ describe FaradayMiddleware::Escher::BaseMiddleware do
|
|
26
26
|
describe '#initialize' do
|
27
27
|
describe 'init take an options hash after app, and catch some of its value' do
|
28
28
|
|
29
|
-
%W[ host
|
29
|
+
%W[ host ].each do |element|
|
30
30
|
it "should save #{element} hast key's value under @#{element}" do
|
31
31
|
expect(subject.instance_variable_get("@#{element}")).to eq options[element.to_sym]
|
32
32
|
end
|
@@ -1,73 +1,58 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
|
-
describe
|
2
|
+
describe Faraday::Middleware::Escher::RequestSigner do
|
3
3
|
describe 'this is a faraday middleware witch instance will response to call method' do
|
4
4
|
|
5
5
|
let(:api_key) { 'superKey' }
|
6
6
|
let(:api_secret) { 'superSecret' }
|
7
7
|
let(:host) { 'localhost' }
|
8
8
|
|
9
|
+
let(:target_url) { "http://api-with-escher.example.com" }
|
9
10
|
let(:stubs) { Faraday::Adapter::Test::Stubs.new }
|
10
11
|
|
12
|
+
let(:request_expectations){ -> env {} }
|
13
|
+
let(:response_expectations){ -> env {} }
|
14
|
+
|
11
15
|
subject do
|
12
16
|
|
13
17
|
Faraday.new do |builder|
|
14
18
|
|
15
|
-
builder.use FaradayMiddleware::Escher::RequestSigner,
|
16
|
-
api_key: api_key,
|
17
|
-
api_secret: api_secret,
|
18
|
-
host: host
|
19
19
|
|
20
|
-
builder.
|
21
|
-
|
20
|
+
builder.use Faraday::Middleware::Escher::RequestSigner, credential_scope: 'example/credential/scope' do
|
21
|
+
{api_key_id: 'EscherExample', api_secret: 'TheBeginningOfABeautifulFriendship'}
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
24
|
+
builder.use ExpectsMiddleware, request_expectations: request_expectations
|
25
|
+
builder.use ExpectsMiddleware, response_expectations: response_expectations
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
api_key: api_key,
|
32
|
-
api_secret: api_secret,
|
33
|
-
host: host
|
27
|
+
builder.adapter :test, stubs do |stub|
|
28
|
+
stub.get(target_url) { |env| [200, {}, 'shrimp'] }
|
29
|
+
end
|
34
30
|
|
35
|
-
builder.use FaradayMiddleware::FollowRedirects
|
36
|
-
builder.adapter Faraday.default_adapter
|
37
31
|
end
|
32
|
+
|
38
33
|
end
|
39
34
|
|
40
|
-
let(:target_url) { "http://api-with-escher.example.com" }
|
41
35
|
|
42
36
|
describe '#call' do
|
43
37
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
# stubs.get('/uni') {[ 200, {}, 'urchin' ]}
|
49
|
-
|
50
|
-
request_mock = stub_request(:get, target_url)
|
51
|
-
|
52
|
-
puts request_mock.methods - Object.methods
|
53
|
-
|
54
|
-
stub_request(:get, "http://facebook.com").to_return(
|
55
|
-
:status => 302,
|
56
|
-
:headers => {"Location" => "http://www.facebook.com/"})
|
57
|
-
|
58
|
-
stub_request(:get, "http://www.facebook.com/").to_return(
|
59
|
-
:status => 302,
|
60
|
-
:headers => {"Location" => "https://www.facebook.com/"})
|
38
|
+
before do
|
39
|
+
@env = nil
|
40
|
+
end
|
61
41
|
|
62
|
-
|
42
|
+
let(:request_expectations) do
|
43
|
+
-> env do
|
44
|
+
@request_env = env
|
45
|
+
end
|
46
|
+
end
|
63
47
|
|
64
|
-
|
48
|
+
it 'should insert escher request headers for the call' do
|
65
49
|
|
66
|
-
expect(
|
50
|
+
expect( subject.get(target_url).status ).to eq 200
|
51
|
+
expect( @request_env[:request_headers]["X-Escher-Auth"].nil? ).to eq false
|
52
|
+
expect( @request_env[:request_headers]["X-Escher-Date"].nil? ).to eq false
|
67
53
|
|
68
54
|
end
|
69
55
|
|
70
|
-
|
71
56
|
end
|
72
57
|
|
73
58
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -45,4 +45,24 @@ RSpec.configure do |config|
|
|
45
45
|
config.expect_with :rspec do |c|
|
46
46
|
c.syntax = :expect
|
47
47
|
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class ExpectsMiddleware < Faraday::Middleware
|
51
|
+
|
52
|
+
def initialize(app,request_expectations:nil,response_expectations:nil)
|
53
|
+
super(app)
|
54
|
+
@request_expectations = request_expectations
|
55
|
+
@response_expectations = response_expectations
|
56
|
+
end
|
57
|
+
|
58
|
+
def call(env)
|
59
|
+
|
60
|
+
@request_expectations.call(env) if @request_expectations.respond_to?(:call)
|
61
|
+
|
62
|
+
@app.call(env).on_complete do |env|
|
63
|
+
@response_expectations.call(env) if @response_expectations.respond_to?(:call)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
48
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday_middleware-escher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
@@ -80,20 +80,6 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: faraday_middleware
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
84
|
name: escher
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,11 +109,12 @@ files:
|
|
123
109
|
- Rakefile
|
124
110
|
- VERSION
|
125
111
|
- faraday_middleware-escher.gemspec
|
112
|
+
- lib/faraday/middleware/escher.rb
|
113
|
+
- lib/faraday/middleware/escher/base.rb
|
114
|
+
- lib/faraday/middleware/escher/request_signer.rb
|
115
|
+
- lib/faraday/middleware/escher/response_validator.rb
|
126
116
|
- lib/faraday_middleware/escher.rb
|
127
|
-
-
|
128
|
-
- lib/faraday_middleware/escher/request_signer.rb
|
129
|
-
- lib/faraday_middleware/escher/response_validator.rb
|
130
|
-
- spec/escher/base_middleware_spec.rb
|
117
|
+
- spec/escher/base_spec.rb
|
131
118
|
- spec/escher/request_signer_spec.rb
|
132
119
|
- spec/spec_helper.rb
|
133
120
|
homepage: https://github.com/adamluzsi/faraday_middleware-escher
|
@@ -155,6 +142,6 @@ signing_key:
|
|
155
142
|
specification_version: 4
|
156
143
|
summary: escher sign and validation for faraday http rest client
|
157
144
|
test_files:
|
158
|
-
- spec/escher/
|
145
|
+
- spec/escher/base_spec.rb
|
159
146
|
- spec/escher/request_signer_spec.rb
|
160
147
|
- spec/spec_helper.rb
|