Class: Hypem::Track

Inherits:
Object
  • Object
show all
Defined in:
lib/hypem/track.rb

Constant Summary collapse

KEY_CONVERSIONS =
{
  mediaid: :media_id,
  dateposted: :dated_posted,
  siteid: :site_id,
  posturl: :post_url,
  posturl_first: :post_url_first,
  postid: :post_id,
  postid_first: :post_id_first,
  dateposted_first: :date_posted_first,
  siteid_first: :site_id_first,
  sitename: :site_name,
  dateposted: :date_posted,
  sitename_first: :site_name_first
}
DATETIME_CONVERSIONS =
[:date_posted, :date_posted_first]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ Track

Returns a new instance of Track.



5
6
7
8
9
10
11
# File 'lib/hypem/track.rb', line 5

def initialize(arg)
  if arg.is_a? Hash
    keys_to_attributes arg
  elsif arg.is_a? String
    @media_id = arg
  end
end

Instance Attribute Details

#media_idObject

Returns the value of attribute media_id.



3
4
5
# File 'lib/hypem/track.rb', line 3

def media_id
  @media_id
end

Instance Method Details

#getObject



13
14
15
16
17
# File 'lib/hypem/track.rb', line 13

def get
  request = Request.new("/playlist/item/#{media_id}/json/1").tap(&:get)
  raw_hash = request.response.body.tap(&:shift)["0"]
  keys_to_attributes raw_hash
end