Install
$ sudo gem install twitter
note: the twitter gem now works with hpricot 0.5+
API Wrapping
I do my best to keep it easy to use. Below are some code samples showing a few of the methods.
twit = twit
twit.update('watching veronica mars')
puts "Public Timeline", "=" * 50
twit.timeline(:public).each do |s|
puts s.text, s.user.name
puts
end
puts '', "Friends Timeline", "=" * 50
twit.timeline(:friends).each do |s|
puts s.text, s.user.name
puts
end
puts '', "You and Your Friends Timeline", "=" * 50
twit.timeline(:user).each do |s|
puts s.text, s.user.name
puts
end
puts '', "Your Friends", "=" * 50
twit.friends.each do |u|
puts u.name, u.status.text
puts
end
puts '', "jnunemaker's Friends", "=" * 50
twit.friends_for('jnunemaker').each do |u|
puts u.name
puts
end
puts '', "Your Followers", "=" * 50
twit.followers.each do |u|
puts u.name
puts
end
Search API Examples
#searches all tweets for httparty
Twitter::Search.new('httparty').each { |r| puts r.inspect }
# searches all of jnunemaker's tweets for httparty
Twitter::Search.new('httparty').from('jnunemaker').each { |r| puts r.inspect }
# searches all tweets from jnunemaker to oaknd1
Twitter::Search.new.from('jnunemaker').to('oaknd1').each { |r| puts r.inspect }
# you can also use fetch to actually just get the parsed response
Twitter::Search.new.from('jnunemaker').to('oaknd1').fetch()
Command Line
I removed the command line dependencies from the gem dependencies list so if you want to use the command line part of the twitter gem be sure to install the following gems as well.
$ sudo gem install main highline sqlite3-ruby
$ sudo gem install activerecord -v 2.2.2
The first thing you'll want to do is install the database so your account(s) can be stored.
$ twitter install
You can always uninstall twitter like this:
$ twitter uninstall
Once the twitter database is installed and migrated, you can add accounts like this:
$ twitter add
Add New Account:
Username: jnunemaker
Password (won't be displayed):
Account added.
You can also list all the accounts you've added.
$ twitter list
Account List
* jnunemaker
snitch_test
The * means denotes the account that will be used when posting, befriending, defriending, following, leaving or viewing a timeline.
To post using the account marked with the *, simply type the following:
$ twitter post "releasing my new twitter gem"
That is about it. You can do pretty much anything that you can do with twitter from the command line interface.
$ twitter
Will give you a list of all the commands. You can get the help for each command by running twitter [command] -h.
Support
Conversations welcome in the google group and bugs/features over at lighthouse
Uses
- Snitch
- Growl + Twitter
- Twitter Woot Bot (more here)
- Tweet Quicksilver Action
- logging security events to twitter
- Shareomatic is using it for their twitter account
Using the twitter gem for something, let me know and I'll add you above.