views:

35

answers:

2

Hi - I'm playing around with the new yahoo API. I'd like to scrap some dummy data using the following address

http://query.yahooapis.com/v1/public/yql?q=desc%20social.updates.search&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=cbfunc

When I run this I get an authenticaion error (Need to be logged into Yahoo) This is fine obviously for me messing around on the internet. However I'd like to call this from a ruby script. Any ideas how I go about authenticating? I can only seem to find some web enabled version.

A: 

You might try the Mechanize gem for this. I've used it for other authenticated services in the past.

Benjamin Oakes
A: 

I'd also recomment httparty -- It is ridiculously easy to map JSON services with this. Try this:

require 'rubygems'
require 'httparty'

class Yahoo
  include HTTParty
  # i don't think you need auth for this endpoint -- but if you do, uncomment below and fill it in
  #basic_auth 'username', 'password'
  format :json

  def self.load
    self.get 'http://query.yahooapis.com/v1/public/yql', :query => {:q => 'desc social.updates.search', :format => 'json', :diagnostics => true, :env => 'store://datatables.org/alltableswithkeys'}
  end
end

puts Yahoo.load
RobH