Class: RSpotify::Album

Inherits:
Base
  • Object
show all
Defined in:
lib/rspotify/album.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#external_urls, #href, #id, #type, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#complete!, #method_missing, #respond_to?

Constructor Details

#initialize(options = {}) ⇒ Album

Returns a new instance of Album.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/rspotify/album.rb', line 53

def initialize(options = {})
  @album_type             = options['album_type']
  @available_markets      = options['available_markets']
  @external_ids           = options['external_ids']
  @genres                 = options['genres']
  @images                 = options['images']
  @name                   = options['name']
  @popularity             = options['popularity']
  @release_date           = options['release_date']
  @release_date_precision = options['release_date_precision']

  @artists = if options['artists']
    options['artists'].map { |a| Artist.new a }
  end

  @tracks = if options['tracks'] && options['tracks']['items']
    options['tracks']['items'].map { |t| Track.new t }
  end

  super(options)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RSpotify::Base

Instance Attribute Details

#album_typeString

The type of the album (album, single, compilation)

Returns:

  • (String)

    the current value of album_type



14
15
16
# File 'lib/rspotify/album.rb', line 14

def album_type
  @album_type
end

#artistsArray<Artist>

The artists of the album

Returns:

  • (Array<Artist>)

    the current value of artists



14
15
16
# File 'lib/rspotify/album.rb', line 14

def artists
  @artists
end

#available_marketsArray<String>

The markets in which the album is available. See ISO 3166-1 alpha-2 country codes

Returns:

  • (Array<String>)

    the current value of available_markets



14
15
16
# File 'lib/rspotify/album.rb', line 14

def available_markets
  @available_markets
end

#external_idsHash

Known external IDs for the album

Returns:

  • (Hash)

    the current value of external_ids



14
15
16
# File 'lib/rspotify/album.rb', line 14

def external_ids
  @external_ids
end

#genresArray<String>

A list of the genres used to classify the album. If not yet classified, the array is empty

Returns:

  • (Array<String>)

    the current value of genres



14
15
16
# File 'lib/rspotify/album.rb', line 14

def genres
  @genres
end

#imagesArray<Hash>

The cover art for the album in various sizes, widest first

Returns:

  • (Array<Hash>)

    the current value of images



14
15
16
# File 'lib/rspotify/album.rb', line 14

def images
  @images
end

#nameString

The name of the album

Returns:

  • (String)

    the current value of name



14
15
16
# File 'lib/rspotify/album.rb', line 14

def name
  @name
end

#popularityInteger

The popularity of the album. The value will be between 0 and 100, with 100 being the most popular

Returns:

  • (Integer)

    the current value of popularity



14
15
16
# File 'lib/rspotify/album.rb', line 14

def popularity
  @popularity
end

#release_dateString

The date the album was first released, for example “1981-12-15”. Depending on the precision, it might be shown as “1981” or “1981-12”

Returns:

  • (String)

    the current value of release_date



14
15
16
# File 'lib/rspotify/album.rb', line 14

def release_date
  @release_date
end

#release_date_precisionString

The precision with which release_date value is known: “year”, “month”, or “day”

Returns:

  • (String)

    the current value of release_date_precision



14
15
16
# File 'lib/rspotify/album.rb', line 14

def release_date_precision
  @release_date_precision
end

#tracksArray<Track>

The tracks of the album.

Returns:

  • (Array<Track>)

    the current value of tracks



14
15
16
# File 'lib/rspotify/album.rb', line 14

def tracks
  @tracks
end

Class Method Details

.find(ids) ⇒ Album+

Returns Album object(s) with id(s) provided

Examples:

album = RSpotify::Album.find('41vPD50kQ7JeamkxQW7Vuy')
album.class #=> RSpotify::Album
album.name  #=> "AM"

ids = %w(41vPD50kQ7JeamkxQW7Vuy 4jKGRliQXa5VwxKOsiCbfL)
albums = RSpotify::Album.find(ids)
albums.class       #=> Array
albums.first.class #=> RSpotify::Album

Parameters:

  • ids (String, Array)

    Maximum: 20 IDs

Returns:



30
31
32
# File 'lib/rspotify/album.rb', line 30

def self.find(ids)
  super(ids, 'album')
end

.search(query, limit = 20, offset = 0) ⇒ Array<Album>

Returns array of Album objects matching the query, ordered by popularity

Examples:

albums = RSpotify::Album.search('AM')
albums.size        #=> 20
albums.first.class #=> RSpotify::Album
albums.first.name  #=> "AM"

albums = RSpotify::Base.search('AM', 10)
albums.size #=> 10

Parameters:

  • query (String)

    The search query’s keywords. See the q description in here for details.

  • limit (Integer) (defaults to: 20)

    Maximum number of albums to return. Minimum: 1. Maximum: 50.

  • offset (Integer) (defaults to: 0)

    The index of the first album to return. Use with limit to get the next set of albums.

Returns:



49
50
51
# File 'lib/rspotify/album.rb', line 49

def self.search(query, limit = 20, offset = 0)
  super(query, 'album', limit, offset)
end