Permalink
Browse files

Permits endpoint definition for both unauthenticated and OAuth proxie…

…d requests
  • Loading branch information...
1 parent 2da6c47 commit ff20ecb4f4fef12c58572fb31e5c06162f8659d7 @earth2marsh earth2marsh committed with pengwynn Jun 16, 2010
Showing with 66 additions and 11 deletions.
  1. +25 −5 lib/twitter.rb
  2. +16 −1 lib/twitter/local_trends.rb
  3. +2 −2 lib/twitter/oauth.rb
  4. +4 −1 lib/twitter/search.rb
  5. +19 −2 lib/twitter/trends.rb
View
@@ -27,38 +27,58 @@ class Unavailable < StandardError; end
class InformTwitter < StandardError; end
class NotFound < StandardError; end
- def self.firehose
+
+
+ def self.firehose(options = {})
+ before_test(options)
perform_get("/statuses/public_timeline.json")
end
- def self.user(id)
+ def self.user(id,options={})
+ before_test(options)
perform_get("/users/show/#{id}.json")
end
- def self.status(id)
+ def self.status(id,options={})
+ before_test(options)
perform_get("/statuses/show/#{id}.json")
end
- def self.friend_ids(id)
+ def self.friend_ids(id,options={})
+ before_test(options)
perform_get("/friends/ids/#{id}.json")
end
- def self.follower_ids(id)
+ def self.follower_ids(id,options={})
+ before_test(options)
perform_get("/followers/ids/#{id}.json")
end
def self.timeline(id, options={})
+ before_test(options)
+ options.delete(:api_endpoint)
perform_get("/statuses/user_timeline/#{id}.json", :query => options)
end
# :per_page = max number of statues to get at once
# :page = which page of tweets you wish to get
def self.list_timeline(list_owner_username, slug, query = {})
+ before_test(query)
+ query.delete(:api_endpoint)
perform_get("/#{list_owner_username}/lists/#{slug}/statuses.json", :query => query)
end
private
+ def self.before_test(options)
+ configure_base_uri(options)
+ end
+
+ def self.configure_base_uri(options)
+ new_base_url = options[:api_endpoint]
+ base_uri "#{new_base_url}/#{API_VERSION}" if new_base_url
+ end
+
def self.perform_get(uri, options = {})
make_friendly(get(uri, options))
end
@@ -5,11 +5,26 @@ class LocalTrends
format :json
def self.available(query={})
+ before_test(query)
+ query.delete(:api_endpoint)
get("/available.json", :query => query).map{|location| Twitter.mash(location)}
end
- def self.for_location(woeid)
+ def self.for_location(woeid,options = {})
+ before_test(options)
get("/#{woeid}.json").map{|location| Twitter.mash(location)}
end
+
+ private
+
+ def self.before_test(options)
+ configure_base_uri(options)
+ end
+
+ def self.configure_base_uri(options)
+ new_base_url = options[:api_endpoint]
+ base_uri "#{new_base_url}/#{API_VERSION}/trends" if new_base_url
+ end
+
end
end
View
@@ -23,7 +23,7 @@ def consumer
end
def signing_consumer
- @signing_consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => signing_endpoint}.merge(consumer_options))
+ @signing_consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => signing_endpoint,:request_endpoint => api_endpoint }.merge(consumer_options))
end
def set_callback_url(url)
@@ -47,7 +47,7 @@ def authorize_from_request(rtoken, rsecret, verifier_or_pin)
end
def access_token
- @access_token ||= ::OAuth::AccessToken.new(consumer, @atoken, @asecret)
+ @access_token ||= ::OAuth::AccessToken.new(signing_consumer, @atoken, @asecret)
end
def authorize_from_access(atoken, asecret)
View
@@ -1,3 +1,4 @@
+require 'pp'
module Twitter
class Search
include HTTParty
@@ -11,7 +12,9 @@ def initialize(q=nil, options={})
@options = options
clear
containing(q) if q && q.strip != ""
- self.class.base_uri(options[:api_endpoint]) if options[:api_endpoint]
+ endpoint_url = options[:api_endpoint]
+ endpoint_url = "#{endpoint_url}/search" if endpoint_url && !endpoint_url.include?("/search")
+ self.class.base_uri(endpoint_url) if endpoint_url
end
def user_agent
View
@@ -8,27 +8,35 @@ class Trends
# :exclude => 'hashtags' to exclude hashtags
def self.current(options={})
+ before_test(options)
+ options.delete(:api_endpoint)
mashup(get("/current.json", :query => options))
end
# :exclude => 'hashtags' to exclude hashtags
# :date => yyyy-mm-dd for specific date
def self.daily(options={})
+ before_test(options)
+ options.delete(:api_endpoint)
mashup(get("/daily.json", :query => options))
end
# :exclude => 'hashtags' to exclude hashtags
# :date => yyyy-mm-dd for specific date
def self.weekly(options={})
+ before_test(options)
+ options.delete(:api_endpoint)
mashup(get("/weekly.json", :query => options))
end
def self.available(query={})
+ #checking for api_endpoint in local_trends
LocalTrends.available(query)
end
- def self.for_location(woeid)
- LocalTrends.for_location(woeid)
+ def self.for_location(woeid,options={})
+ #checking for api_endpoint in local_trends
+ LocalTrends.for_location(woeid,options)
end
private
@@ -37,5 +45,14 @@ def self.mashup(response)
response["trends"].values.flatten.map{|t| Twitter.mash(t)}
end
+ def self.before_test(options)
+ configure_base_uri(options)
+ end
+
+ def self.configure_base_uri(options)
+ new_base_url = options[:api_endpoint]
+ base_uri "#{new_base_url}/trends" if new_base_url
+ end
+
end
end

0 comments on commit ff20ecb

Please sign in to comment.