Permalink
Browse files

Relax `multi_json` dependency to "~> 1.0"

Use `Object#respond_to?` to determine which MultiJson API to use.
  • Loading branch information...
sferik committed Apr 27, 2012
1 parent 5b5609a commit 9d50d2556ce6249aa83c2c27b9ba33020e309ad8
View
@@ -49,9 +49,11 @@ def body
# Procs that, when called, will parse a response body according
# to the specified format.
PARSERS = {
- :json => lambda{|body| MultiJson.load(body) rescue body },
- :query => lambda{|body| Rack::Utils.parse_query(body) },
- :text => lambda{|body| body}
+ # Can't reliably detect whether MultiJson responds to load, since it's
+ # a reserved word. Use adapter as a proxy for new features.
+ :json => lambda{ |body| MultiJson.respond_to?(:adapter) ? MultiJson.load(body) : MultiJson.decode(body) rescue body },
+ :query => lambda{ |body| Rack::Utils.parse_query(body) },
+ :text => lambda{ |body| body }
}
# Content type assignments for various potential HTTP content types.
View
@@ -4,7 +4,7 @@ require File.expand_path('../lib/oauth2/version', __FILE__)
Gem::Specification.new do |gem|
gem.add_dependency 'faraday', '~> 0.8'
gem.add_dependency 'httpauth', '~> 0.1'
- gem.add_dependency 'multi_json', '~> 1.3'
+ gem.add_dependency 'multi_json', '~> 1.0'
gem.add_dependency 'rack', '~> 1.4'
gem.add_development_dependency 'addressable'
gem.add_development_dependency 'multi_xml'
@@ -4,8 +4,8 @@
describe AccessToken do
let(:token) {'monkey'}
- let(:token_body) {MultiJson.dump(:access_token => 'foo', :expires_in => 600, :refresh_token => 'bar')}
- let(:refresh_body) {MultiJson.dump(:access_token => 'refreshed_foo', :expires_in => 600, :refresh_token => 'refresh_bar')}
+ let(:token_body) {MultiJson.encode(:access_token => 'foo', :expires_in => 600, :refresh_token => 'bar')}
+ let(:refresh_body) {MultiJson.encode(:access_token => 'refreshed_foo', :expires_in => 600, :refresh_token => 'refresh_bar')}
let(:client) do
Client.new('abc', 'def', :site => 'https://api.example.com') do |builder|
builder.request :url_encoded
@@ -10,7 +10,7 @@
stub.get('/success') {|env| [200, {'Content-Type' => 'text/awesome'}, 'yay']}
stub.get('/reflect') {|env| [200, {}, env[:body]]}
stub.post('/reflect') {|env| [200, {}, env[:body]]}
- stub.get('/unauthorized') {|env| [401, {'Content-Type' => 'application/json'}, MultiJson.dump(:error => error_value, :error_description => error_description_value)]}
+ stub.get('/unauthorized') {|env| [401, {'Content-Type' => 'application/json'}, MultiJson.encode(:error => error_value, :error_description => error_description_value)]}
stub.get('/conflict') {|env| [409, {'Content-Type' => 'text/plain'}, 'not authorized']}
stub.get('/redirect') {|env| [302, {'Content-Type' => 'text/plain', 'location' => '/success' }, '']}
stub.post('/redirect') {|env| [303, {'Content-Type' => 'text/plain', 'location' => '/reflect' }, '']}
@@ -52,7 +52,7 @@
it "parses application/json body" do
headers = {'Content-Type' => 'application/json'}
- body = MultiJson.dump(:foo => 'bar', :answer => 42)
+ body = MultiJson.encode(:foo => 'bar', :answer => 42)
response = double('response', :headers => headers, :body => body)
subject = Response.new(response)
subject.parsed.keys.size.should == 2
@@ -67,6 +67,7 @@
response = double('response', :headers => headers, :body => body)
MultiJson.should_not_receive(:decode)
+ MultiJson.should_not_receive(:load)
Rack::Utils.should_not_receive(:parse_query)
subject = Response.new(response)
@@ -4,7 +4,7 @@
let(:code) {'sushi'}
let(:kvform_token) {'expires_in=600&access_token=salmon&refresh_token=trout&extra_param=steve'}
let(:facebook_token) {kvform_token.gsub('_in', '')}
- let(:json_token) {MultiJson.dump(:expires_in => 600, :access_token => 'salmon', :refresh_token => 'trout', :extra_param => 'steve')}
+ let(:json_token) {MultiJson.encode(:expires_in => 600, :access_token => 'salmon', :refresh_token => 'trout', :extra_param => 'steve')}
let(:client) do
OAuth2::Client.new('abc', 'def', :site => 'http://api.example.com') do |builder|

0 comments on commit 9d50d25

Please sign in to comment.