Skip to content
Ruby Wrapper for Yahoo Query Language
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
spec
History.txt
Manifest.txt
README.rdoc
yql.gemspec

README.rdoc

DESCRIPTION

A basic Ruby Wrapper for interacting programatically with YQL API.

TODO

  1. Add Unit Tests

  2. Add oauth

  3. Add table creation

  4. Add update / insert / delete operations

INSTALLATION

sudo gem source –add rubygems.org

sudo gem install yql

USAGE

require 'rubygems'

require 'yql'

Building Query

Finders

yql = Yql::Client.new

  • Query builder takes table as mandatory parameter.

query = Yql::QueryBuilder.new 'yelp.review.search'

query.to_s #=> “select * from yelp.review.search”

query.find #=> “select * from yelp.review.search limit 1”

query.limit = 4

query.to_s #=> “select * from yelp.review.search limit 4”

query.find_all #=> “select * from yelp.review.search”

Conditions

  • Conditions for a query can be either provided as a string or a hash just like rails

query.conditions = “term like '%pizza%'”

query.to_s #=> “select * from yelp.review.search where term='%pizza%'”

query.conditions = {:term => 'pizza', :location => 'london', 'ywsid' => '6L0Lc-yn1OKMkCKeXLD4lg'}

query.to_s #=> “select * from yelp.review.search where term='pizza' and location='london' and ywsid= '6L0Lc-yn1OKMkCKeXLD4lg'”

query.select = 'user_photo_url, state'

yql.query = query

response = yql.get

  • the above method call will give an xml output, set the yql client format to json like so

yql.format = 'json'

response = yql.get #=> Yql::Response object

response.show

  • to print the xml output on console

response.show.to_s

Piped Filters

query.unique = 'name'

query.to_s #=> “select title, Rating, LastReviewIntro from yelp.review.search where ywsid='6L0Lc-yn1OKMkCKeXLD4lg' and term='pizza' and location='london' | unique(field='name')”

query.tail = 4

query.to_s #=> “select title, Rating, LastReviewIntro from yelp.review.search where ywsid='6L0Lc-yn1OKMkCKeXLD4lg' and term='pizza' and location='london' | unique(field='name') | tail(count=4)”

query.reorder_pipe_command :from => 1, :to => 0

query.to_s #=> “select title, Rating, LastReviewIntro from yelp.review.search where ywsid='6L0Lc-yn1OKMkCKeXLD4lg' and term='pizza' and location='london' | tail(count=4) | unique(field='name')”

yql.format = 'json'

response = yql.get #=> Yql::Response object

  • to print the xml output on console

response.show.to_s

Pagination

query.per_page = 10

query.current_page = 1

yql.query = query

response = yql.get #=> Yql::Response object

Describe and show tables

  • To describe a table and see its required parameters, etc.

query = Yql::QueryBuilder.describe_table('yelp.review.search')

  • To see all the table sources and their names in YQL

query = Yql::QueryBuilder.show_tables

yql.query = query

response = yql.get #=> Yql::Response object

response.show

Something went wrong with that request. Please try again.