Module: Spotify
- Includes:
- HTTParty
- Defined in:
- lib/spotify.rb,
lib/spotify/version.rb
Overview
Public: Various methods for interacting with the Spotify Metadata API. Please read the Terms of Use for this API (is.gd/0Mcl04) before using it.
Examples
require 'spotify'
artists = Spotify.search_artist 'Radiohead'
puts artists.first.name # => 'Radiohead'
album = Spotify.search_album('The King of Limbs').first
puts "#{album.artist.name} - #{album.name}" # => Radiohead - Kid A
Defined Under Namespace
Constant Summary
- API_VERSION =
Internal: The version Integer of Spotify's API.
1- VERSION =
Internal: The version String of this library.
'0.1.0'
Class Method Summary (collapse)
-
+ (Object) lookup_album(uri, extras = nil)
Public: Looks up an Spotify album URI.
-
+ (Object) lookup_artist(uri, extras = nil)
Public: Looks up an Spotify artist URI.
-
+ (Object) lookup_track(uri)
Public: Looks up an Spotify track URI.
-
+ (Object) search_album(name, options = {})
Public: searches the Spotify API for albums.
-
+ (Object) search_artist(name, options = {})
Public: Searches the Spotify API for artists.
-
+ (Object) search_track(name, options = {})
Public: searches the Spotify API for tracks.
Class Method Details
+ (Object) lookup_album(uri, extras = nil)
Public: Looks up an Spotify album URI.
uri - The Spotify URI String that needs to be lookup up. extras - A Symbol that defines the detail level expected in the response
(default: nil).
:track - request basic information about all tracks in the
album.
:trackdetail - request detailed information about all tracks in the
album.
Returns nil or an Spotify::Album object.
89 90 91 92 93 94 95 96 |
# File 'lib/spotify.rb', line 89 def self.lookup_album(uri, extras = nil) query = extras.nil? ? { :uri => uri } : { :uri => uri, :extras => extras } album = Album.new self.lookup(query)['album'] album.tracks.map! { |track| Track.new track } if extras album end |
+ (Object) lookup_artist(uri, extras = nil)
Public: Looks up an Spotify artist URI.
uri - The Spotify URI String that needs to be lookup up. extras - A Symbol that define the detail level expected in the response
(default: nil).
:album - request basic information about all the albums the
artist is featured in.
:albumdetail - request detailed information about all the albums
the artist is featured in
Returns nil or an Spotify::Artist object.
69 70 71 72 73 74 75 76 |
# File 'lib/spotify.rb', line 69 def self.lookup_artist(uri, extras = nil) query = extras.nil? ? { :uri => uri } : { :uri => uri, :extras => extras } artist = Artist.new self.lookup(query)['artist'] artist.albums.map! { |album| Album.new album['album'] } if extras artist end |
+ (Object) lookup_track(uri)
Public: Looks up an Spotify track URI.
uri - The Spotify URI String that needs to be lookup up.
Returns nil or an Spotify::Track object.
103 104 105 |
# File 'lib/spotify.rb', line 103 def self.lookup_track(uri) Track.new self.lookup(:uri => uri)['track'] end |
+ (Object) search_album(name, options = {})
Public: searches the Spotify API for albums.
name - The name String of the album. options - The Hash options send along with the request (default: {}).
:page - The page of the result set (optional).
Returns nil or an Array of Spotify::Album objects.
43 44 45 |
# File 'lib/spotify.rb', line 43 def self.search_album(name, = {}) self.search :album, .merge(:q => name) end |
+ (Object) search_artist(name, options = {})
Public: Searches the Spotify API for artists.
name - The name String of the artist. options - The Hash options send along with the request (default: {}).
:page - The page of the result set (optional).
Returns nil or an Array of Spotify::Artist objects.
32 33 34 |
# File 'lib/spotify.rb', line 32 def self.search_artist(name, = {}) self.search :artist, .merge(:q => name) end |
+ (Object) search_track(name, options = {})
Public: searches the Spotify API for tracks.
name - The name String of the track. options - The Hash options send along with the request (default: {}).
:page - The page of the result set (optional).
Returns nil or an Array of Spotify::Track objects.
54 55 56 |
# File 'lib/spotify.rb', line 54 def self.search_track(name, = {}) self.search :track, .merge(:q => name) end |