Module: RSpotify

Defined in:
lib/rspotify.rb,
lib/rspotify/base.rb,
lib/rspotify/user.rb,
lib/rspotify/album.rb,
lib/rspotify/track.rb,
lib/rspotify/artist.rb,
lib/rspotify/version.rb,
lib/rspotify/playlist.rb,
lib/rspotify/connection.rb

Defined Under Namespace

Classes: Album, Artist, Base, Playlist, Track, User

Constant Summary collapse

VERSION =
'1.6.1'
API_URI =
'https://api.spotify.com/v1/'
AUTHORIZE_URI =
'https://accounts.spotify.com/authorize'
TOKEN_URI =
'https://accounts.spotify.com/api/token'
VERBS =
%w(get post put delete)

Class Method Summary collapse

Class Method Details

.authenticate(client_id, client_secret) ⇒ Object

Authenticates access to restricted data. Requires user credentials

Examples:

RSpotify.authenticate("<your_client_id>", "<your_client_secret>")

playlist = RSpotify::Playlist.find('wizzler', '00wHcTN0zQiun4xri9pmvX')
playlist.name #=> "Movie Soundtrack Masterpieces"

Parameters:

  • client_id (String)
  • client_secret (String)


24
25
26
27
28
29
30
# File 'lib/rspotify/connection.rb', line 24

def authenticate(client_id, client_secret)
  @client_id, @client_secret = client_id, client_secret
  request_body = { grant_type: 'client_credentials' }
  response = RestClient.post(TOKEN_URI, request_body, auth_header)
  @client_token = JSON.parse(response)['access_token']
  true
end

.resolve_auth_request(user_id, url) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/rspotify/connection.rb', line 45

def resolve_auth_request(user_id, url)
  users_credentials = if User.class_variable_defined?('@@users_credentials')
    User.class_variable_get('@@users_credentials')
  end

  if users_credentials && users_credentials[user_id]
    User.oauth_get(user_id, url)
  else
    auth_get(url)
  end
end