Skip to content

Instantly share code, notes, and snippets.

@zlu
Created September 10, 2009 23:28
Show Gist options
  • Save zlu/184913 to your computer and use it in GitHub Desktop.
Save zlu/184913 to your computer and use it in GitHub Desktop.
"**********"
{"query"=>{"results"=>{"result"=>{"value"=>"got some data here"}}, "uri"=>"http://query.yahooapis.com/v1/yql?q=SELECT+*+FROM+yql.storage+WHERE+name+%3D+%27store%3A%2F%2FLymM4H0i9TI0FgdrLZlAE1%27", "diagnostics"=>{"build-version"=>"3130", "publiclyCallable"=>"true", "user-time"=>"34", "service-time"=>"31"}, "count"=>"1", "lang"=>"en-US", "updated"=>Thu Sep 10 11:24:04 UTC 2009, "created"=>Thu Sep 10 11:24:04 UTC 2009}}
"**********"
{"query"=>{"results"=>{"success"=>"Updated store://jQhfGRIErjcVVzd4wOY2nj"}, "uri"=>"http://query.yahooapis.com/v1/yql?q=UPDATE+yql.storage+SET+value%3D%27%7B%22apples%22%3A%22green%22%2C%22bananas%22%3A%22yellow%22%7D%27+WHERE+name+%3D+%27store%3A%2F%2Fk02azLQDF27kArKxszngfx%27", "diagnostics"=>{"build-version"=>"3130", "publiclyCallable"=>"true", "user-time"=>"65", "service-time"=>"64"}, "count"=>"1", "lang"=>"en-US", "updated"=>Thu Sep 10 11:24:04 UTC 2009, "created"=>Thu Sep 10 11:24:04 UTC 2009}}
"**********"
{"query"=>{"results"=>{"result"=>{"value"=>{"bananas"=>"yellow", "apples"=>"green"}}}, "uri"=>"http://query.yahooapis.com/v1/yql?q=SELECT+*+FROM+yql.storage+WHERE+name+%3D+%27store%3A%2F%2FLymM4H0i9TI0FgdrLZlAE1%27", "diagnostics"=>{"build-version"=>"3130", "publiclyCallable"=>"true", "user-time"=>"36", "service-time"=>"31"}, "count"=>"1", "lang"=>"en-US", "updated"=>Thu Sep 10 11:24:04 UTC 2009, "created"=>Thu Sep 10 11:24:04 UTC 2009}}
"**********"
require 'rubygems'
require 'httparty'
require 'json'
class YQL
include HTTParty
format :json
base_uri 'http://query.yahooapis.com'
def initialize(params)
@execute_key = params[:execute_key]
@select_key = params[:select_key]
@update_key = params[:update_key]
@extended_url = '/v1/public/yql?format=json&q='
end
def get_datastore
query = "SELECT * FROM yql.storage WHERE name = '#{@select_key}'"
url = URI.encode(@extended_url + query)
self.class.get url
end
def update_datastore(hash_table)
query = "UPDATE yql.storage SET value='#{hash_table.to_json}' WHERE name = '#{@update_key}'"
url = URI.encode(@extended_url + query)
self.class.put url
end
end
yql = YQL.new({ :execute_key => 'store://',
:select_key => 'store://',
:update_key => 'store://' })
#First lets see whats in there
p '*'*10
p yql.get_datastore
p '*'*10
#Lets update
p yql.update_datastore({ :apples => 'green', :bananas => 'yellow' })
p '*'*10
#Now whats in there?
p yql.get_datastore
p '*'*10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment