Permalink
Browse files

added configurable search host (via @JonathonMA)

  • Loading branch information...
1 parent 3b0fa25 commit 76e2b444ca71a524fd710a12531c91e554d6fd2f @moomerman committed Oct 12, 2012
Showing with 7 additions and 6 deletions.
  1. +1 −0 lib/twitter_oauth/client.rb
  2. +6 −6 lib/twitter_oauth/search.rb
@@ -27,6 +27,7 @@ def initialize(options = {})
@debug = options[:debug]
@api_version = options[:api_version] || '1'
@api_host = options[:api_host] || 'api.twitter.com'
+ @search_host = options[:search_host] || 'search.twitter.com'
end
def authorize(token, secret, options = {})
@@ -2,33 +2,33 @@
module TwitterOAuth
class Client
-
+
def search(q, options={})
options[:page] ||= 1
options[:rpp] ||= 20
options[:q] = URI.escape(q)
args = options.map{|k,v| "#{k}=#{v}"}.join('&')
search_get("/search.json?#{args}")
end
-
+
# Returns the current top 10 trending topics on Twitter.
def current_trends
search_get("/trends/current.json")
end
-
+
# Returns the top 20 trending topics for each hour in a given day.
def daily_trends
search_get("/trends/daily.json")
end
-
+
# Returns the top 30 trending topics for each day in a given week.
def weekly_trends
search_get("/trends/weekly.json")
end
-
+
private
def search_get(path)
- response = open('http://search.twitter.com' + path, 'User-Agent' => 'github.com/moomerman/twitter_outh')
+ response = open("http://#{@search_host}" + path, 'User-Agent' => "twitter_oauth gem v#{TwitterOAuth::VERSION}")
JSON.parse(response.read)
end
end

0 comments on commit 76e2b44

Please sign in to comment.