Permalink
Browse files

Add tests for Yql::Client class plus the following:

  * 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...
1 parent a45e4cb commit 56832050d2f0261580d8bbf159b7dc3786d1a981 nas committed Jun 22, 2010
Showing with 136 additions and 7 deletions.
  1. +4 −0 README.rdoc
  2. +3 −4 lib/yql/client.rb
  3. +129 −3 spec/yql/client_spec.rb
View
@@ -2,6 +2,10 @@
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
View
@@ -24,8 +24,8 @@ def version
@version ||= VERSION
end
- def full_url
- "#{version}/#{URL_SUFFIX}"
+ def path_without_domain
+ "/#{version}/#{URL_SUFFIX}"
end
def get
@@ -34,8 +34,7 @@ def get
end
http = Net::HTTP.new(BASE_URL, Net::HTTP.https_default_port)
http.use_ssl = true
- path = "/#{version}/#{URL_SUFFIX}"
- Yql::Response.new(http.post(path, parameters), format)
+ Yql::Response.new(http.post(path_without_domain, parameters), format)
end
def parameters
View
@@ -2,8 +2,134 @@
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

0 comments on commit 5683205

Please sign in to comment.