Post by Hendy Irawan on May 18th, 2007

Twitter Gem: Twitterize Your Ruby Application

Twitter-1

You've heard of Twitter, an online service that allows you and your friends to communicate up-to-the-second by sending short messages. Twitter has built-in features to deliver the updates to your instant messaging account (such as Google Talk) or to your cell phone. Yesterday we covered real-time Flash visualization of RailsConf twitters.

Want to incorporate Twitter functionality into your own projects? Enter the Twitter gem by John Nunemaker. Observe:

# to post an update to twitter
$ twitter post "posting from the twitter gem"

# to see you and your friends timeline
$ twitter timeline

The command line interface is very simple, and configuring it is easy using a YAML file. Of course, it also sports a Ruby API:

twit.update('me got dizzy this time')
# Show your friends' status
twit.timeline(:friends).each do |s|
  puts s.text, s.user.name
end

Use RubyGems as usual to install it:

gem install twitter --include-dependencies

Head on to Twitter gem site for more information.

[Post to Twitter] Tweet This

6 Responses to “Twitter Gem: Twitterize Your Ruby Application”

  1. #1
    John Nunemaker Says:

    Thanks for the link. One note, the gem uses hpricot to parse the xml and there is an annoying bug that reared it's head in the 0.5+ versions (it doesn't like xml elements named text). That said, be sure to sudo gem install hpricot --source http://code.whytheluckystiff.net -v 0.4.86 and uninstall any hpricot versions 0.5+.

  2. #2
    Hendy Irawan Says:

    Thank you John for your tip! :-)

  3. #3
    John Nunemaker Says:

    I just pushed a new version of the gem today which negates the previous comment. You can now just sudo gem install twitter -y. :)

  4. #4
    Hendy Irawan Says:

    Super thanks John :)

  5. #5
    Koen Van der Auwera Says:

    Shareomatic! uses the twitter gem for it's twittering and it's works just perfect!

    Good work!

  6. #6
    Hendy Irawan Says:

    Thank you Mr. Koen Van der Auwera for sharing your experience. Yep, I fully agree John Nunemaker's work is awesome! :)