Skip to content
Browse files

Set endpoint to api.twitter.com

  • Loading branch information...
1 parent fcda8b2 commit cdf99eca86feb09f014a9d5cee1e8b9c31788a56 @sferik committed Mar 18, 2010
View
13 lib/twitter.rb
@@ -28,32 +28,31 @@ class Unavailable < StandardError; end
class InformTwitter < StandardError; end
class NotFound < StandardError; end
-
def self.firehose
- response = HTTParty.get('http://twitter.com/statuses/public_timeline.json', :format => :json)
+ response = HTTParty.get('http://api.twitter.com/statuses/public_timeline.json', :format => :json)
response.map { |tweet| Hashie::Mash.new(tweet) }
end
def self.user(id)
- response = HTTParty.get("http://twitter.com/users/show/#{id}.json", :format => :json)
+ response = HTTParty.get("http://api.twitter.com/users/show/#{id}.json", :format => :json)
Hashie::Mash.new(response)
end
def self.status(id)
- response = HTTParty.get("http://twitter.com/statuses/show/#{id}.json", :format => :json)
+ response = HTTParty.get("http://api.twitter.com/statuses/show/#{id}.json", :format => :json)
Hashie::Mash.new(response)
end
def self.friend_ids(id)
- HTTParty.get("http://twitter.com/friends/ids/#{id}.json", :format => :json)
+ HTTParty.get("http://api.twitter.com/friends/ids/#{id}.json", :format => :json)
end
def self.follower_ids(id)
- HTTParty.get("http://twitter.com/followers/ids/#{id}.json", :format => :json)
+ HTTParty.get("http://api.twitter.com/followers/ids/#{id}.json", :format => :json)
end
def self.timeline(id, options={})
- response = HTTParty.get("http://twitter.com/statuses/user_timeline/#{id}.json", :query => options, :format => :json)
+ response = HTTParty.get("http://api.twitter.com/statuses/user_timeline/#{id}.json", :query => options, :format => :json)
response.map{|tweet| Hashie::Mash.new tweet}
end
View
4 lib/twitter/httpauth.rb
@@ -8,7 +8,7 @@ class HTTPAuth
def initialize(username, password, options={})
@username, @password = username, password
@options = {:ssl => false}.merge(options)
- options[:api_endpoint] ||= "twitter.com"
+ options[:api_endpoint] ||= "api.twitter.com"
self.class.base_uri "http#{'s' if options[:ssl]}://#{options[:api_endpoint]}"
end
@@ -33,4 +33,4 @@ def basic_auth
@basic_auth ||= {:username => @username, :password => @password}
end
end
-end
+end
View
4 lib/twitter/oauth.rb
@@ -17,7 +17,7 @@ def initialize(ctoken, csecret, options={})
end
def consumer
- @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'http://twitter.com'}.merge(consumer_options))
+ @consumer ||= ::OAuth::Consumer.new(@ctoken, @csecret, {:site => 'http://api.twitter.com'}.merge(consumer_options))
end
def set_callback_url(url)
@@ -53,4 +53,4 @@ def clear_request_token
@request_token = nil
end
end
-end
+end
View
2 test/test_helper.rb
@@ -31,7 +31,7 @@ def fixture_file(filename)
end
def twitter_url(url)
- url =~ /^http/ ? url : "http://twitter.com:80#{url}"
+ url =~ /^http/ ? url : "http://api.twitter.com:80#{url}"
end
def stub_get(url, filename, status=nil)
View
12 test/twitter/httpauth_test.rb
@@ -19,12 +19,12 @@ class HTTPAuthTest < Test::Unit::TestCase
end
should "use https if ssl is true" do
- Twitter::HTTPAuth.expects(:base_uri).with('https://twitter.com')
+ Twitter::HTTPAuth.expects(:base_uri).with('https://api.twitter.com')
twitter = Twitter::HTTPAuth.new('username', 'password', :ssl => true)
end
should "use http if ssl is false" do
- Twitter::HTTPAuth.expects(:base_uri).with('http://twitter.com')
+ Twitter::HTTPAuth.expects(:base_uri).with('http://api.twitter.com')
twitter = Twitter::HTTPAuth.new('username', 'password', :ssl => false)
end
end
@@ -35,13 +35,13 @@ class HTTPAuthTest < Test::Unit::TestCase
end
should "not throw error when accessing response message" do
- stub_get('http://twitter.com:80/statuses/user_timeline.json', 'user_timeline.json')
+ stub_get('http://api.twitter.com:80/statuses/user_timeline.json', 'user_timeline.json')
response = @twitter.get('/statuses/user_timeline.json')
response.message.should == 'OK'
end
should "be able to get" do
- stub_get('http://username:password@twitter.com:80/statuses/user_timeline.json', 'user_timeline.json')
+ stub_get('http://username:password@api.twitter.com:80/statuses/user_timeline.json', 'user_timeline.json')
response = @twitter.get('/statuses/user_timeline.json')
response.should == fixture_file('user_timeline.json')
end
@@ -57,7 +57,7 @@ class HTTPAuthTest < Test::Unit::TestCase
end
should "be able to post" do
- stub_post('http://username:password@twitter.com:80/statuses/update.json', 'status.json')
+ stub_post('http://username:password@api.twitter.com:80/statuses/update.json', 'status.json')
response = @twitter.post('/statuses/update.json', :text => 'My update.')
response.should == fixture_file('status.json')
end
@@ -73,4 +73,4 @@ class HTTPAuthTest < Test::Unit::TestCase
@twitter.post('/statuses/update.json', {:text => 'My update.'}, {'Foo' => 'Bar'})
end
end
-end
+end
View
10 test/twitter/oauth_test.rb
@@ -20,7 +20,7 @@ class OAuthTest < Test::Unit::TestCase
should "have a consumer" do
consumer = mock('oauth consumer')
- OAuth::Consumer.expects(:new).with('token', 'secret', {:site => 'http://twitter.com'}).returns(consumer)
+ OAuth::Consumer.expects(:new).with('token', 'secret', {:site => 'http://api.twitter.com'}).returns(consumer)
twitter = Twitter::OAuth.new('token', 'secret')
twitter.consumer.should == consumer
@@ -30,7 +30,7 @@ class OAuthTest < Test::Unit::TestCase
consumer = mock('oauth consumer')
request_token = mock('request token')
consumer.expects(:get_request_token).returns(request_token)
- OAuth::Consumer.expects(:new).with('token', 'secret', {:site => 'http://twitter.com'}).returns(consumer)
+ OAuth::Consumer.expects(:new).with('token', 'secret', {:site => 'http://api.twitter.com'}).returns(consumer)
twitter = Twitter::OAuth.new('token', 'secret')
twitter.request_token.should == request_token
@@ -43,7 +43,7 @@ class OAuthTest < Test::Unit::TestCase
OAuth::Consumer.
expects(:new).
- with('token', 'secret', {:site => 'http://twitter.com'}).
+ with('token', 'secret', {:site => 'http://api.twitter.com'}).
returns(consumer)
twitter = Twitter::OAuth.new('token', 'secret')
@@ -58,7 +58,7 @@ class OAuthTest < Test::Unit::TestCase
should "be able to create access token from request token, request secret and verifier" do
twitter = Twitter::OAuth.new('token', 'secret')
- consumer = OAuth::Consumer.new('token', 'secret', {:site => 'http://twitter.com'})
+ consumer = OAuth::Consumer.new('token', 'secret', {:site => 'http://api.twitter.com'})
twitter.stubs(:consumer).returns(consumer)
access_token = mock('access token', :token => 'atoken', :secret => 'asecret')
@@ -81,7 +81,7 @@ class OAuthTest < Test::Unit::TestCase
should "be able to create access token from access token and secret" do
twitter = Twitter::OAuth.new('token', 'secret')
- consumer = OAuth::Consumer.new('token', 'secret', {:site => 'http://twitter.com'})
+ consumer = OAuth::Consumer.new('token', 'secret', {:site => 'http://api.twitter.com'})
twitter.stubs(:consumer).returns(consumer)
twitter.authorize_from_access('atoken', 'asecret')
View
20 test/twitter/request_test.rb
@@ -138,63 +138,63 @@ class RequestTest < Test::Unit::TestCase
end
should "not raise error for 200" do
- stub_get('http://twitter.com:80/foo', '', ['200'])
+ stub_get('http://api.twitter.com:80/foo', '', ['200'])
lambda {
Twitter::Request.get(@client, '/foo')
}.should_not raise_error
end
should "not raise error for 304" do
- stub_get('http://twitter.com:80/foo', '', ['304'])
+ stub_get('http://api.twitter.com:80/foo', '', ['304'])
lambda {
Twitter::Request.get(@client, '/foo')
}.should_not raise_error
end
should "raise RateLimitExceeded for 400" do
- stub_get('http://twitter.com:80/foo', 'rate_limit_exceeded.json', ['400'])
+ stub_get('http://api.twitter.com:80/foo', 'rate_limit_exceeded.json', ['400'])
lambda {
Twitter::Request.get(@client, '/foo')
}.should raise_error(Twitter::RateLimitExceeded)
end
should "raise Unauthorized for 401" do
- stub_get('http://twitter.com:80/foo', '', ['401'])
+ stub_get('http://api.twitter.com:80/foo', '', ['401'])
lambda {
Twitter::Request.get(@client, '/foo')
}.should raise_error(Twitter::Unauthorized)
end
should "raise General for 403" do
- stub_get('http://twitter.com:80/foo', '', ['403'])
+ stub_get('http://api.twitter.com:80/foo', '', ['403'])
lambda {
Twitter::Request.get(@client, '/foo')
}.should raise_error(Twitter::General)
end
should "raise NotFound for 404" do
- stub_get('http://twitter.com:80/foo', '', ['404'])
+ stub_get('http://api.twitter.com:80/foo', '', ['404'])
lambda {
Twitter::Request.get(@client, '/foo')
}.should raise_error(Twitter::NotFound)
end
should "raise InformTwitter for 500" do
- stub_get('http://twitter.com:80/foo', '', ['500'])
+ stub_get('http://api.twitter.com:80/foo', '', ['500'])
lambda {
Twitter::Request.get(@client, '/foo')
}.should raise_error(Twitter::InformTwitter)
end
should "raise Unavailable for 502" do
- stub_get('http://twitter.com:80/foo', '', ['502'])
+ stub_get('http://api.twitter.com:80/foo', '', ['502'])
lambda {
Twitter::Request.get(@client, '/foo')
}.should raise_error(Twitter::Unavailable)
end
should "raise Unavailable for 503" do
- stub_get('http://twitter.com:80/foo', '', ['503'])
+ stub_get('http://api.twitter.com:80/foo', '', ['503'])
lambda {
Twitter::Request.get(@client, '/foo')
}.should raise_error(Twitter::Unavailable)
@@ -209,7 +209,7 @@ class RequestTest < Test::Unit::TestCase
end
should "not attempt to create mash of return object" do
- stub_get('http://twitter.com:80/foo', 'friend_ids.json')
+ stub_get('http://api.twitter.com:80/foo', 'friend_ids.json')
object = Twitter::Request.get(@client, '/foo', :mash => false)
object.class.should_not be(Hashie::Mash)
end
View
12 test/twitter_test.rb
@@ -2,7 +2,7 @@
class TwitterTest < Test::Unit::TestCase
should "have firehose method for public timeline" do
- stub_get('http://twitter.com:80/statuses/public_timeline.json', 'firehose.json')
+ stub_get('http://api.twitter.com:80/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://twitter.com:80/users/show/jnunemaker.json', 'user.json')
+ stub_get('http://api.twitter.com:80/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://twitter.com:80/statuses/show/1533815199.json', 'status_show.json')
+ stub_get('http://api.twitter.com:80/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://twitter.com:80/statuses/user_timeline/jnunemaker.json', 'user_timeline.json')
+ stub_get('http://api.twitter.com:80/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://twitter.com:80/friends/ids/jnunemaker.json', 'friend_ids.json')
+ stub_get('http://api.twitter.com:80/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://twitter.com:80/followers/ids/jnunemaker.json', 'follower_ids.json')
+ stub_get('http://api.twitter.com:80/followers/ids/jnunemaker.json', 'follower_ids.json')
ids = Twitter.follower_ids('jnunemaker')
ids.size.should == 1252
end

0 comments on commit cdf99ec

Please sign in to comment.
Something went wrong with that request. Please try again.