mirror of
https://github.com/samsonjs/instapaper.git
synced 2026-03-25 08:55:49 +00:00
Merge pull request #1 from brainsley/handle-invalid-credentials
Handle invalid credentials
This commit is contained in:
commit
7873923aef
3 changed files with 15 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
1
spec/fixtures/invalid_credentials.qline
vendored
Normal file
1
spec/fixtures/invalid_credentials.qline
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
Invalid xAuth credentials.
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue