Class: RSpotify::Album
Instance Attribute Summary collapse
-
#album_type ⇒ String
The type of the album (album, single, compilation).
-
#artists ⇒ Array<Artist>
The artists of the album.
-
#available_markets ⇒ Array<String>
The markets in which the album is available.
-
#copyrights ⇒ Array<Hash>
The copyright statements of the album.
-
#external_ids ⇒ Hash
Known external IDs for the album.
-
#genres ⇒ Array<String>
A list of the genres used to classify the album.
-
#images ⇒ Array<Hash>
The cover art for the album in various sizes, widest first.
-
#name ⇒ String
The name of the album.
-
#popularity ⇒ Integer
The popularity of the album.
-
#release_date ⇒ String
The date the album was first released, for example “1981-12-15”.
-
#release_date_precision ⇒ String
The precision with which release_date value is known: “year”, “month”, or “day”.
Attributes inherited from Base
#external_urls, #href, #id, #type, #uri
Class Method Summary collapse
-
.find(ids) ⇒ Album+
Returns Album object(s) with id(s) provided.
-
.new_releases(limit: 20, offset: 0, country: nil) ⇒ Array<Album>
Get a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab).
-
.search(query, limit: 20, offset: 0, market: nil) ⇒ Array<Album>
Returns array of Album objects matching the query, ordered by popularity.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Album
constructor
A new instance of Album.
-
#tracks(limit: 50, offset: 0) ⇒ Array<Track>
Returns array of tracks from the album.
Methods inherited from Base
#complete!, #method_missing, #respond_to?
Constructor Details
#initialize(options = {}) ⇒ Album
Returns a new instance of Album.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rspotify/album.rb', line 71 def initialize( = {}) @album_type = ['album_type'] @available_markets = ['available_markets'] @copyrights = ['copyrights'] @external_ids = ['external_ids'] @genres = ['genres'] @images = ['images'] @name = ['name'] @popularity = ['popularity'] @release_date = ['release_date'] @release_date_precision = ['release_date_precision'] @artists = if ['artists'] ['artists'].map { |a| Artist.new a } end @tracks_cache = if ['tracks'] && ['tracks']['items'] ['tracks']['items'].map { |i| Track.new i } end super() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RSpotify::Base
Instance Attribute Details
#album_type ⇒ String
The type of the album (album, single, compilation)
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def album_type @album_type end |
#artists ⇒ Array<Artist>
The artists of the album
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def artists @artists end |
#available_markets ⇒ Array<String>
The markets in which the album is available. See ISO 3166-1 alpha-2 country codes
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def available_markets @available_markets end |
#copyrights ⇒ Array<Hash>
The copyright statements of the album
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def copyrights @copyrights end |
#external_ids ⇒ Hash
Known external IDs for the album
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def external_ids @external_ids end |
#genres ⇒ Array<String>
A list of the genres used to classify the album. If not yet classified, the array is empty
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def genres @genres end |
#images ⇒ Array<Hash>
The cover art for the album in various sizes, widest first
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def images @images end |
#name ⇒ String
The name of the album
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def name @name end |
#popularity ⇒ Integer
The popularity of the album. The value will be between 0 and 100, with 100 being the most popular
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def popularity @popularity end |
#release_date ⇒ String
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”
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def release_date @release_date end |
#release_date_precision ⇒ String
The precision with which release_date value is known: “year”, “month”, or “day”
14 15 16 |
# File 'lib/rspotify/album.rb', line 14 def release_date_precision @release_date_precision end |
Class Method Details
.find(ids) ⇒ Album+
Returns Album object(s) with id(s) provided
30 31 32 |
# File 'lib/rspotify/album.rb', line 30 def self.find(ids) super(ids, 'album') end |
.new_releases(limit: 20, offset: 0, country: nil) ⇒ Array<Album>
Get a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab).
44 45 46 47 48 49 50 51 |
# File 'lib/rspotify/album.rb', line 44 def self.new_releases(limit: 20, offset: 0, country: nil) url = "browse/new-releases?limit=#{limit}&offset=#{offset}" url << "&country=#{country}" if country response = RSpotify.get(url) return response if RSpotify.raw_response response['albums']['items'].map { |i| Album.new i } end |
.search(query, limit: 20, offset: 0, market: nil) ⇒ Array<Album>
Returns array of Album objects matching the query, ordered by popularity. It’s also possible to find the total number of search results for the query
67 68 69 |
# File 'lib/rspotify/album.rb', line 67 def self.search(query, limit: 20, offset: 0, market: nil) super(query, 'album', limit: limit, offset: offset, market: market) end |
Instance Method Details
#tracks(limit: 50, offset: 0) ⇒ Array<Track>
Returns array of tracks from the album
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rspotify/album.rb', line 103 def tracks(limit: 50, offset: 0) last_track = offset + limit - 1 if @tracks_cache && last_track < 50 && !RSpotify.raw_response return @tracks_cache[offset..last_track] end url = "albums/#{@id}/tracks?limit=#{limit}&offset=#{offset}" response = RSpotify.get(url) json = RSpotify.raw_response ? JSON.parse(response) : response tracks = json['items'].map { |i| Track.new i } @tracks_cache = tracks if limit == 50 && offset == 0 return response if RSpotify.raw_response tracks end |