Fixed error with creating hash for invalid credentials

This commit is contained in:
Niels van Hoorn 2012-12-27 23:37:45 +01:00
parent 1be023c996
commit 6e234ce26c
3 changed files with 15 additions and 1 deletions

View file

@ -6,7 +6,12 @@ module Instapaper
# Gets an OAuth access token for a user.
def access_token(username, password)
response = post('oauth/access_token', { :x_auth_username => username, :x_auth_password => password, :x_auth_mode => "client_auth"}, true)
Hash[*response.body.split("&").map {|part| part.split("=") }.flatten]
params = response.body.split("&")
values = params.map {|part| part.split("=") }.flatten
if values.length == 1
values.unshift('error')
end
Hash[*values]
end
end

View file

@ -0,0 +1 @@
Invalid xAuth credentials.

View file

@ -9,6 +9,8 @@ describe Instapaper::Client::User do
before do
stub_post("oauth/access_token").with(:body => { :x_auth_username => 'ohai', :x_auth_password => 'p455w0rd', :x_auth_mode => 'client_auth'}).
to_return(:body => fixture("access_token.qline"), :headers => {:content_type => "text/plain; charset=utf-8"})
stub_post("oauth/access_token").with(:body => { :x_auth_username => 'inval1d', :x_auth_password => 'cr3dentials', :x_auth_mode => 'client_auth'}).
to_return(:body => fixture("invalid_credentials.qline"), :headers => {:content_type => "text/plain; charset=utf-8"})
end
it "should get the correct resource" do
@ -23,6 +25,12 @@ describe Instapaper::Client::User do
tokens.key?('oauth_token').should be_true
tokens.key?('oauth_token_secret').should be_true
end
it "should return a hash containing the error on invalid credentials" do
tokens = @client.access_token('inval1d', 'cr3dentials')
tokens.should be_a Hash
tokens.key?('error').should be_true
end
end
end