Created
May 14, 2010 07:33
-
-
Save erikeldridge/400922 to your computer and use it in GitHub Desktop.
A convenience function for making a call to YQL from Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a convenience function for making a call to YQL from Ruby | |
# License: Yahoo! BSD http://gist.github.com/375593 | |
# Usage: http://erikeldridge.wordpress.com/2010/02/18/ruby-yql-utility-function-example/ | |
require 'net/http' | |
require 'rubygems' | |
require 'json' | |
def yql(query) | |
uri = "http://query.yahooapis.com/v1/public/yql" | |
# everything's requested via POST, which is all I needed when I wrote this | |
# likewise, everything coming back is json encoded | |
response = Net::HTTP.post_form( URI.parse( uri ), { | |
'q' => query, | |
'format' => 'json' | |
} ) | |
json = JSON.parse( response.body ) | |
return json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment