foauth 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +26 -1
- data/lib/foauth/version.rb +1 -1
- data/lib/foauth.rb +2 -1
- data/spec/client_spec.rb +14 -0
- data/spec/middleware_spec.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -50,9 +50,34 @@ more information.
|
|
50
50
|
4. Push to the branch (`git push origin my-new-feature`)
|
51
51
|
5. Create new Pull Request
|
52
52
|
|
53
|
+
## Version history
|
54
|
+
|
55
|
+
**0.2.1** (January 5, 2013)
|
56
|
+
|
57
|
+
* Make sure client works without blocks
|
58
|
+
([#3](https://github.com/hecticjeff/foauth/issues/3))
|
59
|
+
|
60
|
+
**0.2.0** (January 5, 2013)
|
61
|
+
|
62
|
+
* Allow client to accept a block to configure Faraday
|
63
|
+
([#2](https://github.com/hecticjeff/foauth/issues/2))
|
64
|
+
|
65
|
+
**0.1.0** (January 5, 2013)
|
66
|
+
|
67
|
+
* Make sure query string is passed through to foauth
|
68
|
+
([#1](https://github.com/hecticjeff/foauth/issues/1))
|
69
|
+
|
70
|
+
**0.0.1** (January 3, 2013)
|
71
|
+
|
72
|
+
* Initial release
|
73
|
+
|
53
74
|
## Credits
|
54
75
|
|
55
|
-
|
76
|
+
Thanks to [@gulopine](https://github.com/gulopine) for creating
|
77
|
+
[foauth.org][foauth].
|
78
|
+
|
79
|
+
Inspired by [requests-foauth][] by
|
80
|
+
[@kennethreitz](https://github.com/kennethreitz).
|
56
81
|
|
57
82
|
Copyright (c) Chris Mytton
|
58
83
|
|
data/lib/foauth/version.rb
CHANGED
data/lib/foauth.rb
CHANGED
@@ -4,11 +4,12 @@ require 'foauth/version'
|
|
4
4
|
require 'foauth/rewrite_middleware'
|
5
5
|
|
6
6
|
module Foauth
|
7
|
-
def self.new(email, password)
|
7
|
+
def self.new(email, password, &block)
|
8
8
|
Faraday.new do |builder|
|
9
9
|
builder.request :basic_auth, email, password
|
10
10
|
builder.use RewriteMiddleware
|
11
11
|
builder.adapter Faraday.default_adapter
|
12
|
+
block.call(builder) if block_given?
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
data/spec/client_spec.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Foauth do
|
4
|
+
class TestMiddleware < Faraday::Middleware
|
5
|
+
def call(env)
|
6
|
+
env['foo'] = 'bar'
|
7
|
+
@app.call(env)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
4
11
|
let(:client) { Foauth.new('bob@example.org', '123') }
|
5
12
|
let(:response) { client.get('https://api.twitter.com/1/statuses/user_timeline.json') }
|
6
13
|
let(:request_headers) { response.env[:request_headers] }
|
@@ -14,4 +21,11 @@ describe Foauth do
|
|
14
21
|
it "authenticates with email and password" do
|
15
22
|
expect(request_headers['Authorization']).to eq 'Basic Ym9iQGV4YW1wbGUub3JnOjEyMw=='
|
16
23
|
end
|
24
|
+
|
25
|
+
describe "with a block" do
|
26
|
+
let(:client) { Foauth.new('bob@example.org', '123') { |builder| builder.use TestMiddleware } }
|
27
|
+
it "runs the given block" do
|
28
|
+
expect(response.env['foo']).to eq 'bar'
|
29
|
+
end
|
30
|
+
end
|
17
31
|
end
|
data/spec/middleware_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Foauth::RewriteMiddleware do
|
4
4
|
let(:conn) do
|
5
|
-
|
5
|
+
Faraday.new do |builder|
|
6
6
|
builder.use Foauth::RewriteMiddleware
|
7
7
|
builder.adapter :test do |stub|
|
8
8
|
stub.get('/api.twitter.com/1/statuses/user_timeline.json') {[ 200, {}, '{}' ]}
|