Sha256: 11efbf229c32c61999040a4d7c798d825ccd82df5023fb0b10c01ad2df1f376a

Contents?: true

Size: 1.14 KB

Versions: 37

Compression:

Stored size: 1.14 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, "/v1/yql?q=#{OAuth::Helper.escape(query)}&format=json")
rsp = JSON.parse(response.body)
pp rsp

Version data entries

37 entries across 36 versions & 19 rubygems

Version Path
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/oauth-0.4.7/examples/yql.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/oauth-0.4.7/examples/yql.rb
oauth-ap-0.4.8 examples/yql.rb
greut-oauth-0.3.6 examples/yql.rb
jwhitmire-oauth-0.3.6.1 examples/yql.rb
mojodna-oauth-0.3.4.1 examples/yql.rb
mojodna-oauth-0.3.5 examples/yql.rb
mojodna-oauth-0.3.6 examples/yql.rb
monkeyhelper-oauth-0.3.5 examples/yql.rb
mzsanford-oauth-0.3.2.2 examples/yql.rb
pelle-oauth-0.3.5 examples/yql.rb
pelle-oauth-0.3.6 examples/yql.rb
sporkd-oauth-0.3.6 examples/yql.rb
oauth-instructure-0.4.10 examples/yql.rb
oauth_weshays-0.4.8.pre2 examples/yql.rb
oauth_weshays-0.4.8.pre examples/yql.rb
oauth-instructure-0.4.9 examples/yql.rb
oauth-instructure-0.4.8 examples/yql.rb
oauth-0.4.7 examples/yql.rb
motionbox-oauth-0.4.5 examples/yql.rb