rufus-verbs 0.4 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +11 -1
- data/lib/rufus/verbs.rb +16 -0
- data/lib/rufus/verbs/endpoint.rb +33 -0
- data/lib/rufus/verbs/version.rb +1 -1
- data/test/simple_test.rb +19 -0
- metadata +2 -2
data/README.txt
CHANGED
@@ -7,12 +7,14 @@
|
|
7
7
|
|
8
8
|
It wraps a certain number of techniques that make it a decent tool for manipulating web resources.
|
9
9
|
|
10
|
+
Head and Options are supported as well.
|
11
|
+
|
10
12
|
|
11
13
|
== features
|
12
14
|
|
13
15
|
currently :
|
14
16
|
|
15
|
-
* follows redirections
|
17
|
+
* follows redirections (disable with :noredir => true)
|
16
18
|
* automatically adds _method={post|put} in the request parameters with the option :fake_put => true
|
17
19
|
* HTTPS aware ('verify none' by default)
|
18
20
|
* HTTP basic authentication
|
@@ -87,6 +89,14 @@ using get(), post(), put() and delete() directly
|
|
87
89
|
delete "http://resta.farian.server:7080/inventory/tools/0"
|
88
90
|
# I don't need that hammer anymore
|
89
91
|
|
92
|
+
ms = options "http://resta.farian.server:7080/inventory/tools"
|
93
|
+
p ms
|
94
|
+
# should yield something like [ :get, :head, :post ]
|
95
|
+
|
96
|
+
res = head "http://resta.farian.server:7080/inventory/tools"
|
97
|
+
# same as get() but only the response headers will be returned
|
98
|
+
# not the response body.
|
99
|
+
|
90
100
|
|
91
101
|
Using get() and co via an EndPoint to share common options for a set of requests
|
92
102
|
|
data/lib/rufus/verbs.rb
CHANGED
@@ -70,5 +70,21 @@ module Rufus::Verbs
|
|
70
70
|
|
71
71
|
EndPoint.request :delete, args
|
72
72
|
end
|
73
|
+
|
74
|
+
#
|
75
|
+
# HEAD
|
76
|
+
#
|
77
|
+
def head (*args)
|
78
|
+
|
79
|
+
EndPoint.request :head, args
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# OPTIONS
|
84
|
+
#
|
85
|
+
def options (*args)
|
86
|
+
|
87
|
+
EndPoint.request :options, args
|
88
|
+
end
|
73
89
|
end
|
74
90
|
|
data/lib/rufus/verbs/endpoint.rb
CHANGED
@@ -111,6 +111,16 @@ module Verbs
|
|
111
111
|
request :delete, args
|
112
112
|
end
|
113
113
|
|
114
|
+
def head (*args)
|
115
|
+
|
116
|
+
request :head, args
|
117
|
+
end
|
118
|
+
|
119
|
+
def options (*args)
|
120
|
+
|
121
|
+
request :options, args
|
122
|
+
end
|
123
|
+
|
114
124
|
#
|
115
125
|
# This is the method called by the module methods verbs.
|
116
126
|
#
|
@@ -179,6 +189,8 @@ module Verbs
|
|
179
189
|
|
180
190
|
res = handle_response method, res, opts
|
181
191
|
|
192
|
+
return parse_options(res) if method == :options
|
193
|
+
|
182
194
|
return res.body if o(opts, :body)
|
183
195
|
|
184
196
|
res
|
@@ -525,6 +537,27 @@ module Verbs
|
|
525
537
|
res
|
526
538
|
end
|
527
539
|
|
540
|
+
#
|
541
|
+
# Returns an array of symbols, like for example
|
542
|
+
#
|
543
|
+
# [ :get, :post ]
|
544
|
+
#
|
545
|
+
# obtained by parsing the 'Allow' response header.
|
546
|
+
#
|
547
|
+
# This method is used to provide the result of an OPTIONS
|
548
|
+
# HTTP method.
|
549
|
+
#
|
550
|
+
def parse_options (res)
|
551
|
+
|
552
|
+
s = res['Allow']
|
553
|
+
|
554
|
+
return [] unless s
|
555
|
+
|
556
|
+
s.split(",").collect do |m|
|
557
|
+
m.strip.downcase.to_sym
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
528
561
|
#
|
529
562
|
# Returns true if the current request has authentication
|
530
563
|
# going on.
|
data/lib/rufus/verbs/version.rb
CHANGED
data/test/simple_test.rb
CHANGED
@@ -80,4 +80,23 @@ class SimpleTest < Test::Unit::TestCase
|
|
80
80
|
r = get "http://rufus.rubyforge.org"
|
81
81
|
assert_kind_of Net::HTTPOK, r
|
82
82
|
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# HEAD
|
86
|
+
#
|
87
|
+
def test_4
|
88
|
+
|
89
|
+
res = head "http://localhost:7777/items"
|
90
|
+
assert_equal 200, res.code.to_i
|
91
|
+
assert_nil res.body
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# OPTIONS
|
96
|
+
#
|
97
|
+
def test_5
|
98
|
+
|
99
|
+
r = options "http://localhost:7777/items"
|
100
|
+
assert_equal [ :delete, :get, :head, :options, :post, :put], r
|
101
|
+
end
|
83
102
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rufus-verbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.5"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mettraux
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-01
|
12
|
+
date: 2008-02-01 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|