Class: Genius::Song

Inherits:
Resource show all
Defined in:
lib/genius/song.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#raw_response, #resource

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

default_headers, default_params, find, from_hash, handle_response, http_delete, http_get, http_post, http_put, #initialize, #reload, resource_name

Constructor Details

This class inherits a constructor from Genius::Resource

Instance Attribute Details

#annotation_countObject (readonly)

Returns the value of attribute annotation_count.



3
4
5
# File 'lib/genius/song.rb', line 3

def annotation_count
  @annotation_count
end

#bop_urlObject (readonly)

Returns the value of attribute bop_url.



3
4
5
# File 'lib/genius/song.rb', line 3

def bop_url
  @bop_url
end

#current_user_metadataObject (readonly)

Returns the value of attribute current_user_metadata.



3
4
5
# File 'lib/genius/song.rb', line 3

def 
  @current_user_metadata
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/genius/song.rb', line 3

def description
  @description
end

#description_annotationObject (readonly)

Returns the value of attribute description_annotation.



3
4
5
# File 'lib/genius/song.rb', line 3

def description_annotation
  @description_annotation
end

#header_image_urlObject (readonly)

Returns the value of attribute header_image_url.



3
4
5
# File 'lib/genius/song.rb', line 3

def header_image_url
  @header_image_url
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/genius/song.rb', line 3

def id
  @id
end

#lyrics_updated_atObject (readonly)

Returns the value of attribute lyrics_updated_at.



3
4
5
# File 'lib/genius/song.rb', line 3

def lyrics_updated_at
  @lyrics_updated_at
end

#mediaObject (readonly)

Returns the value of attribute media.



3
4
5
# File 'lib/genius/song.rb', line 3

def media
  @media
end

#pyongs_countObject (readonly)

Returns the value of attribute pyongs_count.



3
4
5
# File 'lib/genius/song.rb', line 3

def pyongs_count
  @pyongs_count
end

#statsObject (readonly)

Returns the value of attribute stats.



3
4
5
# File 'lib/genius/song.rb', line 3

def stats
  @stats
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/genius/song.rb', line 3

def title
  @title
end

#tracking_pathsObject (readonly)

Returns the value of attribute tracking_paths.



3
4
5
# File 'lib/genius/song.rb', line 3

def tracking_paths
  @tracking_paths
end

#updated_by_human_atObject (readonly)

Returns the value of attribute updated_by_human_at.



3
4
5
# File 'lib/genius/song.rb', line 3

def updated_by_human_at
  @updated_by_human_at
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/genius/song.rb', line 3

def url
  @url
end

#verified_annotations_byObject (readonly)

Returns the value of attribute verified_annotations_by.



3
4
5
# File 'lib/genius/song.rb', line 3

def verified_annotations_by
  @verified_annotations_by
end

Class Method Details

.search(query, params: {}, headers: {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/genius/song.rb', line 8

def self.search(query, params: {}, headers: {})
  headers = default_headers.merge(headers)
  params = default_params.merge(q: query).merge(params)

  response = http_get("/search", query: params, headers: headers)

  response["response"]["hits"].map do |hit|
    self.from_hash(hit["result"], text_format: params[:text_format])
  end
end

Instance Method Details



45
46
47
48
49
# File 'lib/genius/song.rb', line 45

def featured_artists
  @featured_artists ||= resource["featured_artists"].map do |artist|
    Artist.from_hash(artist)
  end
end

#parse_resource!Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/genius/song.rb', line 19

def parse_resource!
  @id = resource["id"]
  @url = resource["url"]
  @title = resource["title"]
  @media = resource["media"]
  @description_annotation = resource["description_annotation"]
  @annotation_count = resource["annotation_count"]
  @tracking_paths = resource["tracking_paths"]
  @description = formatted_attribute("description")
  @bop_url = resource["bop_url"]
  @header_image_url = resource["header_image_url"]

  if resource["updated_by_human_at"]
    @updated_by_human_at = Time.at(resource["updated_by_human_at"])
  end

  if resource["lyrics_updated_at"]
    @lyrics_updated_at = Time.at(resource["lyrics_updated_at"])
  end

  @pyongs_count = resource["pyongs_count"]
  @stats = resource["stats"]
  @current_user_metadata = resource["current_user_metadata"]
  @verified_annotations_by = resource["verified_annotations_by"]
end

#primary_artistObject



63
64
65
# File 'lib/genius/song.rb', line 63

def primary_artist
  @primary_artist ||= Artist.from_hash(resource["primary_artist"])
end

#producer_artistsObject



51
52
53
54
55
# File 'lib/genius/song.rb', line 51

def producer_artists
  @featured_artists ||= resource["producer_artists"].map do |artist|
    Artist.from_hash(artist)
  end
end

#writer_artistsObject



57
58
59
60
61
# File 'lib/genius/song.rb', line 57

def writer_artists
  @featured_artists ||= resource["writer_artists"].map do |artist|
    Artist.from_hash(artist)
  end
end