Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Yet another URL shortener.
Ruby CSS JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
config
lib
test
.gitignore
.rvmrc
CHANGELOG.rdoc
Gemfile
Gemfile.lock
Manifest.txt
README.rdoc
Rakefile
Unused-Procfile
config.ru

README.rdoc

Oso

Description

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

Configuring

Oso has a .rvmrc because it's useful in our dev process. We know it's annoying for you.

If you run bundle install you can launch 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. If a name is already taken, you'll get a `412` response.

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"

If Oso.shorten doesn't receive a response within one second it returns the original, unshortened URL. To raise an error, call Oso.shorten! instead.

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 Gemfile.lock, and it'll use the REDISTOGO_URL env var if it exists. You'll probably want to set the BUNDLE_WITHOUT env var to exclude the development and test groups.

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 Gemfile), 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.

Something went wrong with that request. Please try again.