James Wilding's Weblog

Tag: ruby

Rip: a RubyGems Replacement?

Rip (“Ruby’s Intelligent Packaging”, via Ruby Inside) is “an attempt to create a next generation packaging system for Ruby”. It’s in alpha, and still under development, but looks cool.

I’m immediately drawn to Rip’s attitude to packaging ruby code for distribution, which seems to be: don’t. Don’t package, just distribute, because Rip allows for installation and management of files, directories, and git repositories (as well as gems), and so removes the need to add an extra layer of packaging logic on top of your existing code:

Rip’s support for a variety of package types means there is nothing to build and distribute. Tag your Git repository and publicize the latest version, or just pass around Gists. Rip does not care.

This makes package management as simple as passing files between friends. Email me your latest library, and I can run rip install path/to/lib. That’s it — you don’t need spec files, and you don’t need to build anything before your send me your code.

I love this simple, stripped-down approach. Rip has the potential to democratise package management by blurring the boundaries between plain old files and ‘proper’ packages — it’s a powerful tool that has a lot in common with Git and even Twitter: all are simple systems that can help people get things done by removing boundaries to productivity.

The code for Rip is available on GitHub, and there’s more information on the Rip website. Although the developers make it clear that Rip is not production ready, you can easily install the code as a gem so I’d encourage all you Rubyists to check it out!

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!