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.
@@ -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
- # (MIT license)
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
- # Methods for the verbose mode
40
- #
41
- module VerboseMixin
29
+ #
30
+ # Methods for the verbose mode
31
+ #
32
+ module VerboseMixin
42
33
 
43
- protected
34
+ protected
44
35
 
45
- #
46
- # logs a unique message to the verbose channel (if any).
47
- #
48
- def vlog (opts, msg)
36
+ #
37
+ # logs a unique message to the verbose channel (if any).
38
+ #
39
+ def vlog (opts, msg)
49
40
 
50
- channel = get_channel(opts) or return
41
+ channel = get_channel(opts) or return
51
42
 
52
- channel << msg
53
- end
43
+ channel << msg
44
+ end
54
45
 
55
- #
56
- # logs the outgoing request
57
- #
58
- def vlog_request (opts, req)
46
+ #
47
+ # logs the outgoing request
48
+ #
49
+ def vlog_request (opts, req)
59
50
 
60
- channel = get_channel(opts) or return
51
+ channel = get_channel(opts) or return
61
52
 
62
- channel << "> #{req.method} #{req.path}\n"
53
+ channel << "> #{req.method} #{req.path}\n"
63
54
 
64
- req.each do |k, v|
65
- channel << "> #{k}: #{v}\n"
66
- end
55
+ req.each do |k, v|
56
+ channel << "> #{k}: #{v}\n"
57
+ end
67
58
 
68
- channel << ">\n"
69
- end
59
+ channel << ">\n"
60
+ end
70
61
 
71
- def vlog_http (opts, http)
62
+ def vlog_http (opts, http)
72
63
 
73
- channel = get_channel(opts) or return
64
+ channel = get_channel(opts) or return
74
65
 
75
- channel << "* #{http.address}:#{http.port}\n"
76
- channel << "*\n"
77
- end
66
+ channel << "* #{http.address}:#{http.port}\n"
67
+ channel << "*\n"
68
+ end
78
69
 
79
- #
80
- # logs the incoming response
81
- #
82
- def vlog_response (opts, res)
70
+ #
71
+ # logs the incoming response
72
+ #
73
+ def vlog_response (opts, res)
83
74
 
84
- channel = get_channel(opts) or return
75
+ channel = get_channel(opts) or return
85
76
 
86
- channel << "< #{res.code} #{res.message}\n"
87
- channel << "<\n"
77
+ channel << "< #{res.code} #{res.message}\n"
78
+ channel << "<\n"
88
79
 
89
- res.each do |k, v|
90
- channel << "< #{k}: #{v}\n"
91
- end
80
+ res.each do |k, v|
81
+ channel << "< #{k}: #{v}\n"
82
+ end
92
83
 
93
- channel << "<\n"
94
- end
84
+ channel << "<\n"
85
+ end
95
86
 
96
- private
87
+ private
97
88
 
98
- def get_channel (opts)
89
+ def get_channel (opts)
99
90
 
100
- v = o(opts, [ :verbose, :v ])
91
+ v = o(opts, [ :verbose, :v ])
101
92
 
102
- return nil if (not v) or (v.to_s == 'false')
93
+ return nil if (not v) or (v.to_s == 'false')
103
94
 
104
- v = $stdout if v.to_s == 'true'
95
+ v = $stdout if v.to_s == 'true'
105
96
 
106
- return nil unless v.is_a?(IO)
97
+ return nil unless v.is_a?(IO)
107
98
 
108
- v
109
- end
99
+ v
110
100
  end
101
+ end
111
102
 
112
103
  end
113
104
  end
@@ -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
- # (MIT license)
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
- # The version of this rufus-verbs [gem]
41
- #
42
- VERSION = '0.10'
29
+ #
30
+ # The version of this rufus-verbs [gem]
31
+ #
32
+ VERSION = '1.0.0'
43
33
  end
44
34
  end
45
35
 
@@ -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
+
@@ -7,40 +7,37 @@
7
7
  # Sun Jan 13 12:33:03 JST 2008
8
8
  #
9
9
 
10
- require 'test/unit'
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
- include TestBaseMixin
14
+ include TestBaseMixin
18
15
 
19
- include Rufus::Verbs
16
+ include Rufus::Verbs
20
17
 
21
- #
22
- # Using an items server with the authentication on.
23
- #
24
- def setup
18
+ #
19
+ # Using an items server with the authentication on.
20
+ #
21
+ def setup
25
22
 
26
- @server = ItemServer.new :auth => :basic
27
- @server.start
28
- end
23
+ @server = ItemServer.new :auth => :basic
24
+ @server.start
25
+ end
29
26
 
30
27
 
31
- def test_0
28
+ def test_0
32
29
 
33
- #res = get :uri => "http://localhost:7777/items"
34
- #assert_equal 200, res.code.to_i
35
- #assert_equal "{}", res.body.strip
36
- expect 401, nil, get(:uri => "http://localhost:7777/items")
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
- expect 401, nil, get(
39
- :uri => "http://localhost:7777/items",
40
- :http_basic_authentication => [ "toto", "wrong" ])
35
+ expect 401, nil, get(
36
+ :uri => "http://localhost:7777/items",
37
+ :http_basic_authentication => [ "toto", "wrong" ])
41
38
 
42
- expect 200, {}, get(
43
- :uri => "http://localhost:7777/items?a",
44
- :http_basic_authentication => [ "toto", "toto" ])
45
- end
39
+ expect 200, {}, get(
40
+ :uri => "http://localhost:7777/items?a",
41
+ :http_basic_authentication => [ "toto", "toto" ])
42
+ end
46
43
  end
@@ -7,10 +7,7 @@
7
7
  # Sun Jan 13 12:33:03 JST 2008
8
8
  #
9
9
 
10
- require 'test/unit'
11
- require 'testbase'
12
-
13
- require 'rufus/verbs'
10
+ require File.dirname(__FILE__) + '/base.rb'
14
11
 
15
12
 
16
13
  class Auth1Test < Test::Unit::TestCase
@@ -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
+
@@ -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 'rufus/verbs'
11
+ require File.dirname(__FILE__) + '/base.rb'
14
12
 
15
13
 
16
14
  class BlockTest < Test::Unit::TestCase
17
- include TestBaseMixin
15
+ include TestBaseMixin
18
16
 
19
- include Rufus::Verbs
17
+ include Rufus::Verbs
20
18
 
21
19
 
22
- def test_0
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
- res = post :uri => "http://localhost:7777/items/1" do |req|
38
- # do whatever with the request [headers]
39
- "John"
40
- end
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
- expect(
45
- 200,
46
- { 0 => "FedorFedorovitch", 1 => "John" },
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