class Napster::Models::Artist
Artist
model
Constants
- ATTRIBUTES
Attributes
client[RW]
Public Class Methods
collection(arg)
click to toggle source
# File lib/napster/models/artist.rb, line 32 def self.collection(arg) arg[:data].map do |artist| Artist.new(data: artist, client: arg[:client]) end end
new(arg)
click to toggle source
# File lib/napster/models/artist.rb, line 23 def initialize(arg) @client = arg[:client] if arg[:client] return unless arg[:data] ATTRIBUTES.each do |attribute| send("#{attribute}=", arg[:data][attribute.to_s.camel_case_lower]) end end
Public Instance Methods
albums(params)
click to toggle source
Instance methods
# File lib/napster/models/artist.rb, line 72 def albums(params) response = @client.get("/artists/#{@id}/albums", params: params) Album.collection(data: response['albums'], client: @client) end
find(arg)
click to toggle source
# File lib/napster/models/artist.rb, line 45 def find(arg) return find_by_id(arg) if Napster::Moniker.check(arg, :artist) find_by_name(arg) end
find_all_by_name(name)
click to toggle source
# File lib/napster/models/artist.rb, line 55 def find_all_by_name(name) options = { params: { q: name, type: 'artist' } } response = @client.get('/search', options) Artist.collection(data: response['data'], client: @client) end
find_by_id(id)
click to toggle source
# File lib/napster/models/artist.rb, line 50 def find_by_id(id) response = @client.get("/artists/#{id}") Artist.new(data: response['artists'].first, client: @client) end
find_by_name(name)
click to toggle source
# File lib/napster/models/artist.rb, line 66 def find_by_name(name) find_all_by_name(name).first end
new_albums(params)
click to toggle source
# File lib/napster/models/artist.rb, line 77 def new_albums(params) response = @client.get("/artists/#{@id}/albums/new", params: params) Album.collection(data: response['albums'], client: @client) end
top(params)
click to toggle source
Top level methods
# File lib/napster/models/artist.rb, line 40 def top(params) response = @client.get('/artists/top', params: params) Artist.collection(data: response['artists'], client: @client) end
top_tracks(params)
click to toggle source
# File lib/napster/models/artist.rb, line 87 def top_tracks(params) response = @client.get("/artists/#{@id}/tracks/top", params: params) Track.collection(data: response['tracks'], client: @client) end
tracks(params)
click to toggle source
# File lib/napster/models/artist.rb, line 82 def tracks(params) response = @client.get("/artists/#{@id}/tracks", params: params) Track.collection(data: response['tracks'], client: @client) end