Sha256: f2693253b50de9a3c12ca1fa9de8254458793881aaeac8082c40e2cf37bf6bf5

Contents?: true

Size: 1.15 KB

Versions: 16

Compression:

Stored size: 1.15 KB

Contents

#!/usr/bin/env ruby -rubygems

# Sample queries:
#  ./yql.rb --consumer-key <key> --consumer-secret <secret> "show tables"
#  ./yql.rb --consumer-key <key> --consumer-secret <secret> "select * from flickr.photos.search where text='Cat' limit 10"

require 'oauth'
require 'optparse'
require 'json'
require 'pp'

options = {}

option_parser = OptionParser.new do |opts|
  opts.banner = "Usage: #{$0} [options] <query>"

  opts.on("--consumer-key KEY", "Specifies the consumer key to use.") do |v|
    options[:consumer_key] = v
  end

  opts.on("--consumer-secret SECRET", "Specifies the consumer secret to use.") do |v|
    options[:consumer_secret] = v
  end
end

option_parser.parse!
query = ARGV.pop
query = STDIN.read if query == "-"

if options[:consumer_key].nil? || options[:consumer_secret].nil? || query.nil?
  puts option_parser.help
  exit 1
end

consumer = OAuth::Consumer.new \
  options[:consumer_key],
  options[:consumer_secret],
  :site => "http://query.yahooapis.com"

access_token = OAuth::AccessToken.new(consumer)

response = access_token.request(:get, url = "/v1/yql?q=#{OAuth::Helper.escape(query)}&format=json")
rsp = JSON.parse(response.body)
pp rsp

Version data entries

16 entries across 16 versions & 6 rubygems

Version Path
metavida-oauth-0.3.2.1 examples/yql.rb
metavida-oauth-0.3.2 examples/yql.rb
mojodna-oauth-0.3.1.6 examples/yql.rb
mojodna-oauth-0.3.1.7 examples/yql.rb
mojodna-oauth-0.3.1.8 examples/yql.rb
mojodna-oauth-0.3.2.1 examples/yql.rb
mojodna-oauth-0.3.2.2 examples/yql.rb
mojodna-oauth-0.3.2 examples/yql.rb
mojodna-oauth-0.3.3 examples/yql.rb
mojodna-oauth-0.3.4 examples/yql.rb
vincentchu-oauth-0.3.2.111 examples/yql.rb
zmalltalker-oauth-0.3.1.7 examples/yql.rb
af-oauth-0.3.4.1 examples/yql.rb
oauth-0.3.2 examples/yql.rb
oauth-0.3.3 examples/yql.rb
oauth-0.3.4 examples/yql.rb