Class: Spotify::Accounts
- Inherits:
-
Object
- Object
- Spotify::Accounts
- Defined in:
- lib/spotify/accounts.rb,
lib/spotify/accounts/session.rb
Overview
Spotify::Accounts deals with authorization using the Spotify Accounts API.
Defined Under Namespace
Classes: Session
Constant Summary collapse
- SCOPES =
An entire list of Spotify’s OAuth scopes. Stored in the form of a symbolized array. Example: ‘[:scope1, :scope2]`
Last updated: 23 June 2018
%i[ playlist-read-private playlist-read-collaborative playlist-modify-public playlist-modify-private ugc-image-upload user-follow-modify user-follow-read user-library-read user-library-modify user-read-private user-read-birthdate user-read-email user-top-read user-read-playback-state user-modify-playback-state user-read-currently-playing user-read-recently-played streaming app-remote-control ].freeze
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
Instance Method Summary collapse
-
#authorize_url(override_params = {}) ⇒ String
Get a HTTP URL to send user for authorizing with Spotify.
-
#exchange_for_session(code) ⇒ Spotify::Accounts::Session
Start a session from your authentication code.
-
#initialize(config = {}) ⇒ Accounts
constructor
Initialize the Spotify Accounts object.
-
#inspect ⇒ Object
:nodoc:.
Constructor Details
#initialize(config = {}) ⇒ Accounts
Initialize the Spotify Accounts object.
61 62 63 64 65 |
# 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 |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
67 68 69 |
# File 'lib/spotify/accounts.rb', line 67 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
67 68 69 |
# File 'lib/spotify/accounts.rb', line 67 def client_secret @client_secret end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
67 68 69 |
# File 'lib/spotify/accounts.rb', line 67 def redirect_uri @redirect_uri end |
Instance Method Details
#authorize_url(override_params = {}) ⇒ String
Get a HTTP URL to send user for authorizing with Spotify.
Parameters used are client_id, redirect_uri, response_type and scope.
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/spotify/accounts.rb', line 88 def (override_params={}) validate_credentials! params = { client_id: @client_id, redirect_uri: @redirect_uri, response_type: "code", scope: SCOPES.join(" ") }.merge(override_params) "https://accounts.spotify.com/authorize?%s" % params.to_query end |
#exchange_for_session(code) ⇒ Spotify::Accounts::Session
Start a session from your authentication code.
116 117 118 119 |
# File 'lib/spotify/accounts.rb', line 116 def exchange_for_session(code) validate_credentials! Spotify::Accounts::Session.(code) end |
#inspect ⇒ Object
:nodoc:
121 122 123 |
# File 'lib/spotify/accounts.rb', line 121 def inspect # :nodoc: "#<%s:0x00%x>" % [self.class.name, (object_id << 1)] end |