Skip to content

Commit

Permalink
Add Yql::Response class and modify Yql::Client class to
Browse files Browse the repository at this point in the history
return response object
  • Loading branch information
nas committed Jun 20, 2010
1 parent f370ed0 commit 7925c6e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
12 changes: 7 additions & 5 deletions README.rdoc
Expand Up @@ -61,10 +61,10 @@ query.to_s #=> "select * from yelp.review.search where term='pizza' and location
query.select = 'user_photo_url, state'

yql.query = query
result = yql.get
response = yql.get

yql.format = 'json'
result = yql.get
response = yql.get #=> Yql::Response object


===Piped Filters
Expand All @@ -82,7 +82,7 @@ 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'
result = yql.get
response = yql.get #=> Yql::Response object


====Pagination
Expand All @@ -91,7 +91,7 @@ query.per_page = 10
query.current_page = 1

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


===Describe and show tables
Expand All @@ -101,4 +101,6 @@ query = Yql::QueryBuilder.describe_table('yelp.review.search')
query = Yql::QueryBuilder.show_tables

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

response.show
3 changes: 2 additions & 1 deletion lib/yql.rb
Expand Up @@ -8,4 +8,5 @@
require 'rexml/document'
require 'yql/error.rb'
require 'yql/client.rb'
require 'yql/query_builder.rb'
require 'yql/query_builder.rb'
require 'yql/response.rb'
5 changes: 1 addition & 4 deletions lib/yql/client.rb
Expand Up @@ -35,10 +35,7 @@ def get
http = Net::HTTP.new(BASE_URL, Net::HTTP.https_default_port)
http.use_ssl = true
path = "/#{version}/#{URL_SUFFIX}"
result = http.post(path, parameters)
#raise(Yql::ResponseFailure, result.response) unless result.code == '200'
return result.body unless format == 'xml'
REXML::Document.new(result.body)
Yql::Response.new(http.post(path, parameters), format)
end

def parameters
Expand Down
36 changes: 36 additions & 0 deletions lib/yql/response.rb
@@ -0,0 +1,36 @@
module Yql

class Response

def initialize(response, format)
@response = response
@format = format
end

def show
raise Yql::ResponseFailure, body.inspect unless success?
output
end

def body
@response.body
end

def code
@response.code
end

def success?
code == '200'
end

private

def output
return body unless @format == 'xml'
REXML::Document.new(body)
end

end

end

0 comments on commit 7925c6e

Please sign in to comment.