toolmantim-teapot 1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/teapot.rb +21 -0
  2. data/teapot.gemspec +18 -0
  3. data/test/test_teapot.rb +35 -0
  4. metadata +60 -0
data/lib/teapot.rb ADDED
@@ -0,0 +1,21 @@
1
+ # Rack middleware to respond to BREW and coffee-pot-command requests. Use in a rackup file like so:
2
+ #
3
+ # use Teapot
4
+ #
5
+ # or if you're an English Breakfast hater:
6
+ #
7
+ # use Teapot, "Lady Grey"
8
+ class Teapot
9
+ VERSION = "1.0.0"
10
+
11
+ def initialize(app, tea="English Breakfast") #:nodoc:
12
+ @app, @tea = app, tea
13
+ end
14
+ def call(env) #:nodoc:
15
+ if env["REQUEST_METHOD"] == "BREW" || env["Content-Type"] == "application/coffee-pot-command"
16
+ ["418 I'm a teapot", {}, "Care for a cup of #{@tea}?"]
17
+ else
18
+ @app.call(env)
19
+ end
20
+ end
21
+ end
data/teapot.gemspec ADDED
@@ -0,0 +1,18 @@
1
+ TEAPOT_GEM_SPEC = Gem::Specification.new do |s|
2
+ s.name = "teapot"
3
+ s.version = "1.0"
4
+ s.date = "2009-01-15"
5
+ s.summary = s.description = "Rack middleware to help you, as a teapot, comply with HTCPCP/1.0: the Hyper Text Coffee Pot Control Protocol"
6
+ s.email = "t.lucas@toolmantim.com"
7
+ s.homepage = "http://github.com/toolmantim/teapot"
8
+ s.has_rdoc = true
9
+ s.authors = ["Tim Lucas"]
10
+ s.files = ["CHANGELOG.rdoc",
11
+ "LICENSE",
12
+ "README.rdoc",
13
+ "teapot.gemspec",
14
+ "lib/teapot.rb",
15
+ "test/test_teapot.rb"]
16
+ s.rdoc_options = ["--main", "README.rdoc"]
17
+ s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.rdoc"]
18
+ end
@@ -0,0 +1,35 @@
1
+ require 'test/unit'
2
+
3
+ require 'rubygems'
4
+ require 'rack/mock'
5
+
6
+ require File.join(File.dirname(__FILE__), "..", "lib", "teapot")
7
+
8
+ class DummyApp
9
+ def call(env)
10
+ [200, {}, ""]
11
+ end
12
+ end
13
+
14
+ class TeapotTest < Test::Unit::TestCase
15
+ def test_returns_418_with_content_type_coffee_pot_command
16
+ req = Rack::MockRequest.new(Teapot.new(DummyApp.new, "English Breakfast"))
17
+ res = req.get("", {"Content-Type" => "application/coffee-pot-command"})
18
+ assert_equal 418, res.status
19
+ end
20
+ def test_returns_418_with_request_method_brew
21
+ req = Rack::MockRequest.new(Teapot.new(DummyApp.new, "STFU"))
22
+ res = req.request("BREW")
23
+ assert_equal 418, res.status
24
+ end
25
+ def test_defaults_tea_type_to_english_breakfast
26
+ req = Rack::MockRequest.new(Teapot.new(DummyApp.new))
27
+ res = req.request("BREW")
28
+ assert_equal "Care for a cup of English Breakfast?", res.body
29
+ end
30
+ def test_serves_tea_passed_into_new
31
+ req = Rack::MockRequest.new(Teapot.new(DummyApp.new, "Lady Grey"))
32
+ res = req.request("BREW")
33
+ assert_equal "Care for a cup of Lady Grey?", res.body
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toolmantim-teapot
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.0"
5
+ platform: ruby
6
+ authors:
7
+ - Tim Lucas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-15 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: "Rack middleware to help you, as a teapot, comply with HTCPCP/1.0: the Hyper Text Coffee Pot Control Protocol"
17
+ email: t.lucas@toolmantim.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - CHANGELOG.rdoc
24
+ - README.rdoc
25
+ files:
26
+ - CHANGELOG.rdoc
27
+ - LICENSE
28
+ - README.rdoc
29
+ - teapot.gemspec
30
+ - lib/teapot.rb
31
+ - test/test_teapot.rb
32
+ has_rdoc: true
33
+ homepage: http://github.com/toolmantim/teapot
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --main
37
+ - README.rdoc
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ requirements: []
53
+
54
+ rubyforge_project:
55
+ rubygems_version: 1.2.0
56
+ signing_key:
57
+ specification_version: 2
58
+ summary: "Rack middleware to help you, as a teapot, comply with HTCPCP/1.0: the Hyper Text Coffee Pot Control Protocol"
59
+ test_files: []
60
+