foauth 0.2.1 → 0.2.2
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/.yardopts +1 -0
- data/README.md +32 -2
- data/lib/foauth.rb +26 -5
- data/lib/foauth/version.rb +1 -1
- data/spec/middleware_spec.rb +2 -2
- metadata +4 -3
- data/lib/foauth/rewrite_middleware.rb +0 -12
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown
|
data/README.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
[foauth.org][foauth] Ruby client built on top of [faraday][].
|
4
4
|
|
5
|
+
## Prerequisites
|
6
|
+
|
7
|
+
To use this gem you'll need to go to [foauth.org][foauth] and register
|
8
|
+
for an account, then go to the [services page][foauth services] and
|
9
|
+
authenticate with the services you want to get your data out of.
|
10
|
+
|
5
11
|
## Installation
|
6
12
|
|
7
13
|
Add this line to your application's Gemfile:
|
@@ -38,9 +44,29 @@ puts response.body # [{"created_at":"Mon Dec 31 23:59:13 +0000 2012"...
|
|
38
44
|
puts response.status # 200
|
39
45
|
```
|
40
46
|
|
47
|
+
### Faraday
|
48
|
+
|
41
49
|
The `client` returned is an instance of `Faraday::Connection` and the
|
42
|
-
`response` is an instance of `Faraday::Response`.
|
43
|
-
|
50
|
+
`response` is an instance of `Faraday::Response`.
|
51
|
+
|
52
|
+
You can pass a block to `Foauth.new` which will yield a
|
53
|
+
`Faraday::Builder` instance. This allows you to customize middleware
|
54
|
+
and change the default http adapter.
|
55
|
+
|
56
|
+
For example, if you want `response.body` to be automatically decoded for
|
57
|
+
you then add `faraday_middleware` to your `Gemfile` and use the
|
58
|
+
following code to add the json and xml parsing middleware.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require 'faraday_middleware'
|
62
|
+
|
63
|
+
client = Foauth.new 'bob@example.org', 'secret' do |builder|
|
64
|
+
builder.response :json, :content_type => /\bjson$/
|
65
|
+
builder.response :xml, :content_type => /\bxml$/
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
See [faraday][] for more information.
|
44
70
|
|
45
71
|
## Contributing
|
46
72
|
|
@@ -52,6 +78,10 @@ more information.
|
|
52
78
|
|
53
79
|
## Version history
|
54
80
|
|
81
|
+
**0.2.2** (January 6, 2013)
|
82
|
+
|
83
|
+
* Documentation updates
|
84
|
+
|
55
85
|
**0.2.1** (January 5, 2013)
|
56
86
|
|
57
87
|
* Make sure client works without blocks
|
data/lib/foauth.rb
CHANGED
@@ -1,15 +1,36 @@
|
|
1
1
|
require 'faraday'
|
2
|
-
|
3
2
|
require 'foauth/version'
|
4
|
-
require 'foauth/rewrite_middleware'
|
5
3
|
|
6
4
|
module Foauth
|
7
|
-
|
5
|
+
Faraday.register_middleware :request, :foauth_proxy => lambda { Proxy }
|
6
|
+
|
7
|
+
# Creates a new `Faraday` instance using the given `email` and `password`.
|
8
|
+
#
|
9
|
+
# @param [String] email Your foauth.org email address.
|
10
|
+
# @param [String] password Your foauth.org password.
|
11
|
+
# @yield [builder] Passes the `Faraday::Builder` instance to the block if given.
|
12
|
+
# @return [Faraday::Connection] Configured to proxy requests to foauth.org.
|
13
|
+
def self.new(email, password)
|
8
14
|
Faraday.new do |builder|
|
15
|
+
builder.request :foauth_proxy
|
9
16
|
builder.request :basic_auth, email, password
|
10
|
-
builder.use RewriteMiddleware
|
11
17
|
builder.adapter Faraday.default_adapter
|
12
|
-
|
18
|
+
yield builder if block_given?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Proxy < Faraday::Middleware
|
23
|
+
def call(env)
|
24
|
+
env[:url] = foauth_proxy_url(env[:url])
|
25
|
+
@app.call(env)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def foauth_proxy_url(url)
|
31
|
+
uri = URI.parse("https://foauth.org/#{url.host}#{url.path}")
|
32
|
+
uri.query = url.query
|
33
|
+
uri
|
13
34
|
end
|
14
35
|
end
|
15
36
|
end
|
data/lib/foauth/version.rb
CHANGED
data/spec/middleware_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Foauth::
|
3
|
+
describe Foauth::Proxy do
|
4
4
|
let(:conn) do
|
5
5
|
Faraday.new do |builder|
|
6
|
-
builder.
|
6
|
+
builder.request :foauth_proxy
|
7
7
|
builder.adapter :test do |stub|
|
8
8
|
stub.get('/api.twitter.com/1/statuses/user_timeline.json') {[ 200, {}, '{}' ]}
|
9
9
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foauth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -52,13 +52,13 @@ extra_rdoc_files: []
|
|
52
52
|
files:
|
53
53
|
- .gitignore
|
54
54
|
- .rspec
|
55
|
+
- .yardopts
|
55
56
|
- Gemfile
|
56
57
|
- LICENSE.txt
|
57
58
|
- README.md
|
58
59
|
- Rakefile
|
59
60
|
- foauth.gemspec
|
60
61
|
- lib/foauth.rb
|
61
|
-
- lib/foauth/rewrite_middleware.rb
|
62
62
|
- lib/foauth/version.rb
|
63
63
|
- spec/client_spec.rb
|
64
64
|
- spec/middleware_spec.rb
|
@@ -91,3 +91,4 @@ test_files:
|
|
91
91
|
- spec/client_spec.rb
|
92
92
|
- spec/middleware_spec.rb
|
93
93
|
- spec/spec_helper.rb
|
94
|
+
has_rdoc:
|