public
Description: GET, POST, PUT, DELETE, with something around (ruby)
Homepage: http://rufus.rubyforge.org/rufus-verbs
Clone URL: git://github.com/jmettraux/rufus-verbs.git
Search Repo:
first commit
jmettraux (author)
Mon Mar 31 16:30:20 -0700 2008
commit  922ca113a80ae003ed827037209a5d8df2d38e44
tree    4b342caa28cb7589fe47d81dfd444d4a929868fa
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
0
@@ -0,0 +1,48 @@
0
+
0
+= rufus-verbs CHANGELOG.txt
0
+
0
+
0
+== rufus-verbs - 0.9 released 2008/04/xx
0
+
0
+- bug #19201 : :params not respected when specified in request -
0
+- todo #19200 : added verbose mode (:v / :verbose) -
0
+
0
+
0
+== rufus-verbs - 0.8 released 2008/02/18
0
+
0
+- todo #18134 : added a fopen method to Rufus::Verbs - s175
0
+- bug #18144 : verb(URI) did not work. Fixed - s172
0
+
0
+
0
+== rufus-verbs - 0.7 released 2008/02/17
0
+
0
+- todo #18071 : can now use Rufus::Verbs::method_name() directly - s158
0
+
0
+
0
+== rufus-verbs - 0.6 released 2008/02/13
0
+
0
+- todo #17989 : :params (equivalent of :query) not working. Fixed. - s147
0
+- todo #17987 : implemented auto-escaping of query parameters and :no_escape - s147
0
+
0
+
0
+== rufus-verbs - 0.5 released 2008/02/01
0
+
0
+- todo #17638 : implemented HEAD - s135
0
+- todo #17637 : implemented OPTIONS - s136
0
+
0
+
0
+== rufus-verbs - 0.4 released 2008/01/28
0
+
0
+- todo #17548 : added the :no_redirections parameter - s120
0
+- bug #17511 : missing explicit dependency on 'rufus-lru', reported by Maik Schmidt - s119
0
+
0
+
0
+== rufus-verbs - 0.3 released 2008/01/23
0
+
0
+- todo #17393 : implemented digest authentication ('auth-int') - s83
0
+- todo #17257 : implemented digest authentication ('auth' only for now) - s82
0
+- todo #17226 : implemented cookie support - s78
0
+
0
+
0
+== rufus-verbs - 0.2 released 2008/01/18
0
+
...
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
0
@@ -0,0 +1,7 @@
0
+
0
+= CREDITS.txt
0
+
0
+== Feedback
0
+
0
+Maik Schmidt : missing 'rufus-lru'
0
+
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0
@@ -0,0 +1,21 @@
0
+
0
+Copyright (c) 2008, John Mettraux, jmettraux@gmail.com
0
+
0
+Permission is hereby granted, free of charge, to any person obtaining a copy
0
+of this software and associated documentation files (the "Software"), to deal
0
+in the Software without restriction, including without limitation the rights
0
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0
+copies of the Software, and to permit persons to whom the Software is
0
+furnished to do so, subject to the following conditions:
0
+
0
+The above copyright notice and this permission notice shall be included in
0
+all copies or substantial portions of the Software.
0
+
0
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0
+THE SOFTWARE.
0
+
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
0
@@ -0,0 +1,341 @@
0
+
0
+= 'rufus-verbs'
0
+
0
+== what is it ?
0
+
0
+'rufus-verbs' is an extended HTTP client library (gem). It provides the four main HTTP "verbs" as Ruby methods : get, put, post and delete.
0
+
0
+It wraps a certain number of techniques that make it a decent tool for manipulating web resources.
0
+
0
+Head and Options are supported as well.
0
+
0
+
0
+== features
0
+
0
+currently :
0
+
0
+* follows redirections (disable with :noredir => true)
0
+* automatically adds _method={post|put} in the request parameters with the option :fake_put => true
0
+* HTTPS aware ('verify none' by default)
0
+* HTTP basic authentication
0
+* doesn't propagate auth credentials in case of redirection to different host
0
+* advertises and uses gzip compression
0
+* proxy-aware (HTTP_PROXY env var or :proxy option)
0
+* conditional GET (via ConditionalEndPoint class)
0
+* request body built via a block (post and put)
0
+* cookie-aware (if :cookies option is explicitely set to true)
0
+* http digest authentication (rfc 2617) (auth ok, auth-int not tested)
0
+* query parameters are automatically escaped (disable with :no_escape => true)
0
+* fopen(uri) method (feels like open-uri's open method, but provides all the previously mentioned features)
0
+
0
+maybe later :
0
+
0
+* retry on failure
0
+* cache awareness
0
+* greediness (automatic parsing for content like JSON or YAML)
0
+* persistent cookie jar
0
+
0
+
0
+== getting it
0
+
0
+ sudo gem install -y rufus-verbs
0
+
0
+or download[http://rubyforge.org/frs/?group_id=4812] it from RubyForge.
0
+
0
+
0
+== usage
0
+
0
+The arguments to the "verbs" follow the schema <tt>method_name(uri, opts)</tt> or <tt>method_name(opts)</tt>. Post and put accept an optional block parameter.
0
+
0
+ require 'rubygems'
0
+ require 'rufus/verbs'
0
+
0
+ include Rufus::Verbs
0
+
0
+using get(), post(), put() and delete() directly
0
+
0
+ res = get "http://en.wikipedia.org/wiki/Ruby"
0
+ puts res.body
0
+
0
+ res = get :uri => "http://en.wikipedia.org/wiki/Ruby"
0
+ puts res.body
0
+
0
+ post "http://resta.farian.server:7080/inventory/tools/0", :d => "hammer"
0
+ # passing the data via the :d (or :data) option
0
+
0
+ res = post "http://resta.farian.server:7080/inventory/tools/1" do
0
+ "sliver bullet"
0
+ end
0
+ # the data is generated by a block
0
+
0
+ puts res.code.to_i
0
+ # 201... resource created, note that by default,
0
+ # an instance of Net::HTTPResponse is returned
0
+
0
+ puts get("http://resta.farian.server:7080/inventory/tools/0", :body => true)
0
+ # "sliver bullet" (directly returning the content of the response)
0
+
0
+ # oops, typo
0
+
0
+ put "http://resta.farian.server:7080/inventory/tools/1" do
0
+ "silver bullet"
0
+ end
0
+
0
+ put "http://resta.farian.server:7080/inventory/tools/1" do |request|
0
+ request['Content-Type'] = "text/plain"
0
+ "no silver bullet"
0
+ end
0
+ # the block accepts a 'request' (Net::HTTPREquest) argument
0
+
0
+ delete "http://resta.farian.server:7080/inventory/tools/0"
0
+ # I don't need that hammer anymore
0
+
0
+ ms = options "http://resta.farian.server:7080/inventory/tools"
0
+ p ms
0
+ # should yield something like [ :get, :head, :post ]
0
+
0
+ res = head "http://resta.farian.server:7080/inventory/tools"
0
+ # same as get() but only the response headers will be returned
0
+ # not the response body.
0
+
0
+
0
+Using get() and co via an EndPoint to share common options for a set of requests
0
+
0
+ ep = EndPoint.new(
0
+ :host => "resta.farian.host",
0
+ :port => 7080,
0
+ :resource => "inventory/tools")
0
+
0
+ res = ep.get :id => 1
0
+ # still a silver bullet ?
0
+
0
+ res = ep.get :id => 0
0
+ # where did the hammer go ?
0
+
0
+
0
+A ConditionalEndPoint is an EndPoint that will use conditional GETs whenever possible
0
+
0
+ ep = ConditionalEndPoint.new(
0
+ :host => "resta.farian.zion",
0
+ :port => 7080,
0
+ :resource => "inventory/tools")
0
+
0
+ res = ep.get :id => 1
0
+ # first call will retrieve the representation completely
0
+
0
+ res = ep.get :id => 1
0
+ # the server (provided that it supports conditional GETs) only
0
+ # returned a 304 answer, the response is returned from the
0
+ # ConditionalEndPoint cache
0
+
0
+More about conditional GETs at http://ruturajv.wordpress.com/2005/12/27/conditional-get-request/
0
+
0
+Cookies may be activated for an endpoint in this way :
0
+
0
+ ep = EndPoint.new :cookies => true
0
+
0
+ res = ep.get "http://resta.farian.zion/tools/3"
0
+ res = ep.post("http://resta.farian.zion/tools") { "hammer" }
0
+
0
+Digest authentication and basic authentication are available at request or endpoint level :
0
+
0
+ ep = EndPoint.new :http_basic_authentication => [ "toto", "secretpass" ]
0
+
0
+ ep = EndPoint.new :digest_authentication => [ "toto", "secretpass" ]
0
+
0
+ res = get "http://server/doc0", :hba => [ "toto", "secretpass" ]
0
+
0
+ res = get(
0
+ "http://server/doc1",
0
+ :digest_authentication => [ "toto", "secretpass" ])
0
+
0
+The Rufus::Verbs module provides as well a <tt>fopen</tt> method, which mostly feels like the <tt>open</tt> method of open-uri.
0
+
0
+ res = fopen "CHANGELOG.txt"
0
+
0
+ Rufus::Verbs.fopen "mydir/mypath.txt" do |f|
0
+ puts f.readlines
0
+ end
0
+
0
+ res = Rufus::Verbs.fopen "http://whatever.nada.ks"
0
+
0
+ res = Rufus::Verbs.fopen "http://whatever.nada.ks", :noredir => true
0
+
0
+But it follows redirections (has all the rufus-verbs features). It's provided for when targets are local files or URIs.
0
+
0
+
0
+The tests may provide good intel as on 'rufus-verbs' usage as well : http://rufus.rubyforge.org/svn/trunk/verbs/test/
0
+
0
+
0
+== the options
0
+
0
+A list of options supported by rufus-verbs, in alphabetical order.
0
+
0
+Most of the options are, well, optional, see the usage for some clarifications about the preseance of the options among them (trying to do it in the 'least surprise' spirit).
0
+
0
+R means that the option can be used at request level only, RE means Request or EndPoint level.
0
+
0
+
0
+* <b>:auth</b> (proc, RE)
0
+this option takes a Ruby proc, it can be used for custom authentication schemes
0
+
0
+ get "http://resource:7777/items/1", :auth => lambda do |request|
0
+ request['X-Secret-Auth-Header'] = "let me in, it's OK"
0
+ end
0
+
0
+see :http_basic_authentication for the basic HTTP authentication mechanism
0
+
0
+* <b>:base</b> (string, RE)
0
+the base of a resource path
0
+
0
+ :base / :resource / :id -->
0
+ "inventory" / "tools" / "7" -->
0
+ "/inventory/tools/7"
0
+
0
+* <b>:body</b> (boolean, RE)
0
+by default, a request returns a Net::HTTPResponse instance, with :body => true, the request will return the body of response directly
0
+
0
+* <b>:cache_size</b> (integer, ConditionalEndPoint only)
0
+by default, a ConditionalEndPoint will cache 147 results (and it'll start discarded the least recently used cached responses). This option is used to set this cache's size.
0
+
0
+* <b>:cookies</b> (boolean/integer, E)
0
+when not set or set to false, rufus-verbs won't care about cookies. If set to true or an integer value, set-cookie requests by the servers will be honoured. The integer value will be interpreted as the size of the 'cookie jar', the default size being 77. The least recently used cookies will be discarded.
0
+The cookie jar implementation is not persistent.
0
+
0
+* <b>:d</b> (string, R)
0
+the short variant of :data
0
+
0
+* <b>:data</b> (string, R)
0
+the data (request body) for a put or a post.
0
+
0
+* <b>:digest_authentication</b> (pair of strings, RE)
0
+the pair username/password to be used for digest authentication.
0
+
0
+* <b>:dry_run</b> (boolean, RE)
0
+when <tt>:dry_run => true</tt>, the request will be prepared but not executed and will be returned instead of the HTTP response (used for testing)
0
+
0
+* <b>:fake_put</b> (boolean, RE)
0
+when set to true, PUT and DELETE requests will be faked as POST requests where the _method query parameter is set to 'put' or 'delete' respectively
0
+
0
+* <b>:fd</b>
0
+the short version of :form_data
0
+
0
+* <b>:form_data</b>
0
+this option expects a hash. The (post or put) request body will then be built with this hash.
0
+
0
+* <b>:h</b> (a hash String => String, RE)
0
+short for :headers
0
+
0
+* <b>:headers</b> (a hash String => String, RE)
0
+A Hash of additional request headers to pass
0
+
0
+* <b>:hba</b> (pair of strings, RE)
0
+short for :http_basic_authentication
0
+
0
+* <b>:host</b> (string, RE)
0
+the host or IP address for the request
0
+
0
+* <b>:http_basic_authentication</b> (pair of strings, RE)
0
+will activate HTTP basic authentication, takes a pair (array) argument [ user, pass ]
0
+
0
+* <b>:id</b> (string, R)
0
+the id part of a full resource path (see :base)
0
+
0
+* <b>:max_redirections</b> (integer, RE)
0
+by default, rufus-verbs will follow any number of redirections. A limit can be set via this option
0
+
0
+* <b>:no_escape</b> (boolean, RE)
0
+by default, query parameters are escaped. When this option is set to true, no escaping will be performed before the request[s].
0
+
0
+* <b>:no_redirections</b> (boolean, RE)
0
+when set to 'true', redirections will not be followed, the server response will be returned directly, even if it's a redirection notification.
0
+
0
+* <b>:noredir</b> (boolean, RE)
0
+the short version for :no_redirections.
0
+
0
+* <b>:nozip</b> (boolean, RE)
0
+if set to true will prevent gzip encoding (advertising) when GETting content
0
+
0
+* <b>:params</b> (hash or string, RE)
0
+a hash of parameters that will get appended to the URI of the request. A string like "a=b?x=y" can be given as well (equivalent to :query)
0
+
0
+* <b>:path</b> (string, RE)
0
+the path (between port and the query string)
0
+
0
+* <b>:port</b> (string, RE)
0
+the port for the request
0
+
0
+* <b>:proxy</b> (uri, string or false, RE)
0
+by default, rufus-verbs will try to use the proxy given in the HTTP_PROXY environment variable (URI). If this :proxy option is set to false, no proxy will be used. It can take the value of a URI (String or URI instance) as well.
0
+
0
+* <b>:query</b> (hash or string, R)
0
+a hash of parameters that will get appended to the URI of the request. A string like "a=b?x=y" can be given as well (equivalent to :params)
0
+
0
+* <b>:raw_response</b> (boolean, RE)
0
+the request will be executed and the HTTP response will be returned immediately, no redirection following, content decompression or eventual caching (conditional GET) will take place
0
+
0
+* <b>:res</b> (string, RE)
0
+a short version of :resource
0
+
0
+* <b>:resource</b>
0
+the resource (or the middle) of a full resource path (see :base)
0
+
0
+* <b>:scheme</b> (string, R)
0
+'http' or 'https'
0
+
0
+* <b>:ssl_verify_peer</b> (boolean, RE)
0
+by default, rufus-verbs doesn't verify ssl certificates. With this option set to true, it will.
0
+
0
+* <b>:u</b> (uri, string, RE)
0
+the short version of :uri
0
+
0
+* <b>:uri</b> (uri, string, RE)
0
+the URI for the request (or the endpoint)
0
+
0
+* <b>:user_agent</b> (string, RE)
0
+for setting a custom 'User-Agent' HTTP header
0
+
0
+* <b>:v</b> (string/boolean/IO, RE)
0
+the short version of :verbose
0
+
0
+* <b>:verbose</b> (string/boolean/IO, RE)
0
+can be set to true or to an IO instance. If set to true, messages will be directed to STDOUT. Can be set to any IO instance.
0
+Will produces verbose messages similar to those of the fine cURL utility.
0
+
0
+
0
+== dependencies
0
+
0
+the gem rufus-lru[http://rufus.rubyforge.org/rufus-lru]
0
+
0
+
0
+== mailing list
0
+
0
+On the Rufus-Ruby list[http://groups.google.com/group/rufus-ruby] :
0
+
0
+ http://groups.google.com/group/rufus-ruby
0
+
0
+
0
+== issue tracker
0
+
0
+ http://rubyforge.org/tracker/?atid=18584&group_id=4812&func=browse
0
+
0
+
0
+== source
0
+
0
+ #svn checkout http://rufus.rubyforge.org/svn/trunk/verbs
0
+
0
+Moved to http://github.com :
0
+
0
+ git clone git://github.com/jmettraux/rufus-verbs.git
0
+
0
+
0
+== author
0
+
0
+John Mettraux, jmettraux@gmail.com,
0
+http://jmettraux.wordpress.com
0
+
0
+
0
+== license
0
+
0
+MIT
0
+
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
0
@@ -0,0 +1,125 @@
0
+
0
+require 'rubygems'
0
+
0
+require 'rake'
0
+require 'rake/clean'
0
+require 'rake/packagetask'
0
+require 'rake/gempackagetask'
0
+require 'rake/rdoctask'
0
+require 'rake/testtask'
0
+
0
+require 'lib/rufus/verbs/version' # Rufus::Verbs::VERSION
0
+
0
+#
0
+# GEM SPEC
0
+
0
+spec = Gem::Specification.new do |s|
0
+
0
+ s.name = "rufus-verbs"
0
+ s.version = Rufus::Verbs::VERSION
0
+ s.authors = [ "John Mettraux" ]
0
+ s.email = "john at openwfe dot org"
0
+ s.homepage = "http://rufus.rubyforge.org/rufus-verbs"
0
+ s.platform = Gem::Platform::RUBY
0
+ s.summary = "GET, POST, PUT, DELETE, with something around"
0
+ #s.license = "MIT"
0
+
0
+ s.require_path = "lib"
0
+ #s.autorequire = "rufus-verbs"
0
+ s.test_file = "test/test.rb"
0
+ s.has_rdoc = true
0
+ s.extra_rdoc_files = [ 'README.txt' ]
0
+
0
+ [ 'rufus-lru' ].each do |d|
0
+ s.requirements << d
0
+ s.add_dependency d
0
+ end
0
+
0
+ files = FileList[ "{bin,docs,lib,test}/**/*" ]
0
+ files.exclude "rdoc"
0
+ files.exclude "extras"
0
+ s.files = files.to_a
0
+end
0
+
0
+#
0
+# tasks
0
+
0
+CLEAN.include("pkg", "html", "rdoc")
0
+
0
+task :default => [ :clean, :repackage ]
0
+
0
+
0
+#
0
+# TESTING
0
+
0
+Rake::TestTask.new(:test) do |t|
0
+ t.libs << "test"
0
+ t.test_files = FileList['test/test.rb']
0
+ t.verbose = true
0
+end
0
+
0
+#
0
+# PACKAGING
0
+
0
+Rake::GemPackageTask.new(spec) do |pkg|
0
+ #pkg.need_tar = true
0
+end
0
+
0
+Rake::PackageTask.new("rufus-verbs", Rufus::Verbs::VERSION) do |pkg|
0
+ pkg.need_zip = true
0
+ pkg.package_files = FileList[
0
+ "Rakefile",
0
+ "*.txt",
0
+ "lib/**/*",
0
+ "test/**/*"
0
+ ].to_a
0
+ #pkg.package_files.delete("MISC.txt")
0
+ class << pkg
0
+ def package_name
0
+ "#{@name}-#{@version}-src"
0
+ end
0
+ end
0
+end
0
+
0
+#
0
+# DOCUMENTATION
0
+
0
+#ALLISON=`allison --path`
0
+ALLISON="/Library/Ruby/Gems/1.8/gems/allison-2.0.3/lib/allison.rb"
0
+
0
+Rake::RDocTask.new do |rd|
0
+
0
+ rd.main = "README.txt"
0
+
0
+ rd.rdoc_dir = "html/rufus-verbs"
0
+
0
+ rd.rdoc_files.include(
0
+ "README.txt",
0
+ "CHANGELOG.txt",
0
+ "LICENSE.txt",
0
+ "CREDITS.txt",
0
+ "lib/**/*.rb")
0
+
0
+ rd.title = "rufus-verbs rdoc"
0
+
0
+ rd.options << '-N' # line numbers
0
+ rd.options << '-S' # inline source
0
+
0
+ rd.template = ALLISON if File.exist?(ALLISON)
0
+end
0
+
0
+
0
+#
0
+# WEBSITE
0
+
0
+task :upload_website => [ :clean, :rdoc ] do
0
+
0
+ account = "jmettraux@rubyforge.org"
0
+ webdir = "/var/www/gforge-projects/rufus"
0
+
0
+ sh "rsync -azv -e ssh html/rufus-verbs #{account}:#{webdir}/"
0
+
0
+ sh "mv html/rufus-verbs html/rufus_verbs"
0
+ sh "rsync -azv -e ssh html/rufus_verbs #{account}:#{webdir}/"
0
+end
0
+
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
0
@@ -0,0 +1,126 @@
0
+#
0
+#--
0
+# Copyright (c) 2008, John Mettraux, jmettraux@gmail.com
0
+#
0
+# Permission is hereby granted, free of charge, to any person obtaining a copy
0
+# of this software and associated documentation files (the "Software"), to deal
0
+# in the Software without restriction, including without limitation the rights
0
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0
+# copies of the Software, and to permit persons to whom the Software is
0
+# furnished to do so, subject to the following conditions:
0
+#
0
+# The above copyright notice and this permission notice shall be included in
0
+# all copies or substantial portions of the Software.
0
+#
0
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
0
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0
+# THE SOFTWARE.
0
+#
0
+# (MIT license)
0
+#++
0
+#
0
+
0
+#
0
+# John Mettraux
0
+#
0
+# Made in Japan
0
+#
0
+# 2008/01/11
0
+#
0
+
0
+require 'rufus/verbs/endpoint'
0
+require 'rufus/verbs/conditional'
0
+
0
+
0
+module Rufus::Verbs
0
+
0
+
0
+ #
0
+ # GET
0
+ #
0
+ def get (*args)
0
+
0
+ EndPoint.request :get, args
0
+ end
0
+
0
+ #
0
+ # POST
0
+ #
0
+ def post (*args, &block)
0
+
0
+ EndPoint.request :post, args, &block
0
+ end
0
+
0
+ #
0
+ # PUT
0
+ #
0
+ def put (*args, &block)
0
+
0
+ EndPoint.request :put, args, &block
0
+ end
0
+
0
+ #
0
+ # DELETE
0
+ #
0
+ def delete (*args)
0
+
0
+ EndPoint.request :delete, args
0
+ end
0
+
0
+ #
0
+ # HEAD
0
+ #
0
+ def head (*args)
0
+
0
+ EndPoint.request :head, args
0
+ end
0
+
0
+ #
0
+ # OPTIONS
0
+ #
0
+ def options (*args)
0
+
0
+ EndPoint.request :options, args
0
+ end
0
+
0
+ #
0
+ # Opens a file or a URI (GETs it and return the reply). Will tolerate
0
+ # a HTTP[S] URI or a file path.
0
+ #
0
+ # It is not named open() in order not to collide with File.open and
0
+ # open-uri's open.
0
+ #
0
+ def fopen (uri, *args, &block)
0
+
0
+ # should I really care about blocks here ? ...
0
+
0
+ u = URI.parse uri.to_s
0
+
0
+ return File.open(uri.to_s, &block) \
0
+ if u.scheme == nil
0
+
0
+ return File.open(uri.to_s[5..-1], &block) \
0
+ if u.scheme == 'file'
0
+
0
+ if u.scheme == 'http' or u.scheme == 'https'
0
+
0
+ r = EndPoint.request(:get, [ uri ] + args) \
0
+
0
+ if block
0
+ block.call r
0
+ return
0
+ else
0
+ return r
0
+ end
0
+ end
0
+
0
+ raise "can't handle scheme '#{u.scheme}' for #{u.to_s}"
0
+ end
0
+
0
+ extend self
0
+end
0
+
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116