class Napster::Models::Library
Library
model
Attributes
client[RW]
Public Class Methods
new(arg)
click to toggle source
# File lib/napster/models/library.rb, line 9 def initialize(arg) @client = arg[:client] if arg[:client] end
Public Instance Methods
add_track(tracks)
click to toggle source
# File lib/napster/models/library.rb, line 94 def add_track(tracks) e = 'tracks argument should be an array.' raise ArgumentError, e unless tracks.class == Array tracks = tracks.join(',') options = { params: { id: tracks }, headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } @client.post('/me/library/tracks', '{}', options) end
album_tracks(album_id, params)
click to toggle source
# File lib/napster/models/library.rb, line 67 def album_tracks(album_id, params) path = "/me/library/albums/#{album_id}/tracks" get_options = { params: params, headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } response = @client.get(path, get_options) Track.collection(data: response['tracks'], client: @client) end
albums(params)
click to toggle source
# File lib/napster/models/library.rb, line 54 def albums(params) get_options = { params: params, headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } response = @client.get('/me/library/albums', get_options) Album.collection(data: response['albums'], client: @client) end
artist_albums(artist_id, params)
click to toggle source
# File lib/napster/models/library.rb, line 26 def artist_albums(artist_id, params) path = "/me/library/artists/#{artist_id}/albums" get_options = { params: params, headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } response = @client.get(path, get_options) Album.collection(data: response['albums'], client: @client) end
artist_tracks(artist_id, params)
click to toggle source
# File lib/napster/models/library.rb, line 40 def artist_tracks(artist_id, params) path = "/me/library/artists/#{artist_id}/tracks" get_options = { params: params, headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } response = @client.get(path, get_options) Track.collection(data: response['tracks'], client: @client) end
artists(params)
click to toggle source
# File lib/napster/models/library.rb, line 13 def artists(params) get_options = { params: params, headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } response = @client.get('/me/library/artists', get_options) Artist.collection(data: response['artists'], client: @client) end
last_updated_date()
click to toggle source
# File lib/napster/models/library.rb, line 122 def last_updated_date path = '/me/library/updated' options = { headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } response = @client.get(path, options) LibraryDateTime.new(data: response['lastUpdateDate'], client: @client) end
remove_track(track_id)
click to toggle source
# File lib/napster/models/library.rb, line 110 def remove_track(track_id) path = "/me/library/tracks/#{track_id}" options = { headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } @client.delete(path, options) end
tracks(params)
click to toggle source
# File lib/napster/models/library.rb, line 81 def tracks(params) get_options = { params: params, headers: { Authorization: 'Bearer ' + @client.access_token, 'Content-Type' => 'application/json', 'Accept-Version' => '2.0.0' } } response = @client.get('/me/library/tracks', get_options) Track.collection(data: response['tracks'], client: @client) end