class Napster::Models::Album

Album model

Constants

ATTRIBUTES

Attributes

client[RW]

Public Class Methods

collection(arg) click to toggle source
# File lib/napster/models/album.rb, line 41
def self.collection(arg)
  arg[:data].map do |album|
    Album.new(data: album, client: @client)
  end
end
new(arg) click to toggle source
# File lib/napster/models/album.rb, line 32
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

find(arg) click to toggle source
# File lib/napster/models/album.rb, line 64
def find(arg)
  return find_by_id(arg) if Napster::Moniker.check(arg, :album)
  find_by_name(arg)
end
find_all_by_name(name) click to toggle source
# File lib/napster/models/album.rb, line 74
def find_all_by_name(name)
  options = {
    params: {
      q: name,
      type: 'album'
    }
  }
  response = @client.get('/search', options)
  Album.collection(data: response['data'])
end
find_by_id(id) click to toggle source
# File lib/napster/models/album.rb, line 69
def find_by_id(id)
  response = @client.get("/albums/#{id}")
  Album.new(data: response['albums'].first, client: @client)
end
find_by_name(name) click to toggle source
# File lib/napster/models/album.rb, line 85
def find_by_name(name)
  find_all_by_name(name).first
end
new_releases(params) click to toggle source

Top level methods

# File lib/napster/models/album.rb, line 49
def new_releases(params)
  response = @client.get('/albums/new', params: params)
  Album.collection(data: response['albums'], client: @client)
end
staff_picks(params) click to toggle source
# File lib/napster/models/album.rb, line 54
def staff_picks(params)
  response = @client.get('/albums/picks', params: params)
  Album.collection(data: response['albums'], client: @client)
end
top(params) click to toggle source
# File lib/napster/models/album.rb, line 59
def top(params)
  response = @client.get('/albums/top', params: params)
  Album.collection(data: response['albums'], client: @client)
end
tracks(params) click to toggle source

Instance methods

# File lib/napster/models/album.rb, line 91
def tracks(params)
  response = @client.get("/albums/#{@id}/tracks", params: params)
  Track.collection(data: response['tracks'], client: @client)
end