Skip to content

wanthony/guillotine

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Guillotine

Simple URL Shortener hobby kit.

USAGE

The easiest way to use it is with the built-in memory adapter.

# app.rb
require 'guillotine'
module MyApp
  class App < Guillotine::App
    set :db => Guillotine::Adapters::MemoryAdapter.new

    get '/' do
      redirect 'https://homepage.com'
    end
  end
end
# config.ru
require "rubygems"
require File.expand_path("../app.rb", __FILE__)
run MyApp::App

Once it's running, add URLs with a simple POST.

curl http://localhost:4567 -i \
  -F "url=http://techno-weenie.net"

You can specify your own code too:

curl http://localhost:4567 -i \
  -F "url=http://techno-weenie.net" \
  -F "code=abc"

Sequel

The memory adapter sucks though. You probably want to use a DB.

require 'guillotine'
require 'sequel'
module MyApp
  class App < Guillotine::App
    set :db => Guillotine::Adapters::SequelAdapter.new(Sequel.sqlite)
  end
end

Riak

If you need to scale out your url shortening services across the cloud, you can use Riak!

require 'guillotine'
require 'riak/client'
module MyApp
  class App < Guillotine::App
    client = Riak::Client.new :protocol => 'pbc', :pb_port => 8087
    bucket = client['guillotine']
    set :db => Guillotine::Adapters::RiakAdapter.new(bucket)
  end
end

Domain Restriction

You can restrict what domains that Guillotine will shorten.

require 'guillotine'
module MyApp
  class App < Guillotine::App
    # only this domain
    set :required_host, 'github.com'

    # or, any *.github.com domain
    set :required_host, /(^|\.)github\.com$/
  end
end

Not TODO

  • Statistics
  • Authentication

About

URL shortening hobby kit

Resources

License

Stars

Watchers

Forks

Packages

No packages published