class Spotify::Accounts
Spotify::Accounts
deals with authorization using the Spotify
Accounts
API.
Constants
- SCOPES
An entire list of Spotify's OAuth scopes. Stored in the form of a symbolized array. Example: `[:scope1, :scope2]`
@see developer.spotify.com/documentation/general/guides/scopes/
Last updated: 23 June 2018
Attributes
client_id[RW]
client_secret[RW]
redirect_uri[RW]
Public Class Methods
new(config={})
click to toggle source
Initialize the Spotify
Accounts
object.
@example
@accounts = Spotify::Accounts.new({ client_id: "[client id goes here]", client_secret: "[client secret goes here]", redirect_uri: "http://localhost" }) @accounts = Spotify::Accounts.new @accounts.client_id = "[client id goes here]" @accounts.client_secret = "[client secret goes here]" @accounts.redirect_uri = "http://localhost" # with SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, and SPOTIFY_REDIRECT_URI in ENV: @accounts = Spotify::Accounts.new
@param [Hash] config The configuration containing your Client ID, Client Secret, and your Redirect URL.
@see developer.spotify.com/dashboard/
# File lib/spotify/accounts.rb, line 61 def initialize(config={}) @client_id = config.delete(:client_id) { ENV["SPOTIFY_CLIENT_ID"] } @client_secret = config.delete(:client_secret) { ENV["SPOTIFY_CLIENT_SECRET"] } @redirect_uri = config.delete(:redirect_uri) { ENV["SPOTIFY_REDIRECT_URI"] } end
Public Instance Methods
exchange_for_session(code)
click to toggle source
Start a session from your authentication code.
@example
@accounts = Spotify::Accounts.new({ client_id: "[client id goes here]", client_secret: "[client secret goes here]", redirect_uri: "http://localhost" }) @accounts.exchange_for_session("code")
@param [String] code The code provided back to your application upon authorization. @return [Spotify::Accounts::Session] session The session object.
@see developer.spotify.com/documentation/general/guides/authorization-guide/
# File lib/spotify/accounts.rb, line 116 def exchange_for_session(code) validate_credentials! Spotify::Accounts::Session.from_authorization_code(code) end