Skip to content

Commit

Permalink
Permits endpoint definition for both unauthenticated and OAuth proxie…
Browse files Browse the repository at this point in the history
…d requests
  • Loading branch information
earth2marsh authored and pengwynn committed Jun 17, 2010
1 parent 2da6c47 commit ff20ecb
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 11 deletions.
30 changes: 25 additions & 5 deletions lib/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion lib/twitter/local_trends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions lib/twitter/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion lib/twitter/search.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'pp'
module Twitter
class Search
include HTTParty
Expand All @@ -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
Expand Down
21 changes: 19 additions & 2 deletions lib/twitter/trends.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.