Permalink
Browse files

Show real response for JSON parser error. 0.9.19

  • Loading branch information...
kyledrake committed Aug 8, 2011
1 parent d5c9293 commit 1d6137ff240a0c59eacd3bf35aafeaf115fade42
Showing with 34 additions and 5 deletions.
  1. +2 −0 lib/geoloqi/session.rb
  2. +1 −1 lib/geoloqi/version.rb
  3. +31 −4 spec/geoloqi_spec.rb
View
@@ -56,6 +56,8 @@ def run(meth, path, query=nil)
else
fail
end
+ rescue JSON::ParserError
+ raise Geoloqi::Error, "API returned invalid JSON. Status: #{response.status} Body: #{response.body}"
end
@config.use_hashie_mash ? Hashie::Mash.new(hash) : hash
end
View
@@ -1,5 +1,5 @@
module Geoloqi
def self.version
- '0.9.18'
+ '0.9.19'
end
end
View
@@ -143,6 +143,18 @@ def api_url(path); "#{Geoloqi::API_URL}/#{Geoloqi::API_VERSION}/#{path}" end
@session = Geoloqi::Session.new :access_token => ACCESS_TOKEN
end
+ it 'throws an exception on a hard request error' do
+ stub_request(:get, api_url('crashing_method')).
+ with(:headers => auth_headers).
+ to_return(:status => 500, :body => 'Something broke hard!')
+
+ expect { rescuing {Geoloqi::Session.new(:access_token => 'access_token1234').get('crashing_method')}.class == Geoloqi::Error }
+ expect {
+ rescuing {Geoloqi::Session.new(:access_token => 'access_token1234').get('crashing_method')}.message ==
+ "API returned invalid JSON. Status: 500 Body: Something broke hard!"
+ }
+ end
+
it 'successfully makes mock call with array' do
stub_request(:post, api_url('play_record_at_geoloqi_hq')).
with(:headers => auth_headers, :body => [{:artist => 'Television'}].to_json).
@@ -328,6 +340,25 @@ def api_url(path); "#{Geoloqi::API_URL}/#{Geoloqi::API_VERSION}/#{path}" end
expect { @session.auth[:access_token] == 'access_token1234' }
expect { response['username'] == 'bulbasaurrulzok' }
end
+
+ it 'does not attempt to refresh for auth code expire' do
+ stub_request(:post, api_url('oauth/token')).
+ with(:body => {:client_id => CLIENT_ID,
+ :client_secret => CLIENT_SECRET,
+ :grant_type => "authorization_code",
+ :code => "1234",
+ :redirect_uri => "http://expired_code.example.com/"}.to_json).
+ to_return(:body => {:access_token => 'access_token1234',
+ :scope => nil,
+ :expires_in => '0',
+ :refresh_token => 'never_expires'}.to_json)
+
+ stub_request(:get, api_url('account/username?code=1234')).
+ with(:headers => auth_headers).
+ to_return(:status => 200, :body => {:points => [1,2]}.to_json)
+
+ # FINISH IMPLEMENTING
+ end
end
describe 'with config and expired auth' do
@@ -358,9 +389,5 @@ def api_url(path); "#{Geoloqi::API_URL}/#{Geoloqi::API_VERSION}/#{path}" end
@session.get 'account/username'
expect { @session.auth[:access_token] == 'access_token4567' }
end
-
- it 'does not attempt to refresh for auth code expire' do
- # IMPLEMENT
- end
end
end

0 comments on commit 1d6137f

Please sign in to comment.