guillotine 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Guillotine
2
+
3
+ Simple URL Shortener hobby kit.
4
+
5
+ ## USAGE
6
+
7
+ The easiest way to use it is with the built-in memory adapter.
8
+
9
+ ```ruby
10
+ # app.rb
11
+ require 'guillotine'
12
+ module MyApp
13
+ class App < Guillotine::App
14
+ set :db => Guillotine::Adapters::MemoryAdapter.new
15
+
16
+ get '/' do
17
+ redirect 'https://homepage.com'
18
+ end
19
+ end
20
+ end
21
+ ```
22
+
23
+ ```ruby
24
+ # config.ru
25
+ require "rubygems"
26
+ require File.expand_path("../app.rb", __FILE__)
27
+ run MyApp::App
28
+ ```
29
+
30
+ Once it's running, add URLs with a simple POST.
31
+
32
+ curl http://localhost:4567 -i \
33
+ -F "url=http://techno-weenie.net"
34
+
35
+ You can specify your own code too:
36
+
37
+ curl http://localhost:4567 -i \
38
+ -F "url=http://techno-weenie.net" \
39
+ -F "code=abc"
40
+
41
+ ## Sequel
42
+
43
+ The memory adapter sucks though. You probably want to use a DB.
44
+
45
+ ```ruby
46
+ require 'guillotine'
47
+ require 'sequel'
48
+ module MyApp
49
+ class App < Guillotine::App
50
+ set :db => Guillotine::Adapters::SequelAdapter.new(Sequel.sqlite)
51
+ end
52
+ end
53
+ ```
54
+
55
+ ## Riak
56
+
57
+ If you need to scale out your url shortening services across the cloud,
58
+ you can use Riak!
59
+
60
+ ```ruby
61
+ require 'guillotine'
62
+ require 'riak/client'
63
+ module MyApp
64
+ class App < Guillotine::App
65
+ client = Riak::Client.new :protocol => 'pbc', :pb_port => 8087
66
+ bucket = client['guillotine']
67
+ set :db => Guillotine::Adapters::RiakAdapter.new(bucket)
68
+ end
69
+ end
70
+ ```
71
+
72
+ ## Domain Restriction
73
+
74
+ You can restrict what domains that Guillotine will shorten.
75
+
76
+ ```ruby
77
+ require 'guillotine'
78
+ module MyApp
79
+ class App < Guillotine::App
80
+ # only this domain
81
+ set :required_host, 'github.com'
82
+
83
+ # or, any *.github.com domain
84
+ set :required_host, /(^|\.)github\.com$/
85
+ end
86
+ end
87
+ ```
88
+
89
+ ## Not TODO
90
+
91
+ * Statistics
92
+ * Authentication
data/guillotine.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'guillotine'
16
- s.version = '0.2.0'
17
- s.date = '2011-08-18'
16
+ s.version = '1.0.0'
17
+ s.date = '2011-08-19'
18
18
  s.rubyforge_project = 'guillotine'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -49,6 +49,7 @@ Gem::Specification.new do |s|
49
49
  s.files = %w[
50
50
  Gemfile
51
51
  LICENSE
52
+ README.md
52
53
  Rakefile
53
54
  config/haproxy.riak.cfg
54
55
  guillotine.gemspec
@@ -35,7 +35,7 @@ module Guillotine
35
35
 
36
36
  begin
37
37
  if code = settings.db.add(url.to_s.strip, code)
38
- redirect code
38
+ redirect code, 201
39
39
  else
40
40
  halt 422, "Unable to shorten #{url}"
41
41
  end
data/lib/guillotine.rb CHANGED
@@ -2,7 +2,7 @@ require 'base64'
2
2
  require 'digest/md5'
3
3
 
4
4
  module Guillotine
5
- VERSION = "0.2.0"
5
+ VERSION = "1.0.0"
6
6
 
7
7
  dir = File.expand_path '../guillotine', __FILE__
8
8
  autoload :App, "#{dir}/app"
data/test/app_test.rb CHANGED
@@ -9,6 +9,7 @@ class AppTest < Guillotine::TestCase
9
9
  def test_adding_a_link_returns_code
10
10
  url = 'http://github.com'
11
11
  post '/', :url => url
12
+ assert_equal 201, last_response.status
12
13
  assert code_url = last_response.headers['Location']
13
14
  code = code_url.gsub(/.*\//, '')
14
15
 
@@ -65,7 +66,7 @@ class AppTest < Guillotine::TestCase
65
66
  assert_match /must be from abc\.com/, last_response.body
66
67
 
67
68
  post '/', :url => 'http://abc.com/def'
68
- assert_equal 302, last_response.status
69
+ assert_equal 201, last_response.status
69
70
  ensure
70
71
  Guillotine::App.set :required_host, nil
71
72
  end
@@ -77,10 +78,10 @@ class AppTest < Guillotine::TestCase
77
78
  assert_match /must match \/abc\\.com/, last_response.body
78
79
 
79
80
  post '/', :url => 'http://abc.com/def'
80
- assert_equal 302, last_response.status
81
+ assert_equal 201, last_response.status
81
82
 
82
83
  post '/', :url => 'http://www.abc.com/def'
83
- assert_equal 302, last_response.status
84
+ assert_equal 201, last_response.status
84
85
  ensure
85
86
  Guillotine::App.set :required_host, nil
86
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guillotine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-18 00:00:00.000000000Z
12
+ date: 2011-08-19 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &70098598402440 !ruby/object:Gem::Requirement
16
+ requirement: &70113022751060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.2.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70098598402440
24
+ version_requirements: *70113022751060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: addressable
27
- requirement: &70098598401980 !ruby/object:Gem::Requirement
27
+ requirement: &70113022750600 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.2.6
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70098598401980
35
+ version_requirements: *70113022750600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rack-test
38
- requirement: &70098598401600 !ruby/object:Gem::Requirement
38
+ requirement: &70113022750220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70098598401600
46
+ version_requirements: *70113022750220
47
47
  description: Adaptable private URL shortener
48
48
  email: technoweenie@gmail.com
49
49
  executables: []
@@ -52,6 +52,7 @@ extra_rdoc_files: []
52
52
  files:
53
53
  - Gemfile
54
54
  - LICENSE
55
+ - README.md
55
56
  - Rakefile
56
57
  - config/haproxy.riak.cfg
57
58
  - guillotine.gemspec