Magpie: a Twitter search gem
Today I’m releasing my first ruby gem into the wild. It’s called Magpie and is designed to provide a simple interface to Twitter’s search system, like this:
[ruby]
require ‘magpie’
search = Magpie::Search.new(‘Hello World’)
tweet = search.results.first
# Get the contents of the tweet
tweet.body # => ‘Hello World!’
# Get the publication date + time as a DateTime object
tweet.published_at # => #<DateTime: 1060555/43200,0,2299161>
# Get the name of the tweet’s author
tweet.author.name # => "Mr Foo (mrfoo)"
# Get the author’s Twitter URI
tweet.author.uri # => "http://twitter.com/mrfoo"
# Get the URI for the author’s profile image
tweet.author.image_uri # => "http://example.com/url/for/img.jpg"
# search.results is just an array
authors = search.results.collect { |tweet| tweet.author }
[/ruby]
Extra Search Options
You can specify additional search parameters as a hash of options:
[ruby]
# Provides 100 results limited to tweets in English
Magpie::Search.new(‘Hello World’, :rpp => 100, :lang => ‘en’)
[/ruby]
There’s a list of valid search params on Twitter’s Search API page.
Installing Magpie
The source code for Magpie is available on GitHub, and you can install the gem thus:
gem sources -a http://gems.github.com
gem install jameswilding-magpie
Magpie is very much a rough draft so feedback and suggestions for improvement are welcome. If you like it, pass it on!