class Napster::Models::Tag

Tag model

Constants

ATTRIBUTES
SUPPORTED_CONTENT_TYPES

Attributes

client[RW]

Public Class Methods

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

all() click to toggle source

Top level methods

# File lib/napster/models/tag.rb, line 44
def all
  response = @client.get('/tags')
  Tag.collection(data: response['tags'])
end
contents(named_tag, type, params) click to toggle source

/me

# File lib/napster/models/tag.rb, line 58
def contents(named_tag, type, params)
  params[:tag] = named_tag if named_tag
  params[:type] = type.to_s if type
  get_options = {
    params: params,
    headers: {
      Authorization: 'Bearer ' + @client.access_token,
      'Content-Type' => 'application/json',
      'Accept-Version' => '2.0.0'
    }
  }
  response = @client.get('/me/tags/search', get_options)
  Content.collection(data: response['data'], client: @client)
end
find(id) click to toggle source
# File lib/napster/models/tag.rb, line 49
def find(id)
  e = 'Invalid tag id'
  raise ArgumentError, e unless Napster::Moniker.check(id, :tag)
  response = @client.get("/tags/#{id}")
  Tag.new(data: response['tags'].first, client: @client)
end