Skip to content

Commit

Permalink
Added several unauthorized methods that twitter provides.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Apr 16, 2009
1 parent f46cdf9 commit 5581361
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions History
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions examples/unauthorized.rb
Original file line number Diff line number Diff line change
@@ -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')

13 changes: 13 additions & 0 deletions lib/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/status_show.json
Original file line number Diff line number Diff line change
@@ -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":"<a href=\"http:\/\/twitter.rubyforge.org\">Twitter App<\/a>"}
19 changes: 19 additions & 0 deletions test/twitter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5581361

Please sign in to comment.