Class: MTV::Artist
Overview
This class represents a music artist in MTV’s database.
Instance Attribute Summary collapse
-
#links ⇒ Object
Returns the value of attribute links.
-
#name ⇒ Object
Returns the value of attribute name.
-
#uid ⇒ Object
Returns the value of attribute uid.
-
#updated ⇒ Object
Returns the value of attribute updated.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
-
.browse(letter = 'a') ⇒ Object
Browse all artists by a single letter.
-
.find(name, options = {}) ⇒ Object
Find an artist by their specific name.
-
.related(artist) ⇒ Object
Finds any related artists, given an artist or artist name.
-
.search(term = nil, options = {}) ⇒ Object
Search all artists.
-
.videos(artist) ⇒ Object
Returns a list of MTV::Video instances that are by the given artist.
Instance Method Summary collapse
-
#browse ⇒ Object
Searches for artists with the same first letter.
-
#initialize(values = {}) ⇒ Artist
constructor
Creates a new artist, setting all the given hash keys as attributes.
- #inspect ⇒ Object
-
#related ⇒ Object
Searchs for related artists.
-
#videos ⇒ Object
Returns all
MTV::Video
s for this artist.
Methods inherited from Base
#attribute_for_inspect, request
Constructor Details
#initialize(values = {}) ⇒ Artist
Creates a new artist, setting all the given hash keys as attributes.
Attributes
-
options
- Possible attributes arename
,uid
,uri
,links
,updated
125 126 127 128 |
# File 'lib/mtv/artist.rb', line 125 def initialize(values={}) super(values) self.uid = uri.gsub(self.class.base_url + "/artist", '').delete '/' unless @uri.nil? end |
Instance Attribute Details
#links ⇒ Object
Returns the value of attribute links.
4 5 6 |
# File 'lib/mtv/artist.rb', line 4 def links @links end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/mtv/artist.rb', line 4 def name @name end |
#uid ⇒ Object
Returns the value of attribute uid.
4 5 6 |
# File 'lib/mtv/artist.rb', line 4 def uid @uid end |
#updated ⇒ Object
Returns the value of attribute updated.
4 5 6 |
# File 'lib/mtv/artist.rb', line 4 def updated @updated end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/mtv/artist.rb', line 4 def uri @uri end |
Class Method Details
.browse(letter = 'a') ⇒ Object
Browse all artists by a single letter.
Examples
MTV::Artist.browse('x')
> [#<MTV::Artist name: "X">, #<MTV::Artist name: "X-Clan">, #<MTV::Artist name: "The X-Ecutioners">, ... ]
17 18 19 20 21 |
# File 'lib/mtv/artist.rb', line 17 def browse(letter='a') response = request "artist/browse/#{letter.to_s.first}/" raise Error, "That artist not found!" if response.nil? || response.empty? parse_many response end |
.find(name, options = {}) ⇒ Object
Find an artist by their specific name. The name will be sanitized for the url, for example ‘Dinosaur Jr.’ becomes ‘dinosaur_jr’.
Examples
MTV::Artist.find('beck')
> #<MTV::Artist name: "Beck">
MTV::Artist.find('meGADeath')
> #<MTV::Artist name: "Megadeath">
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mtv/artist.rb', line 32 def find(name, ={}) return name if name.is_a? Artist .symbolize_keys! name = string_to_uid([:name] || name) response = request "artist/#{name}/" raise Error, "That artist not found!" if response.nil? || response.empty? parse_one response end |
.related(artist) ⇒ Object
Finds any related artists, given an artist or artist name.
Examples
MTV::Artist.related('Q Tip')
> [#<MTV::Artist name: "Allure">, #<MTV::Artist name: "Beastie Boys">, #<MTV::Artist name: "Busta Rhymes">, ... ]
49 50 51 52 53 54 |
# File 'lib/mtv/artist.rb', line 49 def (artist) artist = find(artist) response = request "artist/#{artist.uid}/related/" raise Error, "That artist not found!" if response.nil? || response.empty? parse_many response end |
.search(term = nil, options = {}) ⇒ Object
Search all artists.
Attributes
-
term
- The search term to find an artist -
options
-:max_results
and/or:start_index
for pagination.
Examples
MTV::Artist.search('Beck', :max_results => 1, :start_index => 1)
> [#<MTV::Artist name: "Beck">]
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/mtv/artist.rb', line 67 def search(term=nil, ={}) .symbolize_keys! params = {} params[:'max-results'] = [:max_results] || 1 params[:'start-index'] = [:start_index] term = [:term] || term params.reject! { |k,v| !v } response = request "artist/search?#{term.to_query('term')}&#{params.to_param}" raise Error, "That artist not found!" if response.nil? || response.empty? parse_many response end |
.videos(artist) ⇒ Object
Returns a list of MTV::Video instances that are by the given artist.
Examples
MTV::Artist.videos('buggles')
> [#<MTV::Video title: "Video Killed The Radio Star", artist_uri: "http://api.mtvnservices.com/1/artist/buggles/">]
85 86 87 |
# File 'lib/mtv/artist.rb', line 85 def videos(artist) MTV::Video.from_artist(artist) end |
Instance Method Details
#browse ⇒ Object
Searches for artists with the same first letter.
Examples
MTV::Artist.find('Sonic Youth').browse
> [#<MTV::Artist name: "The S.O.U.L. S.Y.S.T.E.M.">, #<MTV::Artist name: "S.T.U.N."> ... ]
141 142 143 |
# File 'lib/mtv/artist.rb', line 141 def browse @browse ||= Artist.browse(uid.first) end |
#inspect ⇒ Object
130 131 132 133 |
# File 'lib/mtv/artist.rb', line 130 def inspect attrs = [:name].map { |name| "#{name}: #{attribute_for_inspect(name)}" }.compact.join(", ") "#<#{self.class} #{attrs}>" end |
#related ⇒ Object
Searchs for related artists.
Examples
MTV::Artist.find('Sonic Youth').related
> [#<MTV::Artist name: "Beck">, #<MTV::Artist name: "Big Black">, #<MTV::Artist name: "Blonde Redhead"> ... ]
151 152 153 |
# File 'lib/mtv/artist.rb', line 151 def @related ||= Artist.(self) end |
#videos ⇒ Object
Returns all MTV::Video
s for this artist.
Examples
MTV::Artist.find('Sonic Youth').videos
> [#<MTV::Video title: "Incinerate", artist_uri: "http://api.mtvnservices.com/1/artist/sonic_youth/"> ... ]
162 163 164 |
# File 'lib/mtv/artist.rb', line 162 def videos @videos ||= Video.from_artist(self) end |