rufus-verbs 0.10 → 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/CHANGELOG.txt +64 -0
- data/CREDITS.txt +9 -0
- data/LICENSE.txt +21 -0
- data/README.txt +4 -4
- data/Rakefile +80 -0
- data/doc/rdoc-style.css +320 -0
- data/lib/rufus-verbs.rb +3 -0
- data/lib/rufus/verbs.rb +67 -76
- data/lib/rufus/verbs/conditional.rb +78 -88
- data/lib/rufus/verbs/cookies.rb +214 -224
- data/lib/rufus/verbs/digest.rb +173 -182
- data/lib/rufus/verbs/endpoint.rb +496 -502
- data/lib/rufus/verbs/verbose.rb +52 -61
- data/lib/rufus/verbs/version.rb +6 -16
- data/rufus-verbs.gemspec +87 -0
- data/test/auth0_test.rb +22 -25
- data/test/auth1_test.rb +1 -4
- data/test/base.rb +56 -0
- data/test/block_test.rb +25 -27
- data/test/conditional_test.rb +24 -26
- data/test/cookie0_test.rb +98 -100
- data/test/cookie1_test.rb +28 -30
- data/test/dryrun_test.rb +53 -40
- data/test/escape_test.rb +16 -18
- data/test/fopen_test.rb +31 -33
- data/test/https_test.rb +19 -22
- data/test/iconditional_test.rb +36 -38
- data/test/items.rb +189 -189
- data/test/proxy_test.rb +53 -55
- data/test/redir_test.rb +16 -18
- data/test/simple_test.rb +77 -82
- data/test/test.rb +22 -26
- data/test/timeout_test.rb +15 -19
- data/test/uri_test.rb +12 -14
- metadata +38 -17
- data/test/testbase.rb +0 -47
data/lib/rufus/verbs/verbose.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
#
|
2
1
|
#--
|
3
|
-
# Copyright (c) 2008, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2008-2010, John Mettraux, jmettraux@gmail.com
|
4
3
|
#
|
5
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -8,10 +7,10 @@
|
|
8
7
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
8
|
# copies of the Software, and to permit persons to whom the Software is
|
10
9
|
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
10
|
+
#
|
12
11
|
# The above copyright notice and this permission notice shall be included in
|
13
12
|
# all copies or substantial portions of the Software.
|
14
|
-
#
|
13
|
+
#
|
15
14
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
15
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
16
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
@@ -20,94 +19,86 @@
|
|
20
19
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
20
|
# THE SOFTWARE.
|
22
21
|
#
|
23
|
-
#
|
22
|
+
# Made in Japan.
|
24
23
|
#++
|
25
|
-
#
|
26
24
|
|
27
|
-
#
|
28
|
-
# John Mettraux
|
29
|
-
#
|
30
|
-
# Made in Japan
|
31
|
-
#
|
32
|
-
# 2008/03/31
|
33
|
-
#
|
34
25
|
|
35
26
|
module Rufus
|
36
27
|
module Verbs
|
37
28
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
29
|
+
#
|
30
|
+
# Methods for the verbose mode
|
31
|
+
#
|
32
|
+
module VerboseMixin
|
42
33
|
|
43
|
-
|
34
|
+
protected
|
44
35
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
36
|
+
#
|
37
|
+
# logs a unique message to the verbose channel (if any).
|
38
|
+
#
|
39
|
+
def vlog (opts, msg)
|
49
40
|
|
50
|
-
|
41
|
+
channel = get_channel(opts) or return
|
51
42
|
|
52
|
-
|
53
|
-
|
43
|
+
channel << msg
|
44
|
+
end
|
54
45
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
46
|
+
#
|
47
|
+
# logs the outgoing request
|
48
|
+
#
|
49
|
+
def vlog_request (opts, req)
|
59
50
|
|
60
|
-
|
51
|
+
channel = get_channel(opts) or return
|
61
52
|
|
62
|
-
|
53
|
+
channel << "> #{req.method} #{req.path}\n"
|
63
54
|
|
64
|
-
|
65
|
-
|
66
|
-
|
55
|
+
req.each do |k, v|
|
56
|
+
channel << "> #{k}: #{v}\n"
|
57
|
+
end
|
67
58
|
|
68
|
-
|
69
|
-
|
59
|
+
channel << ">\n"
|
60
|
+
end
|
70
61
|
|
71
|
-
|
62
|
+
def vlog_http (opts, http)
|
72
63
|
|
73
|
-
|
64
|
+
channel = get_channel(opts) or return
|
74
65
|
|
75
|
-
|
76
|
-
|
77
|
-
|
66
|
+
channel << "* #{http.address}:#{http.port}\n"
|
67
|
+
channel << "*\n"
|
68
|
+
end
|
78
69
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
70
|
+
#
|
71
|
+
# logs the incoming response
|
72
|
+
#
|
73
|
+
def vlog_response (opts, res)
|
83
74
|
|
84
|
-
|
75
|
+
channel = get_channel(opts) or return
|
85
76
|
|
86
|
-
|
87
|
-
|
77
|
+
channel << "< #{res.code} #{res.message}\n"
|
78
|
+
channel << "<\n"
|
88
79
|
|
89
|
-
|
90
|
-
|
91
|
-
|
80
|
+
res.each do |k, v|
|
81
|
+
channel << "< #{k}: #{v}\n"
|
82
|
+
end
|
92
83
|
|
93
|
-
|
94
|
-
|
84
|
+
channel << "<\n"
|
85
|
+
end
|
95
86
|
|
96
|
-
|
87
|
+
private
|
97
88
|
|
98
|
-
|
89
|
+
def get_channel (opts)
|
99
90
|
|
100
|
-
|
91
|
+
v = o(opts, [ :verbose, :v ])
|
101
92
|
|
102
|
-
|
93
|
+
return nil if (not v) or (v.to_s == 'false')
|
103
94
|
|
104
|
-
|
95
|
+
v = $stdout if v.to_s == 'true'
|
105
96
|
|
106
|
-
|
97
|
+
return nil unless v.is_a?(IO)
|
107
98
|
|
108
|
-
|
109
|
-
end
|
99
|
+
v
|
110
100
|
end
|
101
|
+
end
|
111
102
|
|
112
103
|
end
|
113
104
|
end
|
data/lib/rufus/verbs/version.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
#
|
2
1
|
#--
|
3
|
-
# Copyright (c) 2008, John Mettraux, jmettraux@gmail.com
|
2
|
+
# Copyright (c) 2008-2010, John Mettraux, jmettraux@gmail.com
|
4
3
|
#
|
5
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -20,26 +19,17 @@
|
|
20
19
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
20
|
# THE SOFTWARE.
|
22
21
|
#
|
23
|
-
#
|
22
|
+
# Made in Japan.
|
24
23
|
#++
|
25
|
-
#
|
26
|
-
|
27
|
-
#
|
28
|
-
# John Mettraux
|
29
|
-
#
|
30
|
-
# Made in Japan
|
31
|
-
#
|
32
|
-
# 2008/01/21
|
33
|
-
#
|
34
24
|
|
35
25
|
|
36
26
|
module Rufus
|
37
27
|
module Verbs
|
38
28
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
29
|
+
#
|
30
|
+
# The version of this rufus-verbs [gem]
|
31
|
+
#
|
32
|
+
VERSION = '1.0.0'
|
43
33
|
end
|
44
34
|
end
|
45
35
|
|
data/rufus-verbs.gemspec
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rufus-verbs}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["John Mettraux"]
|
12
|
+
s.date = %q{2010-01-11}
|
13
|
+
s.description = %q{
|
14
|
+
GET, POST, PUT, DELETE, with something around.
|
15
|
+
|
16
|
+
An HTTP client Ruby gem, with conditional GET, basic auth, and more.
|
17
|
+
}
|
18
|
+
s.email = %q{jmettraux@gmail.com}
|
19
|
+
s.extra_rdoc_files = [
|
20
|
+
"LICENSE.txt",
|
21
|
+
"README.txt"
|
22
|
+
]
|
23
|
+
s.files = [
|
24
|
+
"CHANGELOG.txt",
|
25
|
+
"CREDITS.txt",
|
26
|
+
"LICENSE.txt",
|
27
|
+
"README.txt",
|
28
|
+
"Rakefile",
|
29
|
+
"doc/rdoc-style.css",
|
30
|
+
"lib/rufus-verbs.rb",
|
31
|
+
"lib/rufus/verbs.rb",
|
32
|
+
"lib/rufus/verbs/conditional.rb",
|
33
|
+
"lib/rufus/verbs/cookies.rb",
|
34
|
+
"lib/rufus/verbs/digest.rb",
|
35
|
+
"lib/rufus/verbs/endpoint.rb",
|
36
|
+
"lib/rufus/verbs/verbose.rb",
|
37
|
+
"lib/rufus/verbs/version.rb",
|
38
|
+
"rufus-verbs.gemspec",
|
39
|
+
"test/auth0_test.rb",
|
40
|
+
"test/auth1_test.rb",
|
41
|
+
"test/base.rb",
|
42
|
+
"test/block_test.rb",
|
43
|
+
"test/bm.rb",
|
44
|
+
"test/conditional_test.rb",
|
45
|
+
"test/cookie0_test.rb",
|
46
|
+
"test/cookie1_test.rb",
|
47
|
+
"test/dryrun_test.rb",
|
48
|
+
"test/escape_test.rb",
|
49
|
+
"test/fopen_test.rb",
|
50
|
+
"test/https_test.rb",
|
51
|
+
"test/iconditional_test.rb",
|
52
|
+
"test/items.rb",
|
53
|
+
"test/proxy_test.rb",
|
54
|
+
"test/redir_test.rb",
|
55
|
+
"test/simple_test.rb",
|
56
|
+
"test/test.htdigest",
|
57
|
+
"test/test.rb",
|
58
|
+
"test/timeout_test.rb",
|
59
|
+
"test/uri_test.rb"
|
60
|
+
]
|
61
|
+
s.homepage = %q{http://github.com/jmettraux/rufus-verbs/}
|
62
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
63
|
+
s.require_paths = ["lib"]
|
64
|
+
s.rubyforge_project = %q{rufus}
|
65
|
+
s.rubygems_version = %q{1.3.5}
|
66
|
+
s.summary = %q{GET, POST, PUT, DELETE, with something around}
|
67
|
+
s.test_files = [
|
68
|
+
"test/test.rb"
|
69
|
+
]
|
70
|
+
|
71
|
+
if s.respond_to? :specification_version then
|
72
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
73
|
+
s.specification_version = 3
|
74
|
+
|
75
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
76
|
+
s.add_runtime_dependency(%q<rufus-lru>, [">= 0"])
|
77
|
+
s.add_development_dependency(%q<yard>, [">= 0"])
|
78
|
+
else
|
79
|
+
s.add_dependency(%q<rufus-lru>, [">= 0"])
|
80
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
81
|
+
end
|
82
|
+
else
|
83
|
+
s.add_dependency(%q<rufus-lru>, [">= 0"])
|
84
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
data/test/auth0_test.rb
CHANGED
@@ -7,40 +7,37 @@
|
|
7
7
|
# Sun Jan 13 12:33:03 JST 2008
|
8
8
|
#
|
9
9
|
|
10
|
-
require '
|
11
|
-
require 'testbase'
|
12
|
-
|
13
|
-
require 'rufus/verbs'
|
10
|
+
require File.dirname(__FILE__) + '/base.rb'
|
14
11
|
|
15
12
|
|
16
13
|
class Auth0Test < Test::Unit::TestCase
|
17
|
-
|
14
|
+
include TestBaseMixin
|
18
15
|
|
19
|
-
|
16
|
+
include Rufus::Verbs
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
#
|
19
|
+
# Using an items server with the authentication on.
|
20
|
+
#
|
21
|
+
def setup
|
25
22
|
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
@server = ItemServer.new :auth => :basic
|
24
|
+
@server.start
|
25
|
+
end
|
29
26
|
|
30
27
|
|
31
|
-
|
28
|
+
def test_0
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
#res = get :uri => "http://localhost:7777/items"
|
31
|
+
#assert_equal 200, res.code.to_i
|
32
|
+
#assert_equal "{}", res.body.strip
|
33
|
+
expect 401, nil, get(:uri => "http://localhost:7777/items")
|
37
34
|
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
expect 401, nil, get(
|
36
|
+
:uri => "http://localhost:7777/items",
|
37
|
+
:http_basic_authentication => [ "toto", "wrong" ])
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
39
|
+
expect 200, {}, get(
|
40
|
+
:uri => "http://localhost:7777/items?a",
|
41
|
+
:http_basic_authentication => [ "toto", "toto" ])
|
42
|
+
end
|
46
43
|
end
|
data/test/auth1_test.rb
CHANGED
data/test/base.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Testing rufus-verbs
|
4
|
+
#
|
5
|
+
# jmettraux@gmail.com
|
6
|
+
#
|
7
|
+
# Sun Jan 13 18:02:50 JST 2008
|
8
|
+
#
|
9
|
+
|
10
|
+
|
11
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
12
|
+
$:.unshift(lib) unless $:.include?(lib)
|
13
|
+
|
14
|
+
require 'test/unit'
|
15
|
+
require 'rubygems'
|
16
|
+
require 'rufus/verbs'
|
17
|
+
|
18
|
+
require File.dirname(__FILE__) + '/items'
|
19
|
+
|
20
|
+
|
21
|
+
module TestBaseMixin
|
22
|
+
|
23
|
+
def setup
|
24
|
+
|
25
|
+
@server = ItemServer.new
|
26
|
+
@server.start
|
27
|
+
end
|
28
|
+
|
29
|
+
def teardown
|
30
|
+
|
31
|
+
@server.shutdown
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
#
|
37
|
+
# one or two asserts...
|
38
|
+
#
|
39
|
+
def expect (code, res_body, res)
|
40
|
+
|
41
|
+
assert_equal code, res.code.to_i
|
42
|
+
|
43
|
+
val = res.body
|
44
|
+
|
45
|
+
val = if res_body.is_a?(String)
|
46
|
+
val.strip
|
47
|
+
elsif res_body
|
48
|
+
eval(val)
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_equal(res_body, val) if res_body
|
52
|
+
|
53
|
+
res
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
data/test/block_test.rb
CHANGED
@@ -7,43 +7,41 @@
|
|
7
7
|
# Sun Jan 13 20:02:25 JST 2008
|
8
8
|
#
|
9
9
|
|
10
|
-
require 'test/unit'
|
11
|
-
require 'testbase'
|
12
10
|
|
13
|
-
require '
|
11
|
+
require File.dirname(__FILE__) + '/base.rb'
|
14
12
|
|
15
13
|
|
16
14
|
class BlockTest < Test::Unit::TestCase
|
17
|
-
|
15
|
+
include TestBaseMixin
|
18
16
|
|
19
|
-
|
17
|
+
include Rufus::Verbs
|
20
18
|
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
res = post :uri => "http://localhost:7777/items/0" do
|
25
|
-
"Fedor" +
|
26
|
-
"Fedorovitch"
|
27
|
-
end
|
28
|
-
assert_equal 201, res.code.to_i
|
29
|
-
assert_equal "http://localhost:7777/items/0", res['Location']
|
20
|
+
def test_0
|
30
21
|
|
22
|
+
res = post :uri => "http://localhost:7777/items/0" do
|
23
|
+
"Fedor" +
|
24
|
+
"Fedorovitch"
|
25
|
+
end
|
26
|
+
assert_equal 201, res.code.to_i
|
27
|
+
assert_equal "http://localhost:7777/items/0", res['Location']
|
31
28
|
|
32
|
-
expect(
|
33
|
-
200,
|
34
|
-
{ 0 => "FedorFedorovitch" },
|
35
|
-
get(:uri => "http://localhost:7777/things"))
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
assert_equal 201, res.code.to_i
|
42
|
-
assert_equal "http://localhost:7777/items/1", res['Location']
|
30
|
+
expect(
|
31
|
+
200,
|
32
|
+
{ 0 => "FedorFedorovitch" },
|
33
|
+
get(:uri => "http://localhost:7777/things"))
|
43
34
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
get(:uri => "http://localhost:7777/things"))
|
35
|
+
res = post :uri => "http://localhost:7777/items/1" do |req|
|
36
|
+
# do whatever with the request [headers]
|
37
|
+
"John"
|
48
38
|
end
|
39
|
+
assert_equal 201, res.code.to_i
|
40
|
+
assert_equal "http://localhost:7777/items/1", res['Location']
|
41
|
+
|
42
|
+
expect(
|
43
|
+
200,
|
44
|
+
{ 0 => "FedorFedorovitch", 1 => "John" },
|
45
|
+
get(:uri => "http://localhost:7777/things"))
|
46
|
+
end
|
49
47
|
end
|