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/category.rb,
lib/rspotify/playlist.rb,
lib/rspotify/connection.rb,
lib/rspotify/audio_features.rb,
lib/rspotify/recommendations.rb,
lib/rspotify/recommendation_seed.rb

Defined Under Namespace

Classes: Album, Artist, AudioFeatures, Base, Category, Playlist, RecommendationSeed, Recommendations, Track, User

Constant Summary

VERSION =
'1.22.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 Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.raw_responseObject

Returns the value of attribute raw_response



13
14
15
# File 'lib/rspotify/connection.rb', line 13

def raw_response
  @raw_response
end

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)


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

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



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rspotify/connection.rb', line 40

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
    get(url)
  end
end