/ Published in: Ruby
Simple test showing how to make a request to Spotify's API.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
=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")
URL: http://developer.spotify.com/en/metadata-api/overview/