Class: SpotifyWeb::Artist

Inherits:
Resource show all
Defined in:
lib/spotify_web/artist.rb

Overview

Represents an artist on Spotify

Constant Summary

Constants inherited from Resource

Resource::BASE62_CHARS

Instance Attribute Summary collapse

Attributes inherited from Resource

#gid, #id, #uri, #uri_id

Method Summary

Methods inherited from Resource

#==, attribute, #attributes=, from_search_result, #hash, #initialize, #load, #load_metadata, #loaded?, #metadata=, #metadata_uri, #pretty_print, #pretty_print_instance_variables

Methods included from Assertions

#assert_valid_keys, #assert_valid_values

Constructor Details

This class inherits a constructor from SpotifyWeb::Resource

Instance Attribute Details

#albumsArray<SpotifyWeb::Album> (readonly)

The albums this artist has recorded

Returns:


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/spotify_web/artist.rb', line 27

attribute :albums, :album_group do |groups|
  # Track all available albums
  albums = []
  groups.each do |group|
    group_albums = []
    group.album.each do |album|
      album = Album.new(client, album.to_hash)
      group_albums << album if album.available?
    end

    albums.concat(group_albums)
  end

  # Load the data to completely determine what albums to give back
  albums = ResourceCollection.new(client, albums)
  albums.load

  # Reject duplicate titles
  albums_by_title = albums.inject({}) do |result, album|
    result[album.title] = album
    result
  end
  albums.reject! {|album| albums_by_title[album.title] != album}

  albums
end

#nameString (readonly)

The title of the artist

Returns:

  • (String)

11
# File 'lib/spotify_web/artist.rb', line 11

attribute :name

#popularityFixnum (readonly)

The relative popularity of this artist on Spotify

Returns:

  • (Fixnum)

15
# File 'lib/spotify_web/artist.rb', line 15

attribute :popularity

#top_songsArray<SpotifyWeb::Song> (readonly)

The top songs for this artist

Returns:


19
20
21
22
23
# File 'lib/spotify_web/artist.rb', line 19

attribute :top_songs, :top_track do |groups|
  group = groups.detect {|group| group.country == 'US'}
  songs = group.track.map {|song| Song.new(client, song.to_hash)}
  ResourceCollection.new(client, songs)
end