Sha256: 0b5e9062c91bc9078233e33586689291845ec5cf7d6a7db8e9dda9968e5bd19e

Contents?: true

Size: 1.27 KB

Versions: 6

Compression:

Stored size: 1.27 KB

Contents

module Rockstar

  # = Authentification
  #
  # There are 2 ways to get an auth token :
  #
  # == Desktop-App
  # 1. Get a new token to request authorisation:
  #     token = Rockstar::Auth.new.token
  # 2. Open a webbrowser with http://www.last.fm/api/auth/?api_key=xxxxxxxxxxx&token=xxxxxxxx
  # 3. Wait for the User to confirm that he accepted your request.
  # 4. Continue with "Get the session token"
  #
  # == Web-App
  # 1. Redirect the user to http://www.last.fm/api/auth/?api_key={YOUR_API_KEY}&cb={YOUR_RETURN_URL}
  # 2. If the user accepts, lastfm will redirect to YOUR_RETURN_URL?token=TOKEN
  #     token = params[:token]
  # 3. Continue with "Get the session token"
  #
  # == Get the session token
  # 1. Use the previous token and call
  #     session = Rockstar::Auth.new.session(token)
  # 2. Store the session.key and session.username returned. The session.key will not
  #    expire. It is save to store it into your database.
  class Auth < Base

    def session(token)
      doc = self.class.fetch_and_parse("auth.getSession", {:token => token}, true)
      Rockstar::Session.new_from_xml(doc)
    end

    def token
      doc = self.class.fetch_and_parse("auth.getToken", {}, true)
      token = (doc).at(:token).inner_html if (doc).at(:token)
      token
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
rockstar-0.8.1 lib/rockstar/auth.rb
rockstar-0.8.0 lib/rockstar/auth.rb
jonaustin-rockstar-0.7.1 lib/rockstar/auth.rb
rockstar-0.7.1 lib/rockstar/auth.rb
rockstar-0.7.0 lib/rockstar/auth.rb
rockstar-0.6.4 lib/rockstar/auth.rb