Oso

Description

Audiosocket’s minimal URL shortener. It’s named “oso” because those three letters look a bit like our logo.

Configuring

We deploy 1.9.2, so Oso expects it. It shouldn’t be too hard to port to 1.8 if you feel the need.

If you install the deps in the .gems file you can run rackup by itself.

Oso needs Redis. Set the OSO_REDIS_URL environment variable, which defaults to redis://localhost:6379. All keys are namespaced under oso:.

Using

There’s a static HTML index that’ll let you shorten URLs by hand, but we mostly use Oso inside other apps. To shorten a URL, POST to / with a url parameter. It’ll return a 201 with the shortened URL in the body.

You can optionally pass a life parameter, which is the lifetime of the shortened URL in seconds.

You can optionally pass a limit parameter, which is the number of times you want the shortened URL to work. After the limit is reached 404‘s are returned.

You can optionally pass a name parameter, which will be used instead of generating a token for the shortened URL. Names can only contain alphanumerics and dashes.

From Ruby

If you install the oso RubyGem:

require "oso"

Oso.shorten "github.com"             # => "http://oso.local/Acf"
Oso.shorten "github.com", life: 30   # => "http://oso.local/Ad0"

Set the OSO_URL environment variable to control where the client looks for the server, or see the RDocs for information on creating multiple instances.

Deploying

If you fork it, Oso is already prepped for Heroku. It has an up-to-date .gems manifest, and it’ll use the REDISTOGO_URL env var if it exists.

If you’d like to use it in your own config.ru file via the gem, you’ll need to provide the server’s dependencies yourself. The gem doesn’t express any runtime dependencies since it’s primarily used as a client.

Assuming you’ve provided the server dependencies (see the .gems file), using the gem from Rack is simple:

require "oso/server"
run Sinatra::Application

Pull requests making Oso a mountable Sinatra::Base app are most welcome.

License

Copyright 2011 Leopona Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.