Skip to content

Instantly share code, notes, and snippets.

@erikeldridge
Created May 14, 2010 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikeldridge/400922 to your computer and use it in GitHub Desktop.
Save erikeldridge/400922 to your computer and use it in GitHub Desktop.
A convenience function for making a call to YQL from Ruby
# 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