Skip to content

Commit

Permalink
Add tests for Yql::Client class plus the following:
Browse files Browse the repository at this point in the history
  * Rename Yql::Client#full_url to #path_without_domain
  * Modify Yql::Client#get to use #path_without_domain instead 
    of doing the same thing again
  • Loading branch information
nas committed Jun 22, 2010
1 parent a45e4cb commit 5683205
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.rdoc
Expand Up @@ -2,6 +2,10 @@


A basic Ruby Wrapper for interacting programatically with YQL API. A basic Ruby Wrapper for interacting programatically with YQL API.


The idea for this library came while attending the world's first Sciencehackday (@sciencehackday) in London - http://www.guardian.co.uk/open-platform/blog/science-hack-day-at-the-guardian.

Most of the people during science hack day were using YQL to fetch or post their data and some were using rails, so I thought it would be cool to have a ruby library that can provide interface to YQL to do a bunch of things programatically. And I ended up hacking together and releasing version 0.0.1 and 0.0.2 during the event.



==TODO ==TODO


Expand Down
7 changes: 3 additions & 4 deletions lib/yql/client.rb
Expand Up @@ -24,8 +24,8 @@ def version
@version ||= VERSION @version ||= VERSION
end end


def full_url def path_without_domain
"#{version}/#{URL_SUFFIX}" "/#{version}/#{URL_SUFFIX}"
end end


def get def get
Expand All @@ -34,8 +34,7 @@ def get
end end
http = Net::HTTP.new(BASE_URL, Net::HTTP.https_default_port) http = Net::HTTP.new(BASE_URL, Net::HTTP.https_default_port)
http.use_ssl = true http.use_ssl = true
path = "/#{version}/#{URL_SUFFIX}" Yql::Response.new(http.post(path_without_domain, parameters), format)
Yql::Response.new(http.post(path, parameters), format)
end end


def parameters def parameters
Expand Down
132 changes: 129 additions & 3 deletions spec/yql/client_spec.rb
Expand Up @@ -2,8 +2,134 @@


describe Yql::Client do describe Yql::Client do


before(:each) do describe ".new" do


context "when no arguments provided" do

before(:each) do
@yql_client = Yql::Client.new
end

it "should set the format to xml by default" do
@yql_client.format.should eql('xml')
end

it "should have the api version set to 'v1' by default" do
@yql_client.version.should eql('v1')
end

end

context "when arguments provided" do

before(:each) do
@yql_client = Yql::Client.new(:format => 'json', :version => 'v2')
end

it "should set the format" do
@yql_client.format.should eql('json')
end

it "should set the api version" do
@yql_client.version.should eql('v2')
end

end

describe "#query" do

before(:each) do
@yql_client = Yql::Client.new
end

context "when query is set to a string query" do

before(:each) do
@yql_client.query = "select * from yelp.review.search where term = 'something' and location like '%london%'"
end

it "should return the query string provided" do
@yql_client.query.should eql("select * from yelp.review.search where term = 'something' and location like '%london%'")
end

end

context "when query is set to the query builder object" do

before(:each) do
@query = Yql::QueryBuilder.new('yql.table.name')
@yql_client.query = @query
end

it "should build and return the query from the query builder object" do
@yql_client.query.should eql("select * from yql.table.name")
end

end

end

describe "#version" do

context "when version not provided on class initialization" do

before(:each) do
@yql_client = Yql::Client.new
end


it "should return the default version" do
@yql_client.version.should eql('v1')
end

end

context "when version provided on class initialization" do

before(:each) do
@yql_client = Yql::Client.new(:version => 'v4')
end


it "should return the default version" do
@yql_client.version.should eql('v4')
end

end
end

end

describe "#path_without_domain" do

before(:each) do
@yql_client = Yql::Client.new
end

context "when version not provided on class initialization" do

before(:each) do
@yql_client = Yql::Client.new
end


it "should return the path without the domain part" do
@yql_client.path_without_domain.should eql('/v1/public/yql')
end

end

context "when version provided on class initialization" do

before(:each) do
@yql_client = Yql::Client.new(:version => 'v4')
end


it "should return the path without the domain part" do
@yql_client.path_without_domain.should eql('/v4/public/yql')
end

end
end end

end end

0 comments on commit 5683205

Please sign in to comment.