Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mobile auth #20

Merged
merged 1 commit into from Jan 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rdoc
Expand Up @@ -23,6 +23,7 @@ It supports methods which require {authentication}[http://www.last.fm/api/authen

=== Auth

* {auth.getMobileSession}[http://www.lastfm.jp/api/show?service=266]
* {auth.getToken}[http://www.lastfm.jp/api/show?service=265]
* {auth.getSession}[http://www.lastfm.jp/api/show?service=125]

Expand Down
4 changes: 4 additions & 0 deletions lib/lastfm/method_category/auth.rb
Expand Up @@ -8,6 +8,10 @@ class Auth < Base
method_for_authentication :get_session, [:token], [] do |response|
response.xml['session']
end

method_for_authentication :get_mobile_session, [:username, :authToken], [] do |response|
response.xml['session']
end
end
end
end
18 changes: 18 additions & 0 deletions spec/lastfm_spec.rb
Expand Up @@ -145,6 +145,24 @@
session['name'].should eql('MyLastFMUsername')
session['key'].should eql('zzzyyyxxx')
end

it 'should get mobile session' do
@lastfm.should_receive(:request).
with('auth.getMobileSession', { :username => 'xxxyyyzzz', :authToken => 'xxxxAuthTokenxxxx' }, :get, true).
and_return(make_response(<<XML))
<?xml version="1.0" encoding="utf-8"?>
<lfm status="ok">
<session>
<name>MyLastFMUsername</name>
<key>zzzyyyxxx</key>
<subscriber>0</subscriber>
</session>
</lfm>
XML
session = @lastfm.auth.get_mobile_session('xxxyyyzzz', 'xxxxAuthTokenxxxx')
session['name'].should eql('MyLastFMUsername')
session['key'].should eql('zzzyyyxxx')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you verify that this is the response body before faking it here? When I try to use this method I get an error:

pry(main)> lastfm.auth.get_mobile_session(my_username, token)
Lastfm::ApiError:
    Invalid authentication token. Please check username/password supplied

where the token was retrieved through lastfm.auth.get_token.

end
end

describe '#track' do
Expand Down