faraday_middleware 0.3.2 → 0.6.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/.rspec +3 -0
- data/LICENSE.md +20 -0
- data/Rakefile +4 -10
- data/faraday_middleware.gemspec +28 -21
- data/lib/faraday/request/oauth.rb +23 -0
- data/lib/faraday/{oauth2.rb → request/oauth2.rb} +7 -7
- data/lib/faraday/response/mashify.rb +24 -0
- data/lib/faraday/response/parse_json.rb +20 -0
- data/lib/faraday/response/parse_xml.rb +11 -0
- data/lib/faraday_middleware.rb +11 -3
- data/lib/faraday_middleware/support/rash.rb +26 -0
- data/lib/faraday_middleware/version.rb +1 -1
- data/spec/helper.rb +25 -0
- data/spec/mashify_spec.rb +85 -0
- data/spec/oauth2_spec.rb +50 -0
- data/spec/oauth_spec.rb +46 -0
- data/spec/parse_json_spec.rb +69 -0
- data/spec/parse_xml_spec.rb +39 -0
- metadata +47 -39
- data/lib/faraday/mashify.rb +0 -27
- data/lib/faraday/parse_json.rb +0 -33
- data/lib/faraday/parse_xml.rb +0 -24
- data/test/helper.rb +0 -9
- data/test/mashify_test.rb +0 -43
- data/test/oauth2_test.rb +0 -18
- data/test/parse_json_test.rb +0 -74
- data/test/parse_xml_test.rb +0 -56
data/.rspec
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Erik Michaels-Ober, Wynn Netherland, et al.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,14 +1,8 @@
|
|
1
|
-
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
2
|
-
require 'rake'
|
3
|
-
require 'rake/testtask'
|
4
1
|
require 'bundler'
|
5
|
-
|
6
2
|
Bundler::GemHelper.install_tasks
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
test.libs << "lib" << "test"
|
11
|
-
test.pattern = "test/**/*_test.rb"
|
12
|
-
end
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
13
6
|
|
14
|
-
task :
|
7
|
+
task :test => :spec
|
8
|
+
task :default => :spec
|
data/faraday_middleware.gemspec
CHANGED
@@ -1,29 +1,36 @@
|
|
1
1
|
require File.expand_path('../lib/faraday_middleware/version', __FILE__)
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
|
-
s.add_development_dependency('hashie', '~> 1.0')
|
5
|
-
s.add_development_dependency('json', '~> 1.4')
|
6
|
-
s.add_development_dependency('multi_json', '~> 0.0')
|
7
|
-
s.add_development_dependency('multi_xml', '~> 0.2')
|
8
|
-
s.add_development_dependency('oauth2', '~> 0.1')
|
9
|
-
s.add_development_dependency('rake', '~> 0.8')
|
10
|
-
s.add_development_dependency('shoulda', '~> 2.11')
|
11
|
-
s.add_development_dependency('simplecov', '~> 0.3')
|
12
|
-
s.add_development_dependency('test-unit', '~> 2.1')
|
13
|
-
s.add_runtime_dependency('faraday', '~> 0.5.4')
|
14
|
-
s.authors = ["Wynn Netherland"]
|
15
|
-
s.description = %q{Various middleware for Faraday}
|
16
|
-
s.email = ['wynn.netherland@gmail.com']
|
17
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
18
|
-
s.extra_rdoc_files = ["README.md"]
|
19
|
-
s.files = `git ls-files`.split("\n")
|
20
|
-
s.homepage = 'http://wynnnetherland.com/projects/faraday-middleware/'
|
21
4
|
s.name = 'faraday_middleware'
|
5
|
+
s.summary = %q{Various middleware for Faraday}
|
6
|
+
s.description = s.summary
|
7
|
+
|
8
|
+
s.homepage = 'http://wynnnetherland.com/projects/faraday-middleware/'
|
9
|
+
|
10
|
+
s.authors = ["Erik Michaels-Ober", "Wynn Netherland"]
|
11
|
+
s.email = ['sferik@gmail.com', 'wynn.netherland@gmail.com']
|
12
|
+
|
13
|
+
s.version = FaradayMiddleware::VERSION
|
22
14
|
s.platform = Gem::Platform::RUBY
|
23
|
-
|
15
|
+
|
24
16
|
s.require_paths = ['lib']
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
|
21
|
+
s.extra_rdoc_files = ["README.md"]
|
22
|
+
s.rdoc_options = ['--charset=UTF-8']
|
23
|
+
|
25
24
|
s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
|
26
|
-
|
27
|
-
s.
|
28
|
-
s.
|
25
|
+
|
26
|
+
s.add_runtime_dependency('faraday', '~> 0.6.0')
|
27
|
+
s.add_development_dependency('rake', '~> 0.8')
|
28
|
+
s.add_development_dependency('rspec', '~> 2.5')
|
29
|
+
s.add_development_dependency('simplecov', '~> 0.4')
|
30
|
+
s.add_development_dependency('hashie', '~> 1.0')
|
31
|
+
s.add_development_dependency('json_pure', '~> 1.5')
|
32
|
+
s.add_development_dependency('multi_json', '~> 0.0')
|
33
|
+
s.add_development_dependency('multi_xml', '~> 0.2')
|
34
|
+
s.add_development_dependency('oauth2', '~> 0.2')
|
35
|
+
s.add_development_dependency('simple_oauth', '~> 0.1')
|
29
36
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Request::OAuth < Faraday::Middleware
|
5
|
+
dependency 'simple_oauth'
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
params = env[:body].is_a?(Hash) ? env[:body] : {}
|
9
|
+
|
10
|
+
signature_params = params.reject{ |k,v| v.respond_to?(:content_type) }
|
11
|
+
|
12
|
+
header = SimpleOAuth::Header.new(env[:method], env[:url], signature_params, @options)
|
13
|
+
|
14
|
+
env[:request_headers]['Authorization'] = header.to_s
|
15
|
+
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(app, options)
|
20
|
+
@app, @options = app, options
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -2,16 +2,16 @@ require 'faraday'
|
|
2
2
|
|
3
3
|
module Faraday
|
4
4
|
class Request::OAuth2 < Faraday::Middleware
|
5
|
-
|
6
|
-
require 'oauth2'
|
7
|
-
rescue LoadError, NameError => error
|
8
|
-
self.load_error = error
|
9
|
-
end
|
5
|
+
dependency 'oauth2'
|
10
6
|
|
11
7
|
def call(env)
|
12
8
|
params = env[:url].query_values || {}
|
13
|
-
|
14
|
-
env[:
|
9
|
+
|
10
|
+
env[:url].query_values = { 'access_token' => @token }.merge(params)
|
11
|
+
|
12
|
+
token = env[:url].query_values['access_token']
|
13
|
+
|
14
|
+
env[:request_headers].merge!('Authorization' => "Token token=\"#{token}\"")
|
15
15
|
|
16
16
|
@app.call env
|
17
17
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response::Mashify < Response::Middleware
|
5
|
+
dependency 'faraday_middleware/support/rash'
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :mash_class
|
9
|
+
end
|
10
|
+
|
11
|
+
self.mash_class = ::Hashie::Rash
|
12
|
+
|
13
|
+
def parse(body)
|
14
|
+
case body
|
15
|
+
when Hash
|
16
|
+
self.class.mash_class.new(body)
|
17
|
+
when Array
|
18
|
+
body.map { |item| item.is_a?(Hash) ? self.class.mash_class.new(item) : item }
|
19
|
+
else
|
20
|
+
body
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response::ParseJson < Response::Middleware
|
5
|
+
dependency 'multi_json'
|
6
|
+
|
7
|
+
def parse(body)
|
8
|
+
case body
|
9
|
+
when ''
|
10
|
+
nil
|
11
|
+
when 'true'
|
12
|
+
true
|
13
|
+
when 'false'
|
14
|
+
false
|
15
|
+
else
|
16
|
+
::MultiJson.decode(body)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/faraday_middleware.rb
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
class Faraday::Request
|
4
|
+
autoload :OAuth, 'faraday/request/oauth'
|
5
|
+
autoload :OAuth2, 'faraday/request/oauth2'
|
6
|
+
end
|
7
|
+
|
8
|
+
class Faraday::Response
|
9
|
+
autoload :Mashify, 'faraday/response/mashify'
|
10
|
+
autoload :ParseJson, 'faraday/response/parse_json'
|
11
|
+
autoload :ParseXml, 'faraday/response/parse_xml'
|
4
12
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'hashie/mash'
|
2
|
+
|
3
|
+
module Hashie
|
4
|
+
class Rash < Mash
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def convert_key(key) #:nodoc:
|
9
|
+
underscore_string(key.to_s)
|
10
|
+
end
|
11
|
+
|
12
|
+
# converts a camel_cased string to a underscore string
|
13
|
+
# subs spaces with underscores, strips whitespace
|
14
|
+
# Same way ActiveSupport does string.underscore
|
15
|
+
def underscore_string(str)
|
16
|
+
str.to_s.strip.
|
17
|
+
gsub(' ', '_').
|
18
|
+
gsub(/::/, '/').
|
19
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
20
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
21
|
+
tr("-", "_").
|
22
|
+
downcase
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'although not required, its recommended you use bundler when running the tests'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'simplecov'
|
8
|
+
SimpleCov.start
|
9
|
+
|
10
|
+
require 'rspec'
|
11
|
+
|
12
|
+
require 'faraday_middleware'
|
13
|
+
|
14
|
+
|
15
|
+
class DummyApp
|
16
|
+
attr_accessor :env
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
@env = env
|
20
|
+
end
|
21
|
+
|
22
|
+
def reset
|
23
|
+
@env = nil
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Faraday::Response::Mashify do
|
4
|
+
context 'during configuration' do
|
5
|
+
it 'should allow for a custom Mash class to be set' do
|
6
|
+
Faraday::Response::Mashify.should respond_to(:mash_class)
|
7
|
+
Faraday::Response::Mashify.should respond_to(:mash_class=)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when used' do
|
12
|
+
before(:each) { Faraday::Response::Mashify.mash_class = ::Hashie::Rash }
|
13
|
+
let(:mashify) { Faraday::Response::Mashify.new }
|
14
|
+
|
15
|
+
it 'should create a Hashie::Rash from the body' do
|
16
|
+
env = { :body => { "name" => "Erik Michaels-Ober", "username" => "sferik" } }
|
17
|
+
me = mashify.on_complete(env)
|
18
|
+
me.class.should == Hashie::Rash
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should handle strings' do
|
22
|
+
env = { :body => "Most amazing string EVER" }
|
23
|
+
me = mashify.on_complete(env)
|
24
|
+
me.should == "Most amazing string EVER"
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should handle hashes and decamelcase the keys' do
|
28
|
+
env = { :body => { "name" => "Erik Michaels-Ober", "userName" => "sferik" } }
|
29
|
+
me = mashify.on_complete(env)
|
30
|
+
me.name.should == 'Erik Michaels-Ober'
|
31
|
+
me.user_name.should == 'sferik'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should handle arrays' do
|
35
|
+
env = { :body => [123, 456] }
|
36
|
+
values = mashify.on_complete(env)
|
37
|
+
values.first.should == 123
|
38
|
+
values.last.should == 456
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should handle arrays of hashes' do
|
42
|
+
env = { :body => [{ "username" => "sferik" }, { "username" => "pengwynn" }] }
|
43
|
+
us = mashify.on_complete(env)
|
44
|
+
us.first.username.should == 'sferik'
|
45
|
+
us.last.username.should == 'pengwynn'
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should handle mixed arrays' do
|
49
|
+
env = { :body => [123, { "username" => "sferik" }, 456] }
|
50
|
+
values = mashify.on_complete(env)
|
51
|
+
values.first.should == 123
|
52
|
+
values.last.should == 456
|
53
|
+
values[1].username.should == 'sferik'
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should allow for use of custom Mash subclasses' do
|
57
|
+
class MyMash < ::Hashie::Mash; end
|
58
|
+
Faraday::Response::Mashify.mash_class = MyMash
|
59
|
+
|
60
|
+
env = { :body => { "name" => "Erik Michaels-Ober", "username" => "sferik" } }
|
61
|
+
me = mashify.on_complete(env)
|
62
|
+
|
63
|
+
me.class.should == MyMash
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'integration test' do
|
68
|
+
let(:stubs) { Faraday::Adapter::Test::Stubs.new }
|
69
|
+
let(:connection) do
|
70
|
+
Faraday::Connection.new do |builder|
|
71
|
+
builder.adapter :test, stubs
|
72
|
+
builder.use Faraday::Response::Mashify
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# although it is not good practice to pass a hash as the body, if we add ParseJson
|
77
|
+
# to the middleware stack we end up testing two middlewares instead of one
|
78
|
+
it 'should create a Hash from the body' do
|
79
|
+
stubs.get('/hash') {[200, {'content-type' => 'application/json; charset=utf-8'}, { "name" => "Erik Michaels-Ober", "username" => "sferik" }]}
|
80
|
+
me = connection.get('/hash').body
|
81
|
+
me.name.should == 'Erik Michaels-Ober'
|
82
|
+
me.username.should == 'sferik'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
data/spec/oauth2_spec.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Faraday::Request::OAuth2 do
|
4
|
+
|
5
|
+
context 'when used with a access token in the initializer' do
|
6
|
+
let(:oauth2) { Faraday::Request::OAuth2.new(DummyApp.new, '1234') }
|
7
|
+
|
8
|
+
it 'should add the access token to the request' do
|
9
|
+
env = {
|
10
|
+
:request_headers => {},
|
11
|
+
:url => Addressable::URI.parse('http://www.github.com')
|
12
|
+
}
|
13
|
+
|
14
|
+
request = oauth2.call(env)
|
15
|
+
request[:request_headers]["Authorization"].should == "Token token=\"1234\""
|
16
|
+
request[:url].query_values["access_token"].should == "1234"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'when used with a access token in the query_values' do
|
21
|
+
let(:oauth2) { Faraday::Request::OAuth2.new(DummyApp.new) }
|
22
|
+
|
23
|
+
it 'should add the access token to the request' do
|
24
|
+
env = {
|
25
|
+
:request_headers => {},
|
26
|
+
:url => Addressable::URI.parse('http://www.github.com/?access_token=1234')
|
27
|
+
}
|
28
|
+
|
29
|
+
request = oauth2.call(env)
|
30
|
+
request[:request_headers]["Authorization"].should == "Token token=\"1234\""
|
31
|
+
request[:url].query_values["access_token"].should == "1234"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'integration test' do
|
36
|
+
let(:stubs) { Faraday::Adapter::Test::Stubs.new }
|
37
|
+
let(:connection) do
|
38
|
+
Faraday::Connection.new do |builder|
|
39
|
+
builder.use Faraday::Request::OAuth2, '1234'
|
40
|
+
builder.adapter :test, stubs
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should add the access token to the query string' do
|
45
|
+
stubs.get('/me?access_token=1234') {[200, {}, 'sferik']}
|
46
|
+
me = connection.get('/me')
|
47
|
+
me.body.should == 'sferik'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/spec/oauth_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Faraday::Request::OAuth do
|
4
|
+
OAUTH_HEADER_REGEX = /^OAuth oauth_consumer_key=\"\d{4}\", oauth_nonce=\".+\", oauth_signature=\".+\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"\d{10}\", oauth_token=\"\d{4}\", oauth_version=\"1\.0\"/
|
5
|
+
|
6
|
+
let(:config) do
|
7
|
+
{
|
8
|
+
:consumer_key => '1234',
|
9
|
+
:consumer_secret => '1234',
|
10
|
+
:token => '1234',
|
11
|
+
:token_secret => '1234'
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when used' do
|
16
|
+
let(:oauth) { Faraday::Request::OAuth.new(DummyApp.new, config) }
|
17
|
+
|
18
|
+
let(:env) do
|
19
|
+
{ :request_headers => {}, :url => Addressable::URI.parse('http://www.github.com') }
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should add the access token to the header' do
|
23
|
+
request = oauth.call(env)
|
24
|
+
request[:request_headers]["Authorization"].should match OAUTH_HEADER_REGEX
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
context 'integration test' do
|
30
|
+
let(:stubs) { Faraday::Adapter::Test::Stubs.new }
|
31
|
+
let(:connection) do
|
32
|
+
Faraday::Connection.new do |builder|
|
33
|
+
builder.use Faraday::Request::OAuth, config
|
34
|
+
builder.adapter :test, stubs
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Sadly we can not check the headers in this integration test, but this will
|
39
|
+
# confirm that the middleware doesn't break the stack
|
40
|
+
it 'should add the access token to the query string' do
|
41
|
+
stubs.get('/me') {[200, {}, 'sferik']}
|
42
|
+
me = connection.get('http://www.github.com/me')
|
43
|
+
me.body.should == 'sferik'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Faraday::Response::ParseJson do
|
4
|
+
context 'when used' do
|
5
|
+
let(:multi_json) { Faraday::Response::ParseJson.new }
|
6
|
+
|
7
|
+
it 'should handle a blank response' do
|
8
|
+
empty = multi_json.on_complete(:body => '')
|
9
|
+
empty.should be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should handle a true response' do
|
13
|
+
response = multi_json.on_complete(:body => 'true')
|
14
|
+
response.should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should handle a false response' do
|
18
|
+
response = multi_json.on_complete(:body => 'false')
|
19
|
+
response.should be_false
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should handle hashes' do
|
23
|
+
me = multi_json.on_complete(:body => '{"name":"Erik Michaels-Ober","screen_name":"sferik"}')
|
24
|
+
me.class.should == Hash
|
25
|
+
me['name'].should == 'Erik Michaels-Ober'
|
26
|
+
me['screen_name'].should == 'sferik'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should handle arrays' do
|
30
|
+
values = multi_json.on_complete(:body => '[123, 456]')
|
31
|
+
values.class.should == Array
|
32
|
+
values.first.should == 123
|
33
|
+
values.last.should == 456
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should handle arrays of hashes' do
|
37
|
+
us = multi_json.on_complete(:body => '[{"screen_name":"sferik"},{"screen_name":"pengwynn"}]')
|
38
|
+
us.class.should == Array
|
39
|
+
us.first['screen_name'].should == 'sferik'
|
40
|
+
us.last['screen_name'].should == 'pengwynn'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should handle mixed arrays' do
|
44
|
+
values = multi_json.on_complete(:body => '[123, {"screen_name":"sferik"}, 456]')
|
45
|
+
values.class.should == Array
|
46
|
+
values.first.should == 123
|
47
|
+
values.last.should == 456
|
48
|
+
values[1]['screen_name'].should == 'sferik'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'integration test' do
|
53
|
+
let(:stubs) { Faraday::Adapter::Test::Stubs.new }
|
54
|
+
let(:connection) do
|
55
|
+
Faraday::Connection.new do |builder|
|
56
|
+
builder.adapter :test, stubs
|
57
|
+
builder.use Faraday::Response::ParseJson
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should create a Hash from the body' do
|
62
|
+
stubs.get('/hash') {[200, {'content-type' => 'application/json; charset=utf-8'}, '{"name":"Erik Michaels-Ober","screen_name":"sferik"}']}
|
63
|
+
me = connection.get('/hash').body
|
64
|
+
me.class.should == Hash
|
65
|
+
me['name'].should == 'Erik Michaels-Ober'
|
66
|
+
me['screen_name'].should == 'sferik'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe Faraday::Response::ParseXml do
|
4
|
+
context 'when used' do
|
5
|
+
let(:multi_xml) { Faraday::Response::ParseXml.new }
|
6
|
+
|
7
|
+
it 'should handle an empty response' do
|
8
|
+
empty = multi_xml.on_complete(:body => '')
|
9
|
+
empty.should == Hash.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should create a Hash from the body' do
|
13
|
+
me = multi_xml.on_complete(:body => '<user><name>Erik Michaels-Ober</name><screen_name>sferik</screen_name></user>')
|
14
|
+
me.class.should == Hash
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should handle hashes' do
|
18
|
+
me = multi_xml.on_complete(:body => '<user><name>Erik Michaels-Ober</name><screen_name>sferik</screen_name></user>')
|
19
|
+
me['user']['name'].should == 'Erik Michaels-Ober'
|
20
|
+
me['user']['screen_name'].should == 'sferik'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'integration test' do
|
25
|
+
let(:stubs) { Faraday::Adapter::Test::Stubs.new }
|
26
|
+
let(:connection) do
|
27
|
+
Faraday::Connection.new do |builder|
|
28
|
+
builder.adapter :test, stubs
|
29
|
+
builder.use Faraday::Response::ParseXml
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should create a Hash from the body' do
|
34
|
+
stubs.get('/hash') {[200, {'content-type' => 'application/xml; charset=utf-8'}, '<user><name>Erik Michaels-Ober</name><screen_name>sferik</screen_name></user>']}
|
35
|
+
me = connection.get('/hash').body
|
36
|
+
me.class.should == Hash
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
CHANGED
@@ -2,129 +2,131 @@
|
|
2
2
|
name: faraday_middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.6.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
+
- Erik Michaels-Ober
|
8
9
|
- Wynn Netherland
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
13
|
|
13
|
-
date: 2011-
|
14
|
+
date: 2011-04-01 00:00:00 -07:00
|
14
15
|
default_executable:
|
15
16
|
dependencies:
|
16
17
|
- !ruby/object:Gem::Dependency
|
17
|
-
name:
|
18
|
+
name: faraday
|
18
19
|
prerelease: false
|
19
20
|
requirement: &id001 !ruby/object:Gem::Requirement
|
20
21
|
none: false
|
21
22
|
requirements:
|
22
23
|
- - ~>
|
23
24
|
- !ruby/object:Gem::Version
|
24
|
-
version:
|
25
|
-
type: :
|
25
|
+
version: 0.6.0
|
26
|
+
type: :runtime
|
26
27
|
version_requirements: *id001
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: rake
|
29
30
|
prerelease: false
|
30
31
|
requirement: &id002 !ruby/object:Gem::Requirement
|
31
32
|
none: false
|
32
33
|
requirements:
|
33
34
|
- - ~>
|
34
35
|
- !ruby/object:Gem::Version
|
35
|
-
version: "
|
36
|
+
version: "0.8"
|
36
37
|
type: :development
|
37
38
|
version_requirements: *id002
|
38
39
|
- !ruby/object:Gem::Dependency
|
39
|
-
name:
|
40
|
+
name: rspec
|
40
41
|
prerelease: false
|
41
42
|
requirement: &id003 !ruby/object:Gem::Requirement
|
42
43
|
none: false
|
43
44
|
requirements:
|
44
45
|
- - ~>
|
45
46
|
- !ruby/object:Gem::Version
|
46
|
-
version: "
|
47
|
+
version: "2.5"
|
47
48
|
type: :development
|
48
49
|
version_requirements: *id003
|
49
50
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
51
|
+
name: simplecov
|
51
52
|
prerelease: false
|
52
53
|
requirement: &id004 !ruby/object:Gem::Requirement
|
53
54
|
none: false
|
54
55
|
requirements:
|
55
56
|
- - ~>
|
56
57
|
- !ruby/object:Gem::Version
|
57
|
-
version: "0.
|
58
|
+
version: "0.4"
|
58
59
|
type: :development
|
59
60
|
version_requirements: *id004
|
60
61
|
- !ruby/object:Gem::Dependency
|
61
|
-
name:
|
62
|
+
name: hashie
|
62
63
|
prerelease: false
|
63
64
|
requirement: &id005 !ruby/object:Gem::Requirement
|
64
65
|
none: false
|
65
66
|
requirements:
|
66
67
|
- - ~>
|
67
68
|
- !ruby/object:Gem::Version
|
68
|
-
version: "0
|
69
|
+
version: "1.0"
|
69
70
|
type: :development
|
70
71
|
version_requirements: *id005
|
71
72
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
73
|
+
name: json_pure
|
73
74
|
prerelease: false
|
74
75
|
requirement: &id006 !ruby/object:Gem::Requirement
|
75
76
|
none: false
|
76
77
|
requirements:
|
77
78
|
- - ~>
|
78
79
|
- !ruby/object:Gem::Version
|
79
|
-
version: "
|
80
|
+
version: "1.5"
|
80
81
|
type: :development
|
81
82
|
version_requirements: *id006
|
82
83
|
- !ruby/object:Gem::Dependency
|
83
|
-
name:
|
84
|
+
name: multi_json
|
84
85
|
prerelease: false
|
85
86
|
requirement: &id007 !ruby/object:Gem::Requirement
|
86
87
|
none: false
|
87
88
|
requirements:
|
88
89
|
- - ~>
|
89
90
|
- !ruby/object:Gem::Version
|
90
|
-
version: "
|
91
|
+
version: "0.0"
|
91
92
|
type: :development
|
92
93
|
version_requirements: *id007
|
93
94
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
95
|
+
name: multi_xml
|
95
96
|
prerelease: false
|
96
97
|
requirement: &id008 !ruby/object:Gem::Requirement
|
97
98
|
none: false
|
98
99
|
requirements:
|
99
100
|
- - ~>
|
100
101
|
- !ruby/object:Gem::Version
|
101
|
-
version: "0.
|
102
|
+
version: "0.2"
|
102
103
|
type: :development
|
103
104
|
version_requirements: *id008
|
104
105
|
- !ruby/object:Gem::Dependency
|
105
|
-
name:
|
106
|
+
name: oauth2
|
106
107
|
prerelease: false
|
107
108
|
requirement: &id009 !ruby/object:Gem::Requirement
|
108
109
|
none: false
|
109
110
|
requirements:
|
110
111
|
- - ~>
|
111
112
|
- !ruby/object:Gem::Version
|
112
|
-
version: "2
|
113
|
+
version: "0.2"
|
113
114
|
type: :development
|
114
115
|
version_requirements: *id009
|
115
116
|
- !ruby/object:Gem::Dependency
|
116
|
-
name:
|
117
|
+
name: simple_oauth
|
117
118
|
prerelease: false
|
118
119
|
requirement: &id010 !ruby/object:Gem::Requirement
|
119
120
|
none: false
|
120
121
|
requirements:
|
121
122
|
- - ~>
|
122
123
|
- !ruby/object:Gem::Version
|
123
|
-
version: 0.
|
124
|
-
type: :
|
124
|
+
version: "0.1"
|
125
|
+
type: :development
|
125
126
|
version_requirements: *id010
|
126
127
|
description: Various middleware for Faraday
|
127
128
|
email:
|
129
|
+
- sferik@gmail.com
|
128
130
|
- wynn.netherland@gmail.com
|
129
131
|
executables: []
|
130
132
|
|
@@ -135,22 +137,27 @@ extra_rdoc_files:
|
|
135
137
|
files:
|
136
138
|
- .gemtest
|
137
139
|
- .gitignore
|
140
|
+
- .rspec
|
138
141
|
- CHANGELOG.md
|
139
142
|
- Gemfile
|
143
|
+
- LICENSE.md
|
140
144
|
- README.md
|
141
145
|
- Rakefile
|
142
146
|
- faraday_middleware.gemspec
|
143
|
-
- lib/faraday/
|
144
|
-
- lib/faraday/oauth2.rb
|
145
|
-
- lib/faraday/
|
146
|
-
- lib/faraday/
|
147
|
+
- lib/faraday/request/oauth.rb
|
148
|
+
- lib/faraday/request/oauth2.rb
|
149
|
+
- lib/faraday/response/mashify.rb
|
150
|
+
- lib/faraday/response/parse_json.rb
|
151
|
+
- lib/faraday/response/parse_xml.rb
|
147
152
|
- lib/faraday_middleware.rb
|
153
|
+
- lib/faraday_middleware/support/rash.rb
|
148
154
|
- lib/faraday_middleware/version.rb
|
149
|
-
-
|
150
|
-
-
|
151
|
-
-
|
152
|
-
-
|
153
|
-
-
|
155
|
+
- spec/helper.rb
|
156
|
+
- spec/mashify_spec.rb
|
157
|
+
- spec/oauth2_spec.rb
|
158
|
+
- spec/oauth_spec.rb
|
159
|
+
- spec/parse_json_spec.rb
|
160
|
+
- spec/parse_xml_spec.rb
|
154
161
|
has_rdoc: true
|
155
162
|
homepage: http://wynnnetherland.com/projects/faraday-middleware/
|
156
163
|
licenses: []
|
@@ -175,13 +182,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
182
|
requirements: []
|
176
183
|
|
177
184
|
rubyforge_project:
|
178
|
-
rubygems_version: 1.
|
185
|
+
rubygems_version: 1.6.2
|
179
186
|
signing_key:
|
180
187
|
specification_version: 3
|
181
188
|
summary: Various middleware for Faraday
|
182
189
|
test_files:
|
183
|
-
-
|
184
|
-
-
|
185
|
-
-
|
186
|
-
-
|
187
|
-
-
|
190
|
+
- spec/helper.rb
|
191
|
+
- spec/mashify_spec.rb
|
192
|
+
- spec/oauth2_spec.rb
|
193
|
+
- spec/oauth_spec.rb
|
194
|
+
- spec/parse_json_spec.rb
|
195
|
+
- spec/parse_xml_spec.rb
|
data/lib/faraday/mashify.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Response::Mashify < Response::Middleware
|
5
|
-
begin
|
6
|
-
require 'hashie'
|
7
|
-
rescue LoadError, NameError => error
|
8
|
-
self.load_error = error
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.register_on_complete(env)
|
12
|
-
env[:response].on_complete do |response|
|
13
|
-
response_body = response[:body]
|
14
|
-
if response_body.is_a?(Hash)
|
15
|
-
response[:body] = ::Hashie::Mash.new(response_body)
|
16
|
-
elsif response_body.is_a?(Array)
|
17
|
-
response[:body] = response_body.map{|item| item.is_a?(Hash) ? ::Hashie::Mash.new(item) : item}
|
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/parse_json.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Response::ParseJson < Response::Middleware
|
5
|
-
begin
|
6
|
-
require 'multi_json'
|
7
|
-
rescue LoadError, NameError => error
|
8
|
-
self.load_error = error
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.register_on_complete(env)
|
12
|
-
env[:response].on_complete do |response|
|
13
|
-
response[:body] = begin
|
14
|
-
case response[:body]
|
15
|
-
when ''
|
16
|
-
nil
|
17
|
-
when 'true'
|
18
|
-
true
|
19
|
-
when 'false'
|
20
|
-
false
|
21
|
-
else
|
22
|
-
::MultiJson.decode(response[:body])
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def initialize(app)
|
29
|
-
super
|
30
|
-
@parser = nil
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
data/lib/faraday/parse_xml.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Response::ParseXml < Response::Middleware
|
5
|
-
begin
|
6
|
-
require 'multi_xml'
|
7
|
-
rescue LoadError, NameError => error
|
8
|
-
self.load_error = error
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.register_on_complete(env)
|
12
|
-
env[:response].on_complete do |response|
|
13
|
-
response[:body] = begin
|
14
|
-
::MultiXml.parse(response[:body])
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(app)
|
20
|
-
super
|
21
|
-
@parser = nil
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/test/helper.rb
DELETED
data/test/mashify_test.rb
DELETED
@@ -1,43 +0,0 @@
|
|
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::ParseJson
|
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, {'content-type' => 'application/json; charset=utf-8'}, '{"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, {'content-type' => 'application/json; charset=utf-8'}, '[{"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, {'content-type' => 'application/json; charset=utf-8'}, "[123, 456]"]}
|
30
|
-
values = @conn.get("/array/simple").body
|
31
|
-
assert_equal 123, values.first
|
32
|
-
assert_equal 456, values.last
|
33
|
-
end
|
34
|
-
|
35
|
-
should 'handle arrays of hashes and non-hashes' do
|
36
|
-
@stubs.get('/array/simple') {[200, {'content-type' => 'application/json; charset=utf-8'}, '[123, {"username":"slainer68"}, 42]']}
|
37
|
-
values = @conn.get("/array/simple").body
|
38
|
-
assert_equal 123, values[0]
|
39
|
-
assert_equal "slainer68", values[1].username
|
40
|
-
assert_equal 42, values[2]
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
data/test/oauth2_test.rb
DELETED
@@ -1,18 +0,0 @@
|
|
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
|
data/test/parse_json_test.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class ParseJsonTest < 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::ParseJson
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "when there is a JSON body" do
|
14
|
-
setup do
|
15
|
-
@stubs.get('/me') {[200, {'content-type' => 'application/json; charset=utf-8'}, '{"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, {'content-type' => 'application/json; charset=utf-8'}, ""]}
|
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 nil, response.body
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context "when the JSON body is 'true'" do
|
43
|
-
setup do
|
44
|
-
@stubs.get('/me') {[200, {'content-type' => 'application/json; charset=utf-8'}, "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 true' do
|
53
|
-
response = @conn.get("/me")
|
54
|
-
assert_equal true, response.body
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
context "when the JSON body is 'false'" do
|
59
|
-
setup do
|
60
|
-
@stubs.get('/me') {[200, {'content-type' => 'application/json; charset=utf-8'}, "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 false' do
|
69
|
-
response = @conn.get("/me")
|
70
|
-
assert_equal false, response.body
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/test/parse_xml_test.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class ParseXmlTest < 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::ParseXml
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
context "when there is a XML body" do
|
14
|
-
setup do
|
15
|
-
@stubs.get('/me') {[200, {'content-type' => 'application/xml; charset=utf-8'}, '<user><name>Erik Michaels-Ober</name><username>sferik</username></user>']}
|
16
|
-
end
|
17
|
-
|
18
|
-
should 'parse the body as XML' do
|
19
|
-
me = @conn.get("/me").body['user']
|
20
|
-
assert me.is_a?(Hash)
|
21
|
-
assert_equal 'Erik Michaels-Ober', me['name']
|
22
|
-
assert_equal 'sferik', me['username']
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "when there is a ATOM body" do
|
27
|
-
setup do
|
28
|
-
@stubs.get('/me') {[200, {'content-type' => 'application/atom+xml; charset=utf-8'}, '<user><name>Erik Michaels-Ober</name><username>sferik</username></user>']}
|
29
|
-
end
|
30
|
-
|
31
|
-
should 'parse the body as XML' do
|
32
|
-
me = @conn.get("/me").body['user']
|
33
|
-
assert me.is_a?(Hash)
|
34
|
-
assert_equal 'Erik Michaels-Ober', me['name']
|
35
|
-
assert_equal 'sferik', me['username']
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "when the XML body is empty" do
|
40
|
-
setup do
|
41
|
-
@stubs.get('/me') {[200, {'content-type' => 'application/xml; charset=utf-8'}, ""]}
|
42
|
-
end
|
43
|
-
|
44
|
-
should 'still have the status code' do
|
45
|
-
response = @conn.get("/me")
|
46
|
-
assert_equal 200, response.status
|
47
|
-
end
|
48
|
-
|
49
|
-
should 'set body to nil' do
|
50
|
-
response = @conn.get("/me")
|
51
|
-
assert_equal Hash.new, response.body
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|