Permalink
Browse files

Added Twitter API versioning support for unauthenticated methods

  • Loading branch information...
1 parent 9555f4a commit fb895cc7e645499826dcc96e2cf8727c94eac83f @sferik committed Mar 21, 2010
Showing with 15 additions and 13 deletions.
  1. +9 −7 lib/twitter.rb
  2. +6 −6 test/twitter_test.rb
View
@@ -22,38 +22,40 @@ class Unavailable < StandardError; end
class InformTwitter < StandardError; end
class NotFound < StandardError; end
+ API_VERSION = 1
+
def self.firehose
- response = HTTParty.get("http://api.twitter.com/statuses/public_timeline.json", :format => :json)
+ response = HTTParty.get("http://api.twitter.com/#{API_VERSION}/statuses/public_timeline.json", :format => :json)
response.map { |tweet| Hashie::Mash.new(tweet) }
end
def self.user(id)
- response = HTTParty.get("http://api.twitter.com/users/show/#{id}.json", :format => :json)
+ response = HTTParty.get("http://api.twitter.com/#{API_VERSION}/users/show/#{id}.json", :format => :json)
Hashie::Mash.new(response)
end
def self.status(id)
- response = HTTParty.get("http://api.twitter.com/statuses/show/#{id}.json", :format => :json)
+ response = HTTParty.get("http://api.twitter.com/#{API_VERSION}/statuses/show/#{id}.json", :format => :json)
Hashie::Mash.new(response)
end
def self.friend_ids(id)
- HTTParty.get("http://api.twitter.com/friends/ids/#{id}.json", :format => :json)
+ HTTParty.get("http://api.twitter.com/#{API_VERSION}/friends/ids/#{id}.json", :format => :json)
end
def self.follower_ids(id)
- HTTParty.get("http://api.twitter.com/followers/ids/#{id}.json", :format => :json)
+ HTTParty.get("http://api.twitter.com/#{API_VERSION}/followers/ids/#{id}.json", :format => :json)
end
def self.timeline(id, options={})
- response = HTTParty.get("http://api.twitter.com/statuses/user_timeline/#{id}.json", :query => options, :format => :json)
+ response = HTTParty.get("http://api.twitter.com/#{API_VERSION}/statuses/user_timeline/#{id}.json", :query => options, :format => :json)
response.map{|tweet| Hashie::Mash.new tweet}
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 = {})
- response = HTTParty.get("http://api.twitter.com/1/#{list_owner_username}/lists/#{slug}/statuses.json", :query => query, :format => :json)
+ response = HTTParty.get("http://api.twitter.com/#{API_VERSION}/#{list_owner_username}/lists/#{slug}/statuses.json", :query => query, :format => :json)
response.map{|tweet| Hashie::Mash.new tweet}
end
end
View
@@ -2,7 +2,7 @@
class TwitterTest < Test::Unit::TestCase
should "have firehose method for public timeline" do
- stub_get('http://api.twitter.com:80/statuses/public_timeline.json', 'firehose.json')
+ stub_get('http://api.twitter.com:80/1/statuses/public_timeline.json', 'firehose.json')
hose = Twitter.firehose
hose.size.should == 20
first = hose.first
@@ -11,35 +11,35 @@ class TwitterTest < Test::Unit::TestCase
end
should "have user method for unauthenticated calls to get a user's information" do
- stub_get('http://api.twitter.com:80/users/show/jnunemaker.json', 'user.json')
+ stub_get('http://api.twitter.com:80/1/users/show/jnunemaker.json', 'user.json')
user = Twitter.user('jnunemaker')
user.name.should == 'John Nunemaker'
user.description.should == 'Loves his wife, ruby, notre dame football and iu basketball'
end
should "have status method for unauthenticated calls to get a status" do
- stub_get('http://api.twitter.com:80/statuses/show/1533815199.json', 'status_show.json')
+ stub_get('http://api.twitter.com:80/1/statuses/show/1533815199.json', 'status_show.json')
status = Twitter.status(1533815199)
status.id.should == 1533815199
status.text.should == 'Eating some oatmeal and butterscotch cookies with a cold glass of milk for breakfast. Tasty!'
end
should "have a timeline method for unauthenticated calls to get a user's timeline" do
- stub_get('http://api.twitter.com:80/statuses/user_timeline/jnunemaker.json', 'user_timeline.json')
+ stub_get('http://api.twitter.com:80/1/statuses/user_timeline/jnunemaker.json', 'user_timeline.json')
statuses = Twitter.timeline('jnunemaker')
statuses.first.id.should == 1445986256
statuses.first.user.screen_name.should == 'jnunemaker'
end
should "have friend_ids method" do
- stub_get('http://api.twitter.com:80/friends/ids/jnunemaker.json', 'friend_ids.json')
+ stub_get('http://api.twitter.com:80/1/friends/ids/jnunemaker.json', 'friend_ids.json')
ids = Twitter.friend_ids('jnunemaker')
ids.size.should == 161
end
should "have follower_ids method" do
- stub_get('http://api.twitter.com:80/followers/ids/jnunemaker.json', 'follower_ids.json')
+ stub_get('http://api.twitter.com:80/1/followers/ids/jnunemaker.json', 'follower_ids.json')
ids = Twitter.follower_ids('jnunemaker')
ids.size.should == 1252
end

0 comments on commit fb895cc

Please sign in to comment.