Permalink
Browse files

Add Search#search method

  • Loading branch information...
1 parent d156fd5 commit 327724b8edcefaf726d9d92c7e9d8f5380003097 @sferik committed Sep 4, 2011
@@ -2,7 +2,7 @@ module Twitter
class Client
# Defines methods related to Search
module Search
- # Returns recent images related to a query
+ # Returns recent statuses that contain images related to a query
#
# @note Undocumented
# @rate_limited Yes
@@ -14,14 +14,14 @@ module Search
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
# @return [Array] An array of statuses that contain images
- # @example Return recent images related to twitter
- # Twitter.image_facets('twitter')
- def image_facets(q, options={})
+ # @example Return recent statuses that contain images related to a query
+ # Twitter.images('twitter')
+ def images(q, options={})
response = get('i/search/image_facets', options.merge(:q => q))
format.to_s.downcase == 'xml' ? response['statuses'] : response
end
- # Returns recent videos related to a query
+ # Returns recent statuses that contain videos related to a query
#
# @note Undocumented
# @rate_limited Yes
@@ -33,12 +33,30 @@ def image_facets(q, options={})
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
# @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
# @return [Array] An array of statuses that contain videos
- # @example Return recent videos related to twitter
- # Twitter.video_facets('twitter')
- def video_facets(q, options={})
+ # @example Return recent statuses that contain videos related to a query
+ # Twitter.videos('twitter')
+ def videos(q, options={})
response = get('i/search/video_facets', options.merge(:q => q))
format.to_s.downcase == 'xml' ? response['statuses'] : response
end
+
+ # Returns recent statuses related to a query with images and videos embedded
+ #
+ # @note Undocumented
+ # @rate_limited Yes
+ # @requires_authentication No
+ # @response_format `json`
+ # @response_format `xml`
+ # @param q [String] A search term.
+ # @param options [Hash] A customizable set of options.
+ # @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
+ # @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1.
+ # @return [Array] An array of statuses that contain videos
+ # @example Return recent statuses related to twitter with images and videos embedded
+ # Twitter.search('twitter')
+ def search(q, options={})
+ response = get('phoenix_search', options.merge(:q => q), :phoenix)['statuses']
+ end
end
end
end
@@ -34,7 +34,7 @@ def connection(format=format, temp_api_endpoint=nil)
builder.use Faraday::Request::Gateway, gateway if gateway
builder.use Faraday::Response::RaiseHttp4xx
case format.to_s.downcase
- when 'json'
+ when 'json', 'phoenix'
builder.use Faraday::Response::Mashify
builder.use Faraday::Response::ParseJson
when 'xml'
View
@@ -38,7 +38,7 @@ def request(method, path, options, format, temp_api_endpoint=nil)
def formatted_path(path, format)
case format.to_s.downcase
- when 'json', 'xml'
+ when 'json', 'phoenix', 'xml'
[path, format].compact.join('.')
when 'raw'
[path, Twitter.format].compact.join('.')

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -7,7 +7,7 @@
@client = Twitter::Client.new(:format => format)
end
- describe ".image_facets" do
+ describe ".images" do
before do
stub_get("i/search/image_facets.#{format}").
@@ -16,20 +16,20 @@
end
it "should get the correct resource" do
- @client.image_facets('twitter')
+ @client.images('twitter')
a_get("i/search/image_facets.#{format}").
with(:query => {:q => "twitter"}).
should have_been_made
end
- it "should return a single status" do
- image_facets = @client.image_facets('twitter')
- image_facets.first.text.should == "Thanks Twitter family! Beautiful. Cc @laurelstout @seacue @janetvh @mgale @choppedonion http://t.co/drAqoba"
+ it "should return recent statuses that contain images related to a query" do
+ images = @client.images('twitter')
+ images.first.text.should == "Thanks Twitter family! Beautiful. Cc @laurelstout @seacue @janetvh @mgale @choppedonion http://t.co/drAqoba"
end
end
- describe ".video_facets" do
+ describe ".videos" do
before do
stub_get("i/search/video_facets.#{format}").
@@ -38,15 +38,36 @@
end
it "should get the correct resource" do
- @client.video_facets('twitter')
+ @client.videos('twitter')
a_get("i/search/video_facets.#{format}").
with(:query => {:q => "twitter"}).
should have_been_made
end
- it "should return a single status" do
- video_facets = @client.video_facets('twitter')
- video_facets.first.text.should == "@Foofighters LEGENDS with a Legendary set of Music Videos http://t.co/IcVGIQO #VMA #VEVO"
+ it "should return recent statuses that contain videos related to a query" do
+ videos = @client.videos('twitter')
+ videos.first.text.should == "@Foofighters LEGENDS with a Legendary set of Music Videos http://t.co/IcVGIQO #VMA #VEVO"
+ end
+ end
+
+ describe ".search" do
+
+ before do
+ stub_get("phoenix_search.phoenix").
+ with(:query => {:q => "twitter"}).
+ to_return(:body => fixture("phoenix_search.phoenix"), :headers => {:content_type => "application/#{format}; charset=utf-8"})
+ end
+
+ it "should get the correct resource" do
+ @client.search('twitter')
+ a_get("phoenix_search.phoenix").
+ with(:query => {:q => "twitter"}).
+ should have_been_made
+ end
+
+ it "should return recent statuses related to a query with images and videos embedded" do
+ search = @client.search('twitter')
+ search.first.text.should == "looking at twitter trends just makes me realize how little i really understand about mankind."
end
end
end

0 comments on commit 327724b

Please sign in to comment.