Class: Genius::Song
Instance Attribute Summary collapse
-
#annotation_count ⇒ Object
readonly
Returns the value of attribute annotation_count.
-
#bop_url ⇒ Object
readonly
Returns the value of attribute bop_url.
-
#current_user_metadata ⇒ Object
readonly
Returns the value of attribute current_user_metadata.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#description_annotation ⇒ Object
readonly
Returns the value of attribute description_annotation.
-
#header_image_url ⇒ Object
readonly
Returns the value of attribute header_image_url.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#lyrics_updated_at ⇒ Object
readonly
Returns the value of attribute lyrics_updated_at.
-
#media ⇒ Object
readonly
Returns the value of attribute media.
-
#pyongs_count ⇒ Object
readonly
Returns the value of attribute pyongs_count.
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#tracking_paths ⇒ Object
readonly
Returns the value of attribute tracking_paths.
-
#updated_by_human_at ⇒ Object
readonly
Returns the value of attribute updated_by_human_at.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#verified_annotations_by ⇒ Object
readonly
Returns the value of attribute verified_annotations_by.
Attributes inherited from Resource
Class Method Summary collapse
Instance Method Summary collapse
- #featured_artists ⇒ Object
- #parse_resource! ⇒ Object
- #primary_artist ⇒ Object
- #producer_artists ⇒ Object
- #writer_artists ⇒ Object
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_count ⇒ Object (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_url ⇒ Object (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_metadata ⇒ Object (readonly)
Returns the value of attribute current_user_metadata.
3 4 5 |
# File 'lib/genius/song.rb', line 3 def @current_user_metadata end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/genius/song.rb', line 3 def description @description end |
#description_annotation ⇒ Object (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_url ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/genius/song.rb', line 3 def id @id end |
#lyrics_updated_at ⇒ Object (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 |
#media ⇒ Object (readonly)
Returns the value of attribute media.
3 4 5 |
# File 'lib/genius/song.rb', line 3 def media @media end |
#pyongs_count ⇒ Object (readonly)
Returns the value of attribute pyongs_count.
3 4 5 |
# File 'lib/genius/song.rb', line 3 def pyongs_count @pyongs_count end |
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
3 4 5 |
# File 'lib/genius/song.rb', line 3 def stats @stats end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/genius/song.rb', line 3 def title @title end |
#tracking_paths ⇒ Object (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_at ⇒ Object (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 |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/genius/song.rb', line 3 def url @url end |
#verified_annotations_by ⇒ Object (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
#featured_artists ⇒ Object
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_artist ⇒ Object
63 64 65 |
# File 'lib/genius/song.rb', line 63 def primary_artist @primary_artist ||= Artist.from_hash(resource["primary_artist"]) end |