Class: Spotify::API::Album
Constant Summary collapse
- ALBUMS_URL =
API endpoint for albums.
"#{BASE_URL}albums"
Constants inherited from Base
Base::BASE_URL, Base::FROM_TOKEN, Base::MAX_RETRIES, Base::SEARCH_URL
Instance Attribute Summary
Attributes inherited from Base
#params, #request, #response, #retries, #timeout, #url
Class Method Summary collapse
-
.search(args = {}) ⇒ Spotify::Models::Paging
Gets the albums related to the given parameters.
-
.search_by_id(args = {}) ⇒ Full::Album
Gets an album.
-
.search_by_ids(args = {}) ⇒ Array<Full::Album>
Gets an album.
-
.tracks(args = {}) ⇒ Full::Album
Gets an album.
Instance Method Summary collapse
-
#search(args = {}) ⇒ Spotify::Models::Paging
Gets the albums related to the given parameters.
-
#search_by_id(args = {}) ⇒ Full::Album
Gets an album.
-
#search_by_ids(args = {}) ⇒ Array<Full::Album>
Gets several albums.
-
#tracks(args = {}) ⇒ Paging
Gets the album’s tracks.
Methods inherited from Base
#body, #define_response, #get, #initialize, #make_request, #prepare_request, #run_with_timeout, #set_response
Constructor Details
This class inherits a constructor from Spotify::API::Base
Class Method Details
.search(args = {}) ⇒ Spotify::Models::Paging
Gets the albums related to the given parameters.
20 21 22 23 24 25 26 27 |
# File 'lib/spotify/api/album.rb', line 20 def self.search(args = {}) args[:type] = :album service_params = args.slice(:timeout, :retries) args = args.slice(:q, :market, :type, :limit, :offset) self.new(service_params).search(args) end |
.search_by_id(args = {}) ⇒ Full::Album
Gets an album.
38 39 40 41 42 43 |
# File 'lib/spotify/api/album.rb', line 38 def self.search_by_id(args = {}) service_params = args.slice(:timeout, :retries) args = args.slice(:id) self.new(service_params).search_by_id(args) end |
.search_by_ids(args = {}) ⇒ Array<Full::Album>
Gets an album.
54 55 56 57 58 59 60 61 |
# File 'lib/spotify/api/album.rb', line 54 def self.search_by_ids(args = {}) args[:ids] = Array(args[:ids]).join(',') service_params = args.slice(:timeout, :retries) args = args.slice(:ids) self.new(service_params).search_by_ids(args) end |
.tracks(args = {}) ⇒ Full::Album
Gets an album.
72 73 74 75 76 77 |
# File 'lib/spotify/api/album.rb', line 72 def self.tracks(args = {}) service_params = args.slice(:timeout, :retries) args = args.slice(:id, :limit, :offset, :market) self.new(service_params).tracks(args) end |
Instance Method Details
#search(args = {}) ⇒ Spotify::Models::Paging
Gets the albums related to the given parameters.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/spotify/api/album.rb', line 88 def search(args = {}) if args[:market].to_s.to_sym == FROM_TOKEN # TODO: Authorization. return Spotify::API::Errors::NOT_AVAILABLE end get(SEARCH_URL, args) define_response do klass = Spotify::Models::Simplified::Album Spotify::Models::Paging.new(response["albums"], klass) end end |
#search_by_id(args = {}) ⇒ Full::Album
Gets an album.
111 112 113 114 115 116 117 118 119 |
# File 'lib/spotify/api/album.rb', line 111 def search_by_id(args = {}) url = ALBUMS_URL + '/' + args[:id].to_s get(url) define_response do Spotify::Models::Full::Album.new(response) end end |
#search_by_ids(args = {}) ⇒ Array<Full::Album>
Gets several albums.
130 131 132 133 134 135 136 137 138 |
# File 'lib/spotify/api/album.rb', line 130 def search_by_ids(args = {}) get(ALBUMS_URL, args) define_response do response["albums"].map do |album| Spotify::Models::Full::Album.new(album) end end end |
#tracks(args = {}) ⇒ Paging
Gets the album’s tracks.
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/spotify/api/album.rb', line 147 def tracks(args = {}) url = ALBUMS_URL + '/' + args[:id] + '/tracks' params = args.slice(:limit, :offset, :market) get(url, params) define_response do klass = Spotify::Models::Simplified::Track Spotify::Models::Paging.new(response, klass) end end |