rufus-verbs 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.txt CHANGED
@@ -25,6 +25,7 @@ currently :
25
25
  * request body built via a block (post and put)
26
26
  * cookie-aware (if :cookies option is explicitely set to true)
27
27
  * http digest authentication (rfc 2617) (auth ok, auth-int not tested)
28
+ * query parameters are automatically escaped (disable with :no_escape => true)
28
29
 
29
30
  maybe later :
30
31
 
@@ -199,6 +200,12 @@ the short version of :form_data
199
200
  * <b>:form_data</b>
200
201
  this option expects a hash. The (post or put) request body will then be built with this hash.
201
202
 
203
+ * <b>:h</b> (a hash String => String, RE)
204
+ short for :headers
205
+
206
+ * <b>:headers</b> (a hash String => String, RE)
207
+ A Hash of additional request headers to pass
208
+
202
209
  * <b>:hba</b> (pair of strings, RE)
203
210
  short for :http_basic_authentication
204
211
 
@@ -214,6 +221,9 @@ the id part of a full resource path (see :base)
214
221
  * <b>:max_redirections</b> (integer, RE)
215
222
  by default, rufus-verbs will follow any number of redirections. A limit can be set via this option
216
223
 
224
+ * <b>:no_escape</b> (boolean, RE)
225
+ by default, query parameters are escaped. When this option is set to true, no escaping will be performed before the request[s].
226
+
217
227
  * <b>:no_redirections</b> (boolean, RE)
218
228
  when set to 'true', redirections will not be followed, the server response will be returned directly, even if it's a redirection notification.
219
229
 
@@ -223,6 +233,9 @@ the short version for :no_redirections.
223
233
  * <b>:nozip</b> (boolean, RE)
224
234
  if set to true will prevent gzip encoding (advertising) when GETting content
225
235
 
236
+ * <b>:params</b> (hash or string, RE)
237
+ 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)
238
+
226
239
  * <b>:path</b> (string, RE)
227
240
  the path (between port and the query string)
228
241
 
@@ -233,7 +246,7 @@ the port for the request
233
246
  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.
234
247
 
235
248
  * <b>:query</b> (hash or string, R)
236
- 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
249
+ 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)
237
250
 
238
251
  * <b>:raw_response</b> (boolean, RE)
239
252
  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
@@ -243,7 +243,7 @@ module Verbs
243
243
  opts[:host],
244
244
  opts[:port] || 80,
245
245
  opts[:path] || '/',
246
- opts[:query] || {} ]
246
+ opts[:query] || opts[:params] || {} ]
247
247
 
248
248
  elsif u
249
249
 
@@ -262,7 +262,7 @@ module Verbs
262
262
  opts[:host] = r[1] || @opts[:host]
263
263
  opts[:port] = r[2] || @opts[:port]
264
264
  opts[:path] = r[3] || @opts[:path]
265
- opts[:query] = r[4] || @opts[:query]
265
+ opts[:query] = r[4] || @opts[:query] || @opts[:params]
266
266
 
267
267
  opts.delete :path if opts[:path] == ""
268
268
 
@@ -435,7 +435,7 @@ module Verbs
435
435
 
436
436
  return path if not query or query.size < 1
437
437
 
438
- path + '?' + h_to_query(query)
438
+ path + '?' + h_to_query(query, opts)
439
439
  end
440
440
 
441
441
  #
@@ -455,9 +455,15 @@ module Verbs
455
455
  #
456
456
  # { "a" => "A", "b" => "B" } -> "a=A&b=B"
457
457
  #
458
- def h_to_query (h)
458
+ def h_to_query (h, opts)
459
459
 
460
- h.entries.collect { |e| e.join("=") }.join("&")
460
+ h.entries.collect { |k, v|
461
+ unless o(opts, :no_escape)
462
+ k = URI.escape k.to_s
463
+ v = URI.escape v.to_s
464
+ end
465
+ "#{k}=#{v}"
466
+ }.join("&")
461
467
  end
462
468
 
463
469
  #
@@ -39,7 +39,7 @@ module Verbs
39
39
  #
40
40
  # The version of this rufus-verbs [gem]
41
41
  #
42
- VERSION = '0.5'
42
+ VERSION = '0.6'
43
43
  end
44
44
  end
45
45
 
@@ -24,19 +24,19 @@ class DryRunTest < Test::Unit::TestCase
24
24
  :uri => "http://localhost:7777/items/1",
25
25
  :params => { "a" => "A", :b => :B })
26
26
 
27
- assert "/items/1?a=A&b=B", req.path
27
+ assert_equal "/items/1?a=A&b=B", req.path
28
28
 
29
29
  req = put(
30
30
  :dry_run => true,
31
31
  :uri => "http://localhost:7777/items/1",
32
32
  :query => { "a" => "A", :b => :B })
33
33
 
34
- assert "/items/1?a=A&b=B", req.path
34
+ assert_equal "/items/1?a=A&b=B", req.path
35
35
 
36
36
  req = put(
37
37
  "http://localhost:7777/items/1?a=A", :d => "toto", :dry_run => true)
38
38
 
39
- assert "/items/1?a=A", req.path
40
- assert "toto", req.body
39
+ assert_equal "/items/1?a=A", req.path
40
+ assert_equal "toto", req.body
41
41
  end
42
42
  end
@@ -0,0 +1,38 @@
1
+
2
+ #
3
+ # Testing rufus-verbs
4
+ #
5
+ # jmettraux@gmail.com
6
+ #
7
+ # Tue Feb 12 23:10:54 JST 2008
8
+ #
9
+
10
+ require 'test/unit'
11
+
12
+ require 'rufus/verbs'
13
+
14
+
15
+ class EscapeTest < Test::Unit::TestCase
16
+
17
+ include Rufus::Verbs
18
+
19
+
20
+ def test_0
21
+
22
+ req = put(
23
+ :dry_run => true,
24
+ :uri => "http://localhost:7777/items/1",
25
+ :query => { "a" => "hontou ni ?" })
26
+
27
+ assert_equal "/items/1?a=hontou%20ni%20?", req.path
28
+
29
+ req = put(
30
+ :dry_run => true,
31
+ :uri => "http://localhost:7777/items/1",
32
+ :params => { "a" => "hontou ni ?" },
33
+ :no_escape => true)
34
+
35
+ assert_equal "/items/1?a=hontou ni ?", req.path
36
+ # would fail anyway...
37
+ end
38
+ end
@@ -16,3 +16,5 @@ require 'conditional_test'
16
16
  require 'cookie0_test'
17
17
  require 'cookie1_test'
18
18
 
19
+ require 'escape_test'
20
+
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.5"
4
+ version: "0.6"
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-02-01 00:00:00 +09:00
12
+ date: 2008-02-13 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,6 +45,7 @@ files:
45
45
  - test/cookie0_test.rb
46
46
  - test/cookie1_test.rb
47
47
  - test/dryrun_test.rb
48
+ - test/escape_test.rb
48
49
  - test/https_test.rb
49
50
  - test/iconditional_test.rb
50
51
  - test/items.rb