From 55813617c5b4cf672800bf7f9e7473904e3c3194 Mon Sep 17 00:00:00 2001 From: John Nunemaker Date: Thu, 16 Apr 2009 12:51:07 -0400 Subject: [PATCH] Added several unauthorized methods that twitter provides. --- History | 3 +++ examples/unauthorized.rb | 16 ++++++++++++++++ lib/twitter.rb | 13 +++++++++++++ test/fixtures/status_show.json | 1 + test/twitter_test.rb | 19 +++++++++++++++++++ 5 files changed, 52 insertions(+) create mode 100644 examples/unauthorized.rb create mode 100644 test/fixtures/status_show.json diff --git a/History b/History index ca20982ee..076c7d6de 100644 --- a/History +++ b/History @@ -2,6 +2,9 @@ * 1 minor enhancement * added ability to pass query parameters to user method * httpauth can now accept :ssl option to use https instead of http + * Added Twitter.status method for no auth calls to fetch status + * Added Twitter.friend_ids method for no auth calls to fetch status + * Added Twitter.follower_ids method for no auth calls to fetch status 0.6.5 - April 15, 2009 * 1 bug fix diff --git a/examples/unauthorized.rb b/examples/unauthorized.rb new file mode 100644 index 000000000..a4d1c6bbd --- /dev/null +++ b/examples/unauthorized.rb @@ -0,0 +1,16 @@ +require File.join(File.dirname(__FILE__), '..', 'lib', 'twitter') +require 'pp' + +puts 'User', '*'*50 +pp Twitter.user('jnunemaker') +pp Twitter.user('snitch_test') + +puts 'Status', '*'*50 +pp Twitter.status(1533815199) + +puts 'Friend Ids', '*'*50 +pp Twitter.friend_ids('jnunemaker') + +puts 'Follower Ids', '*'*50 +pp Twitter.follower_ids('jnunemaker') + diff --git a/lib/twitter.rb b/lib/twitter.rb index 248dd6c0e..dba53b6c9 100644 --- a/lib/twitter.rb +++ b/lib/twitter.rb @@ -38,6 +38,19 @@ def self.user(id) response = HTTParty.get("http://twitter.com/users/show/#{id}.json", :format => :json) Mash.new(response) end + + def self.status(id) + response = HTTParty.get("http://twitter.com/statuses/show/#{id}.json", :format => :json) + Mash.new(response) + end + + def self.friend_ids(id) + HTTParty.get("http://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) + end end directory = File.dirname(__FILE__) diff --git a/test/fixtures/status_show.json b/test/fixtures/status_show.json new file mode 100644 index 000000000..ddf913727 --- /dev/null +++ b/test/fixtures/status_show.json @@ -0,0 +1 @@ +{"in_reply_to_screen_name":null,"user":{"profile_background_image_url":"http:\/\/static.twitter.com\/images\/themes\/theme9\/bg.gif","description":"Loves his wife, ruby, notre dame football and iu basketball","time_zone":"Indiana (East)","utc_offset":-18000,"friends_count":161,"profile_sidebar_border_color":"181A1E","following":false,"favourites_count":80,"notifications":false,"profile_background_color":"1A1B1F","url":"http:\/\/railstips.org\/about","name":"John Nunemaker","statuses_count":4771,"protected":false,"profile_background_tile":false,"profile_text_color":"666666","created_at":"Sun Aug 13 22:56:06 +0000 2006","profile_image_url":"http:\/\/s3.amazonaws.com\/twitter_production\/profile_images\/61024905\/black250_normal.jpg","profile_link_color":"2FC2EF","location":"Mishawaka, Indiana","screen_name":"jnunemaker","id":4243,"profile_sidebar_fill_color":"252429","followers_count":1252},"text":"Eating some oatmeal and butterscotch cookies with a cold glass of milk for breakfast. Tasty!","truncated":false,"in_reply_to_status_id":null,"created_at":"Thu Apr 16 14:12:36 +0000 2009","in_reply_to_user_id":null,"id":1533815199,"favorited":false,"source":"Twitter App<\/a>"} \ No newline at end of file diff --git a/test/twitter_test.rb b/test/twitter_test.rb index 7faafa18d..5b4a27c0c 100644 --- a/test/twitter_test.rb +++ b/test/twitter_test.rb @@ -16,4 +16,23 @@ class TwitterTest < Test::Unit::TestCase 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') + 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 friend_ids method" do + stub_get('http://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') + ids = Twitter.follower_ids('jnunemaker') + ids.size.should == 1252 + end end