faraday_middleware 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -24
- data/CHANGELOG.md +9 -9
- data/Gemfile +3 -3
- data/Gemfile.lock +38 -29
- data/README.md +42 -42
- data/Rakefile +14 -14
- data/faraday_middleware.gemspec +27 -24
- data/lib/faraday/mashify.rb +21 -25
- data/lib/faraday/multi_json.rb +27 -31
- data/lib/faraday/oauth2.rb +18 -21
- data/lib/faraday_middleware.rb +6 -6
- data/lib/faraday_middleware/version.rb +3 -3
- data/test/helper.rb +12 -12
- data/test/mashify_test.rb +35 -35
- data/test/multi_json_test.rb +75 -75
- data/test/oauth2_test.rb +18 -18
- metadata +69 -21
data/.gitignore
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
## MAC OS
|
2
|
-
.DS_Store
|
3
|
-
|
4
|
-
## TEXTMATE
|
5
|
-
*.tmproj
|
6
|
-
tmtags
|
7
|
-
|
8
|
-
## EMACS
|
9
|
-
*~
|
10
|
-
\#*
|
11
|
-
.\#*
|
12
|
-
|
13
|
-
## VIM
|
14
|
-
*.swp
|
15
|
-
|
16
|
-
## PROJECT::GENERAL
|
17
|
-
coverage
|
18
|
-
rdoc
|
19
|
-
pkg
|
20
|
-
*.gem
|
21
|
-
.yardopts
|
22
|
-
.yardoc
|
23
|
-
|
24
|
-
## PROJECT::SPECIFIC
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
*.gem
|
21
|
+
.yardopts
|
22
|
+
.yardoc
|
23
|
+
|
24
|
+
## PROJECT::SPECIFIC
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
# Changelog
|
2
|
-
|
3
|
-
### 0.0.2 September 25, 2010
|
4
|
-
|
5
|
-
* Mashify now handles arrays of non-hashes
|
6
|
-
|
7
|
-
### 0.0.1 June 27, 2010
|
8
|
-
|
9
|
-
* MultiJSON
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
### 0.0.2 September 25, 2010
|
4
|
+
|
5
|
+
* Mashify now handles arrays of non-hashes
|
6
|
+
|
7
|
+
### 0.0.1 June 27, 2010
|
8
|
+
|
9
|
+
* MultiJSON
|
10
10
|
* Mashify
|
data/Gemfile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
|
3
|
-
gemspec
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,29 +1,38 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
faraday_middleware (0.0.
|
5
|
-
faraday (~> 0.4.5)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
faraday_middleware (0.0.4)
|
5
|
+
faraday (~> 0.4.5)
|
6
|
+
hashie (~> 0.4.0)
|
7
|
+
multi_json (~> 0.0.4)
|
8
|
+
oauth2 (~> 0.0.13)
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: http://rubygems.org/
|
12
|
+
specs:
|
13
|
+
addressable (2.2.1)
|
14
|
+
faraday (0.4.6)
|
15
|
+
addressable (>= 2.1.1)
|
16
|
+
rack (>= 1.0.1)
|
17
|
+
hashie (0.4.0)
|
18
|
+
json (1.4.6)
|
19
|
+
multi_json (0.0.4)
|
20
|
+
oauth2 (0.0.13)
|
21
|
+
faraday (~> 0.4.1)
|
22
|
+
multi_json (>= 0.0.4)
|
23
|
+
rack (1.2.1)
|
24
|
+
rake (0.8.7)
|
25
|
+
shoulda (2.11.3)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
faraday (~> 0.4.5)
|
32
|
+
faraday_middleware!
|
33
|
+
hashie (~> 0.4.0)
|
34
|
+
json (~> 1.4.6)
|
35
|
+
multi_json (~> 0.0.4)
|
36
|
+
oauth2 (~> 0.0.13)
|
37
|
+
rake (~> 0.8.7)
|
38
|
+
shoulda (~> 2.11.3)
|
data/README.md
CHANGED
@@ -1,43 +1,43 @@
|
|
1
|
-
# Faraday Middleware
|
2
|
-
|
3
|
-
Collection of [Faraday](http://github.com/technoweenie/faraday) middlewares I've been using in some of my API wrappers
|
4
|
-
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
sudo gem install faraday-middleware
|
9
|
-
|
10
|
-
|
11
|
-
#### Some examples
|
12
|
-
|
13
|
-
Let's decode the response body with [MultiJson](http://github.com/intridea/multi_json)
|
14
|
-
|
15
|
-
conn = Faraday::Connection.new(:url => 'http://api.twitter.com/1') do |builder|
|
16
|
-
builder.adapter Faraday.default_adapter
|
17
|
-
builder.use Faraday::Response::MultiJson
|
18
|
-
end
|
19
|
-
|
20
|
-
resp = conn.get do |req|
|
21
|
-
req.url '/users/show.json', :screen_name => 'pengwynn'
|
22
|
-
end
|
23
|
-
|
24
|
-
u = resp.body
|
25
|
-
u['name']
|
26
|
-
# => "Wynn Netherland"
|
27
|
-
|
28
|
-
|
29
|
-
Want to ditch the brackets and use dot notation? [Mashify](http://github.com/intridea/hashie) it!
|
30
|
-
|
31
|
-
conn = Faraday::Connection.new(:url => 'http://api.twitter.com/1') do |builder|
|
32
|
-
builder.adapter Faraday.default_adapter
|
33
|
-
builder.use Faraday::Response::MultiJson
|
34
|
-
builder.use Faraday::Response::Mashify
|
35
|
-
end
|
36
|
-
|
37
|
-
resp = conn.get do |req|
|
38
|
-
req.url '/users/show.json', :screen_name => 'pengwynn'
|
39
|
-
end
|
40
|
-
|
41
|
-
u = resp.body
|
42
|
-
u.name
|
1
|
+
# Faraday Middleware
|
2
|
+
|
3
|
+
Collection of [Faraday](http://github.com/technoweenie/faraday) middlewares I've been using in some of my API wrappers
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
sudo gem install faraday-middleware
|
9
|
+
|
10
|
+
|
11
|
+
#### Some examples
|
12
|
+
|
13
|
+
Let's decode the response body with [MultiJson](http://github.com/intridea/multi_json)
|
14
|
+
|
15
|
+
conn = Faraday::Connection.new(:url => 'http://api.twitter.com/1') do |builder|
|
16
|
+
builder.adapter Faraday.default_adapter
|
17
|
+
builder.use Faraday::Response::MultiJson
|
18
|
+
end
|
19
|
+
|
20
|
+
resp = conn.get do |req|
|
21
|
+
req.url '/users/show.json', :screen_name => 'pengwynn'
|
22
|
+
end
|
23
|
+
|
24
|
+
u = resp.body
|
25
|
+
u['name']
|
26
|
+
# => "Wynn Netherland"
|
27
|
+
|
28
|
+
|
29
|
+
Want to ditch the brackets and use dot notation? [Mashify](http://github.com/intridea/hashie) it!
|
30
|
+
|
31
|
+
conn = Faraday::Connection.new(:url => 'http://api.twitter.com/1') do |builder|
|
32
|
+
builder.adapter Faraday.default_adapter
|
33
|
+
builder.use Faraday::Response::MultiJson
|
34
|
+
builder.use Faraday::Response::Mashify
|
35
|
+
end
|
36
|
+
|
37
|
+
resp = conn.get do |req|
|
38
|
+
req.url '/users/show.json', :screen_name => 'pengwynn'
|
39
|
+
end
|
40
|
+
|
41
|
+
u = resp.body
|
42
|
+
u.name
|
43
43
|
# => "Wynn Netherland"
|
data/Rakefile
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/testtask'
|
4
|
-
require 'bundler'
|
5
|
-
|
6
|
-
Bundler::GemHelper.install_tasks
|
7
|
-
|
8
|
-
Rake::TestTask.new(:test) do |test|
|
9
|
-
test.ruby_opts = ["-rubygems"] if defined? Gem
|
10
|
-
test.libs << "lib" << "test"
|
11
|
-
test.pattern = "test/**/*_test.rb"
|
12
|
-
end
|
13
|
-
|
14
|
-
task :default => :test
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
Bundler::GemHelper.install_tasks
|
7
|
+
|
8
|
+
Rake::TestTask.new(:test) do |test|
|
9
|
+
test.ruby_opts = ["-rubygems"] if defined? Gem
|
10
|
+
test.libs << "lib" << "test"
|
11
|
+
test.pattern = "test/**/*_test.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
task :default => :test
|
data/faraday_middleware.gemspec
CHANGED
@@ -1,24 +1,27 @@
|
|
1
|
-
require File.expand_path("../lib/faraday_middleware/version", __FILE__)
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.add_development_dependency('hashie', ['~> 0.4.0'])
|
5
|
-
s.add_development_dependency('
|
6
|
-
s.add_development_dependency('
|
7
|
-
s.add_development_dependency('
|
8
|
-
s.add_runtime_dependency('faraday', ['~> 0.4.5'])
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
s.
|
14
|
-
s.
|
15
|
-
s.
|
16
|
-
s.
|
17
|
-
s.
|
18
|
-
s.
|
19
|
-
s.
|
20
|
-
s.
|
21
|
-
s.
|
22
|
-
s.
|
23
|
-
s.
|
24
|
-
|
1
|
+
require File.expand_path("../lib/faraday_middleware/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.add_development_dependency('hashie', ['~> 0.4.0'])
|
5
|
+
s.add_development_dependency('json', ['~> 1.4.6'])
|
6
|
+
s.add_development_dependency('shoulda', ['~> 2.11.3'])
|
7
|
+
s.add_development_dependency('rake', ['~> 0.8.7'])
|
8
|
+
s.add_runtime_dependency('faraday', ['~> 0.4.5'])
|
9
|
+
s.add_runtime_dependency('hashie', ['~> 0.4.0'])
|
10
|
+
s.add_runtime_dependency('multi_json', ['~> 0.0.4'])
|
11
|
+
s.add_runtime_dependency('oauth2', ['~> 0.0.13'])
|
12
|
+
s.authors = ["Wynn Netherland"]
|
13
|
+
s.description = %q{Various middleware for Faraday}
|
14
|
+
s.email = ['wynn.netherland@gmail.com']
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.extra_rdoc_files = ["README.md"]
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.homepage = 'http://wynnnetherland.com/projects/faraday-middleware/'
|
19
|
+
s.name = 'faraday_middleware'
|
20
|
+
s.platform = Gem::Platform::RUBY
|
21
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
s.required_rubygems_version = ">= 1.3.6"
|
24
|
+
s.summary = %q{Various middleware for Faraday}
|
25
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
|
+
s.version = FaradayMiddleware::VERSION
|
27
|
+
end
|
data/lib/faraday/mashify.rb
CHANGED
@@ -1,25 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@parser = nil
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require 'hashie'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response::Mashify < Response::Middleware
|
5
|
+
def self.register_on_complete(env)
|
6
|
+
env[:response].on_complete do |response|
|
7
|
+
json = response[:body]
|
8
|
+
if json.is_a?(Hash)
|
9
|
+
response[:body] = Hashie::Mash.new(json)
|
10
|
+
elsif json.is_a?(Array) and json.first.is_a?(Hash)
|
11
|
+
response[:body] = json.map{|item| Hashie::Mash.new(item) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(app)
|
17
|
+
super
|
18
|
+
@parser = nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/faraday/multi_json.rb
CHANGED
@@ -1,31 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
@parser = nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response::MultiJson < Response::Middleware
|
5
|
+
def self.register_on_complete(env)
|
6
|
+
env[:response].on_complete do |response|
|
7
|
+
response[:body] = begin
|
8
|
+
case response[:body]
|
9
|
+
when ""
|
10
|
+
nil
|
11
|
+
when "true"
|
12
|
+
true
|
13
|
+
when "false"
|
14
|
+
false
|
15
|
+
else
|
16
|
+
MultiJson.decode(response[:body])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(app)
|
23
|
+
super
|
24
|
+
@parser = nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/faraday/oauth2.rb
CHANGED
@@ -1,21 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
require 'oauth2'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Request::OAuth2 < Faraday::Middleware
|
5
|
+
def initialize(app, *args)
|
6
|
+
@app = app
|
7
|
+
@token = args.shift
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
params = env[:url].query_values || {}
|
12
|
+
env[:url].query_values = params.merge('access_token' => @token)
|
13
|
+
env[:request_headers].merge!('Authorization' => "Token token=\"#{@token}\"")
|
14
|
+
|
15
|
+
@app.call env
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/faraday_middleware.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
directory = File.expand_path(File.dirname(__FILE__))
|
4
|
-
require File.join(directory, 'faraday', 'oauth2')
|
5
|
-
require File.join(directory, 'faraday', 'multi_json')
|
6
|
-
require File.join(directory, 'faraday', 'mashify')
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
4
|
+
require File.join(directory, 'faraday', 'oauth2')
|
5
|
+
require File.join(directory, 'faraday', 'multi_json')
|
6
|
+
require File.join(directory, 'faraday', 'mashify')
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module FaradayMiddleware
|
2
|
-
VERSION = "0.0.
|
3
|
-
end
|
1
|
+
module FaradayMiddleware
|
2
|
+
VERSION = "0.0.5"
|
3
|
+
end
|
data/test/helper.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'pathname'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'shoulda'
|
5
|
-
require 'faraday'
|
6
|
-
|
7
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
-
require 'faraday_middleware'
|
10
|
-
|
11
|
-
class Test::Unit::TestCase
|
12
|
-
end
|
1
|
+
require 'test/unit'
|
2
|
+
require 'pathname'
|
3
|
+
require 'rubygems'
|
4
|
+
require 'shoulda'
|
5
|
+
require 'faraday'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
8
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
9
|
+
require 'faraday_middleware'
|
10
|
+
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
end
|
data/test/mashify_test.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class MashifyTest < Test::Unit::TestCase
|
4
|
-
context 'when used' do
|
5
|
-
setup do
|
6
|
-
@stubs = Faraday::Adapter::Test::Stubs.new
|
7
|
-
@conn = Faraday::Connection.new do |builder|
|
8
|
-
builder.adapter :test, @stubs
|
9
|
-
builder.use Faraday::Response::MultiJson
|
10
|
-
builder.use Faraday::Response::Mashify
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
should 'create a Hashie::Mash from the body' do
|
15
|
-
@stubs.get('/hash') { [200, {}, "{\"name\":\"Wynn Netherland\",\"username\":\"pengwynn\"}"] }
|
16
|
-
me = @conn.get("/hash").body
|
17
|
-
assert_equal 'Wynn Netherland', me.name
|
18
|
-
assert_equal 'pengwynn', me.username
|
19
|
-
end
|
20
|
-
|
21
|
-
should 'handle arrays' do
|
22
|
-
@stubs.get('/array') { [200, {}, "[{\"username\":\"pengwynn\"},{\"username\":\"jnunemaker\"}]" ] }
|
23
|
-
us = @conn.get("/array").body
|
24
|
-
assert_equal 'pengwynn', us.first.username
|
25
|
-
assert_equal 'jnunemaker', us.last.username
|
26
|
-
end
|
27
|
-
|
28
|
-
should 'handle arrays of non-hashes' do
|
29
|
-
@stubs.get('/array/simple') { [200, {}, "[123, 456]" ] }
|
30
|
-
values = @conn.get("/array/simple").body
|
31
|
-
assert_equal 123, values.first
|
32
|
-
assert_equal 456, values.last
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class MashifyTest < Test::Unit::TestCase
|
4
|
+
context 'when used' do
|
5
|
+
setup do
|
6
|
+
@stubs = Faraday::Adapter::Test::Stubs.new
|
7
|
+
@conn = Faraday::Connection.new do |builder|
|
8
|
+
builder.adapter :test, @stubs
|
9
|
+
builder.use Faraday::Response::MultiJson
|
10
|
+
builder.use Faraday::Response::Mashify
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'create a Hashie::Mash from the body' do
|
15
|
+
@stubs.get('/hash') { [200, {}, "{\"name\":\"Wynn Netherland\",\"username\":\"pengwynn\"}"] }
|
16
|
+
me = @conn.get("/hash").body
|
17
|
+
assert_equal 'Wynn Netherland', me.name
|
18
|
+
assert_equal 'pengwynn', me.username
|
19
|
+
end
|
20
|
+
|
21
|
+
should 'handle arrays' do
|
22
|
+
@stubs.get('/array') { [200, {}, "[{\"username\":\"pengwynn\"},{\"username\":\"jnunemaker\"}]" ] }
|
23
|
+
us = @conn.get("/array").body
|
24
|
+
assert_equal 'pengwynn', us.first.username
|
25
|
+
assert_equal 'jnunemaker', us.last.username
|
26
|
+
end
|
27
|
+
|
28
|
+
should 'handle arrays of non-hashes' do
|
29
|
+
@stubs.get('/array/simple') { [200, {}, "[123, 456]" ] }
|
30
|
+
values = @conn.get("/array/simple").body
|
31
|
+
assert_equal 123, values.first
|
32
|
+
assert_equal 456, values.last
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/test/multi_json_test.rb
CHANGED
@@ -1,75 +1,75 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class Multi_Json_Test < Test::Unit::TestCase
|
4
|
-
context 'when used' do
|
5
|
-
setup do
|
6
|
-
@stubs = Faraday::Adapter::Test::Stubs.new
|
7
|
-
@conn = Faraday::Connection.new do |builder|
|
8
|
-
builder.adapter :test, @stubs
|
9
|
-
builder.use Faraday::Response::MultiJson
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "when there is a JSON body" do
|
14
|
-
setup do
|
15
|
-
@stubs.get('/me') { [200, {}, "{\"name\":\"Wynn Netherland\",\"username\":\"pengwynn\"}"] }
|
16
|
-
end
|
17
|
-
|
18
|
-
should 'parse the body as JSON' do
|
19
|
-
me = @conn.get("/me").body
|
20
|
-
assert me.is_a?(Hash)
|
21
|
-
assert_equal 'Wynn Netherland', me['name']
|
22
|
-
assert_equal 'pengwynn', me['username']
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "when the JSON body is empty" do
|
27
|
-
setup do
|
28
|
-
@stubs.get('/me') { [200, {}, ""] }
|
29
|
-
end
|
30
|
-
|
31
|
-
should 'still have the status code' do
|
32
|
-
response = @conn.get("/me")
|
33
|
-
assert_equal 200, response.status
|
34
|
-
end
|
35
|
-
|
36
|
-
should 'set body to nil' do
|
37
|
-
response = @conn.get("/me")
|
38
|
-
assert_equal response.body, nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when the JSON body is 'true'" do
|
43
|
-
setup do
|
44
|
-
@stubs.get('/me') { [200, {}, "true"] }
|
45
|
-
end
|
46
|
-
|
47
|
-
should 'still have the status code' do
|
48
|
-
response = @conn.get("/me")
|
49
|
-
assert_equal 200, response.status
|
50
|
-
end
|
51
|
-
|
52
|
-
should 'set body to nil' do
|
53
|
-
response = @conn.get("/me")
|
54
|
-
assert_equal response.body, true
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "when the JSON body is 'false'" do
|
59
|
-
setup do
|
60
|
-
@stubs.get('/me') { [200, {}, "false"] }
|
61
|
-
end
|
62
|
-
|
63
|
-
should 'still have the status code' do
|
64
|
-
response = @conn.get("/me")
|
65
|
-
assert_equal 200, response.status
|
66
|
-
end
|
67
|
-
|
68
|
-
should 'set body to nil' do
|
69
|
-
response = @conn.get("/me")
|
70
|
-
assert_equal response.body, false
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class Multi_Json_Test < Test::Unit::TestCase
|
4
|
+
context 'when used' do
|
5
|
+
setup do
|
6
|
+
@stubs = Faraday::Adapter::Test::Stubs.new
|
7
|
+
@conn = Faraday::Connection.new do |builder|
|
8
|
+
builder.adapter :test, @stubs
|
9
|
+
builder.use Faraday::Response::MultiJson
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when there is a JSON body" do
|
14
|
+
setup do
|
15
|
+
@stubs.get('/me') { [200, {}, "{\"name\":\"Wynn Netherland\",\"username\":\"pengwynn\"}"] }
|
16
|
+
end
|
17
|
+
|
18
|
+
should 'parse the body as JSON' do
|
19
|
+
me = @conn.get("/me").body
|
20
|
+
assert me.is_a?(Hash)
|
21
|
+
assert_equal 'Wynn Netherland', me['name']
|
22
|
+
assert_equal 'pengwynn', me['username']
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when the JSON body is empty" do
|
27
|
+
setup do
|
28
|
+
@stubs.get('/me') { [200, {}, ""] }
|
29
|
+
end
|
30
|
+
|
31
|
+
should 'still have the status code' do
|
32
|
+
response = @conn.get("/me")
|
33
|
+
assert_equal 200, response.status
|
34
|
+
end
|
35
|
+
|
36
|
+
should 'set body to nil' do
|
37
|
+
response = @conn.get("/me")
|
38
|
+
assert_equal response.body, nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when the JSON body is 'true'" do
|
43
|
+
setup do
|
44
|
+
@stubs.get('/me') { [200, {}, "true"] }
|
45
|
+
end
|
46
|
+
|
47
|
+
should 'still have the status code' do
|
48
|
+
response = @conn.get("/me")
|
49
|
+
assert_equal 200, response.status
|
50
|
+
end
|
51
|
+
|
52
|
+
should 'set body to nil' do
|
53
|
+
response = @conn.get("/me")
|
54
|
+
assert_equal response.body, true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when the JSON body is 'false'" do
|
59
|
+
setup do
|
60
|
+
@stubs.get('/me') { [200, {}, "false"] }
|
61
|
+
end
|
62
|
+
|
63
|
+
should 'still have the status code' do
|
64
|
+
response = @conn.get("/me")
|
65
|
+
assert_equal 200, response.status
|
66
|
+
end
|
67
|
+
|
68
|
+
should 'set body to nil' do
|
69
|
+
response = @conn.get("/me")
|
70
|
+
assert_equal response.body, false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
data/test/oauth2_test.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class OAuth2Test < Test::Unit::TestCase
|
4
|
-
context 'when used' do
|
5
|
-
setup do
|
6
|
-
@stubs = Faraday::Adapter::Test::Stubs.new
|
7
|
-
@stubs.get('/me?access_token=OU812') { [200, {}, 'pengwynn'] }
|
8
|
-
end
|
9
|
-
|
10
|
-
should 'add the access token to the request' do
|
11
|
-
do_you = Faraday::Connection.new do |builder|
|
12
|
-
builder.use Faraday::Request::OAuth2, 'OU812'
|
13
|
-
builder.adapter :test, @stubs
|
14
|
-
end
|
15
|
-
do_you.get("/me")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class OAuth2Test < Test::Unit::TestCase
|
4
|
+
context 'when used' do
|
5
|
+
setup do
|
6
|
+
@stubs = Faraday::Adapter::Test::Stubs.new
|
7
|
+
@stubs.get('/me?access_token=OU812') { [200, {}, 'pengwynn'] }
|
8
|
+
end
|
9
|
+
|
10
|
+
should 'add the access token to the request' do
|
11
|
+
do_you = Faraday::Connection.new do |builder|
|
12
|
+
builder.use Faraday::Request::OAuth2, 'OU812'
|
13
|
+
builder.adapter :test, @stubs
|
14
|
+
end
|
15
|
+
do_you.get("/me")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday_middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Wynn Netherland
|
@@ -35,51 +35,51 @@ dependencies:
|
|
35
35
|
type: :development
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: json
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
45
|
+
hash: 11
|
46
46
|
segments:
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
version:
|
47
|
+
- 1
|
48
|
+
- 4
|
49
|
+
- 6
|
50
|
+
version: 1.4.6
|
51
51
|
type: :development
|
52
52
|
version_requirements: *id002
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: shoulda
|
55
55
|
prerelease: false
|
56
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
57
|
none: false
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
61
|
+
hash: 37
|
62
62
|
segments:
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
version:
|
63
|
+
- 2
|
64
|
+
- 11
|
65
|
+
- 3
|
66
|
+
version: 2.11.3
|
67
67
|
type: :development
|
68
68
|
version_requirements: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rake
|
71
71
|
prerelease: false
|
72
72
|
requirement: &id004 !ruby/object:Gem::Requirement
|
73
73
|
none: false
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
hash:
|
77
|
+
hash: 49
|
78
78
|
segments:
|
79
|
-
-
|
80
|
-
-
|
81
|
-
-
|
82
|
-
version:
|
79
|
+
- 0
|
80
|
+
- 8
|
81
|
+
- 7
|
82
|
+
version: 0.8.7
|
83
83
|
type: :development
|
84
84
|
version_requirements: *id004
|
85
85
|
- !ruby/object:Gem::Dependency
|
@@ -98,6 +98,54 @@ dependencies:
|
|
98
98
|
version: 0.4.5
|
99
99
|
type: :runtime
|
100
100
|
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: hashie
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 15
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
- 4
|
113
|
+
- 0
|
114
|
+
version: 0.4.0
|
115
|
+
type: :runtime
|
116
|
+
version_requirements: *id006
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: multi_json
|
119
|
+
prerelease: false
|
120
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 23
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
- 0
|
129
|
+
- 4
|
130
|
+
version: 0.0.4
|
131
|
+
type: :runtime
|
132
|
+
version_requirements: *id007
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: oauth2
|
135
|
+
prerelease: false
|
136
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
hash: 5
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
- 0
|
145
|
+
- 13
|
146
|
+
version: 0.0.13
|
147
|
+
type: :runtime
|
148
|
+
version_requirements: *id008
|
101
149
|
description: Various middleware for Faraday
|
102
150
|
email:
|
103
151
|
- wynn.netherland@gmail.com
|