Return to Snippet

Revision: 55106
at January 26, 2012 10:04 by chrisaiv


Initial Code
=begin
http://developer.spotify.com/en/metadata-api/overview/

Requests: http://ws.spotify.com/service/version/method[.format]?parameters

http://ws.spotify.com/search/1/track.json?q=kaizers+orchestra

Track Lookup
http://ws.spotify.com/lookup/1/.json?uri=spotify:track:6NmXV4o6bmp704aPGyTVVG

Artist lookup
http://ws.spotify.com/lookup/1/.json?uri=spotify:artist:4YrKBkKSVeqDamzBPWVnSJ
http://ws.spotify.com/lookup/1/.json?uri=spotify:artist:4YrKBkKSVeqDamzBPWVnSJ&extras=album
http://ws.spotify.com/lookup/1/.json?uri=spotify:artist:4YrKBkKSVeqDamzBPWVnSJ&extras=albumdetail

Album lookup
http://ws.spotify.com/lookup/1/.json?uri=spotify:album:6G9fHYDCoyEErUkHrFYfs4
http://ws.spotify.com/lookup/1/.json?uri=spotify:album:6G9fHYDCoyEErUkHrFYfs4&extras=track
http://ws.spotify.com/lookup/1/.json?uri=spotify:album:6G9fHYDCoyEErUkHrFYfs4&extras=trackdetail

Search Example
http://ws.spotify.com/search/1/artist?q=Bj%C3%B6rk.

=end

class SpotifyAPIRequest
  require 'open-uri'

  def initialize
    
  end
  
  def lookup( keyword )
    open("http://ws.spotify.com/search/1/track.json?q=" + keyword){
      |f|
      #Get the Full response which should be the full HTML
      @req = f.read
      #Find the first place where "No match is found", if nothing is found, it will return 'nil'
      puts @req
      
=begin 
      @txt = @req.index("No match")
      puts @txt

      if @txt.nil?
        puts "Domain " + word + ".com is available"
      else
        puts "Domain " + word + ".com is taken"
      end
=end
    }    
  end
end

spotify = SpotifyAPIRequest.new
spotify.lookup("beethoven")

Initial URL
http://developer.spotify.com/en/metadata-api/overview/

Initial Description
Simple test showing how to make a request to Spotify's API.

Initial Title
Ruby: Search Spotify API

Initial Tags
ruby

Initial Language
Ruby