taf2-curb 0.4.4.0 → 0.4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README +104 -86
  2. data/Rakefile +5 -0
  3. data/ext/curb.h +3 -3
  4. data/lib/curb.rb +41 -1
  5. data/tests/tc_curl_multi.rb +17 -0
  6. metadata +16 -16
data/README CHANGED
@@ -1,40 +1,40 @@
1
- == Curb - Libcurl bindings for Ruby
1
+ # Curb - Libcurl bindings for Ruby
2
2
 
3
- * http://curb.rubyforge.org/
4
- * http://rubyforge.org/projects/curb
5
- * http://github.com/taf2/curb/tree/master
3
+ + [rubyforge rdoc](http://curb.rubyforge.org/)
4
+ + [rubyforge project](http://rubyforge.org/projects/curb)
5
+ + [github project](http://github.com/taf2/curb/tree/master)
6
6
 
7
7
  Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for the
8
8
  libcurl(3), a fully-featured client-side URL transfer library.
9
- cURL and libcurl live at http://curl.haxx.se/ .
9
+ cURL and libcurl live at [http://curl.haxx.se/](http://curl.haxx.se/) .
10
10
 
11
11
  Curb is a work-in-progress, and currently only supports libcurl's 'easy' and 'multi' modes.
12
12
 
13
- === License
13
+ ## License
14
14
 
15
15
  Curb is copyright (c)2006 Ross Bamford, and released under the terms of the
16
16
  Ruby license. See the LICENSE file for the gory details.
17
17
 
18
- === You will need
18
+ ## You will need
19
19
 
20
- * A working Ruby installation (1.8+, tested with 1.8.5, 1.8.6, 1.8.7, and 1.9.1)
21
- * A working (lib)curl installation, with development stuff (7.5+, tested with 7.15)
22
- * A sane build environment
20
+ + A working Ruby installation (1.8+, tested with 1.8.5, 1.8.6, 1.8.7, and 1.9.1)
21
+ + A working (lib)curl installation, with development stuff (7.5+, tested with 7.15)
22
+ + A sane build environment
23
23
 
24
- === Installation...
24
+ ## Installation...
25
25
 
26
26
  ... will usually be as simple as:
27
27
 
28
- $ gem install curb
28
+ $ gem install curb
29
29
 
30
30
  Or, if you downloaded the archive:
31
31
 
32
- $ rake install
32
+ $ rake install
33
33
 
34
34
  If you have a wierd setup, you might need extconf options. In this case, pass
35
35
  them like so:
36
36
 
37
- $ rake install EXTCONF_OPTS='--with-curl-dir=/path/to/libcurl --prefix=/what/ever'
37
+ $ rake install EXTCONF_OPTS='--with-curl-dir=/path/to/libcurl --prefix=/what/ever'
38
38
 
39
39
  Currently, Curb is tested only on GNU/Linux x86 - YMMV on other platforms.
40
40
  If you do use another platform and experience problems, or if you can
@@ -44,95 +44,113 @@ list on Curb's Rubyforge page.
44
44
  Curb has fairly extensive RDoc comments in the source. You can build the
45
45
  documentation with:
46
46
 
47
- $ rake doc
47
+ $ rake doc
48
48
 
49
- === Examples
49
+ ## Examples
50
50
 
51
- Simple fetch via HTTP:
51
+ ### Simple fetch via HTTP:
52
52
 
53
- c = Curl::Easy.perform("http://www.google.co.uk")
54
- puts c.body_str
53
+ c = Curl::Easy.perform("http://www.google.co.uk")
54
+ puts c.body_str
55
55
 
56
- Same thing, more manual:
56
+ ### Same thing, more manual:
57
57
 
58
- c = Curl::Easy.new("http://www.google.co.uk")
59
- c.perform
60
- puts c.body_str
58
+ c = Curl::Easy.new("http://www.google.co.uk")
59
+ c.perform
60
+ puts c.body_str
61
61
 
62
- Additional config:
62
+ ### Additional config:
63
63
 
64
- Curl::Easy.perform("http://www.google.co.uk") do |curl|
65
- curl.headers["User-Agent"] = "myapp-0.0"
66
- curl.verbose = true
67
- end
64
+ Curl::Easy.perform("http://www.google.co.uk") do |curl|
65
+ curl.headers["User-Agent"] = "myapp-0.0"
66
+ curl.verbose = true
67
+ end
68
68
 
69
- Same thing, more manual:
69
+ ### Same thing, more manual:
70
70
 
71
- c = Curl::Easy.new("http://www.google.co.uk") do |curl|
72
- curl.headers["User-Agent"] = "myapp-0.0"
73
- curl.verbose = true
74
- end
71
+ c = Curl::Easy.new("http://www.google.co.uk") do |curl|
72
+ curl.headers["User-Agent"] = "myapp-0.0"
73
+ curl.verbose = true
74
+ end
75
75
 
76
- c.perform
76
+ c.perform
77
77
 
78
- Supplying custom handlers:
78
+ ### Supplying custom handlers:
79
79
 
80
- c = Curl::Easy.new("http://www.google.co.uk")
80
+ c = Curl::Easy.new("http://www.google.co.uk")
81
81
 
82
- c.on_body { |data| print(data) }
83
- c.on_header { |data| print(data) }
82
+ c.on_body { |data| print(data) }
83
+ c.on_header { |data| print(data) }
84
84
 
85
- c.perform
85
+ c.perform
86
86
 
87
- Reusing Curls:
87
+ ### Reusing Curls:
88
88
 
89
- c = Curl::Easy.new
89
+ c = Curl::Easy.new
90
90
 
91
- ["http://www.google.co.uk", "http://www.ruby-lang.org/"].map do |url|
92
- c.url = url
93
- c.perform
94
- c.body_str
95
- end
96
-
97
- HTTP POST form:
98
-
99
- c = Curl::Easy.http_post("http://my.rails.box/thing/create",
100
- Curl::PostField.content('thing[name]', 'box',
101
- Curl::PostField.content('thing[type]', 'storage')
102
-
103
- HTTP POST file upload:
104
-
105
- c = Curl::Easy.new("http://my.rails.box/files/upload")
106
- c.multipart_form_post = true
107
- c.http_post(Curl::PostField.file('myfile.rb'))
108
-
109
- Multi Interface (Basic):
110
- easy_options = {:follow_location => true}
111
- multi_options = {:pipeline => true}
112
-
113
- Curl::Multi.get('url1','url2','url3','url4','url5', easy_options, multi_options) do|easy|
114
- # do something interesting with the easy response
115
- puts easy.last_effective_url
116
- end
117
-
118
- Multi Interface (Advanced):
119
- responses = {}
120
- requests = ["http://www.google.co.uk/", "http://www.ruby-lang.org/"]
121
- m = Curl::Multi.new
122
- # add a few easy handles
123
- requests.each do |url|
124
- responses[url] = ""
125
- c = Curl::Easy.new(url) do|curl|
126
- curl.follow_location = true
127
- curl.on_body{|data| responses[url] << data; data.size }
91
+ ["http://www.google.co.uk", "http://www.ruby-lang.org/"].map do |url|
92
+ c.url = url
93
+ c.perform
94
+ c.body_str
95
+ end
96
+
97
+ ### HTTP POST form:
98
+
99
+ c = Curl::Easy.http_post("http://my.rails.box/thing/create",
100
+ Curl::PostField.content('thing[name]', 'box',
101
+ Curl::PostField.content('thing[type]', 'storage')
102
+
103
+ ### HTTP POST file upload:
104
+
105
+ c = Curl::Easy.new("http://my.rails.box/files/upload")
106
+ c.multipart_form_post = true
107
+ c.http_post(Curl::PostField.file('myfile.rb'))
108
+
109
+ ### Multi Interface (Basic):
110
+
111
+ # make multiple GET requests
112
+ easy_options = {:follow_location => true}
113
+ multi_options = {:pipeline => true}
114
+
115
+ Curl::Multi.get('url1','url2','url3','url4','url5', easy_options, multi_options) do|easy|
116
+ # do something interesting with the easy response
117
+ puts easy.last_effective_url
128
118
  end
129
- m.add(c)
130
- end
131
119
 
132
- m.perform do
133
- puts "idling... can do some work here, including add new requests"
134
- end
120
+ # make multiple POST requests
121
+ easy_options = {:follow_location => true, :multipart_form_post => true}
122
+ multi_options = {:pipeline => true}
123
+
124
+ url_fields = [
125
+ { :url => 'url1', :post_fields => {'f1' => 'v1'} },
126
+ { :url => 'url2', :post_fields => {'f1' => 'v1'} },
127
+ { :url => 'url3', :post_fields => {'f1' => 'v1'} }
128
+ ]
135
129
 
136
- requests.each do|url|
137
- puts responses[url]
138
- end
130
+ Curl::Multi.post(url_fields, easy_options, multi_options) do|easy|
131
+ # do something interesting with the easy response
132
+ puts easy.last_effective_url
133
+ end
134
+
135
+ ### Multi Interface (Advanced):
136
+
137
+ responses = {}
138
+ requests = ["http://www.google.co.uk/", "http://www.ruby-lang.org/"]
139
+ m = Curl::Multi.new
140
+ # add a few easy handles
141
+ requests.each do |url|
142
+ responses[url] = ""
143
+ c = Curl::Easy.new(url) do|curl|
144
+ curl.follow_location = true
145
+ curl.on_body{|data| responses[url] << data; data.size }
146
+ end
147
+ m.add(c)
148
+ end
149
+
150
+ m.perform do
151
+ puts "idling... can do some work here, including add new requests"
152
+ end
153
+
154
+ requests.each do|url|
155
+ puts responses[url]
156
+ end
data/Rakefile CHANGED
@@ -63,6 +63,11 @@ end
63
63
  desc "Compile the shared object"
64
64
  task :compile => [CURB_SO]
65
65
 
66
+ desc "Create the markdown file"
67
+ task :markdown do
68
+ cp "README", "README.markdown"
69
+ end
70
+
66
71
  desc "Install to your site_ruby directory"
67
72
  task :install => :alltests do
68
73
  m = make 'install'
data/ext/curb.h CHANGED
@@ -20,11 +20,11 @@
20
20
  #include "curb_macros.h"
21
21
 
22
22
  // These should be managed from the Rake 'release' task.
23
- #define CURB_VERSION "0.4.4.0"
24
- #define CURB_VER_NUM 440
23
+ #define CURB_VERSION "0.4.5.0"
24
+ #define CURB_VER_NUM 450
25
25
  #define CURB_VER_MAJ 0
26
26
  #define CURB_VER_MIN 4
27
- #define CURB_VER_MIC 4
27
+ #define CURB_VER_MIC 5
28
28
  #define CURB_VER_PATCH 0
29
29
 
30
30
 
data/lib/curb.rb CHANGED
@@ -75,11 +75,51 @@ module Curl
75
75
  easy_options.each do|k,v|
76
76
  c.send("#{k}=",v)
77
77
  end
78
- c.on_complete {|curl| blk.call curl }
78
+ c.on_complete {|curl| blk.call curl } if blk
79
79
  m.add(c)
80
80
  end
81
81
  m.perform
82
82
  end
83
+
84
+ # call-seq:
85
+ #
86
+ # Curl::Multi.post([{:url => 'url1', :post_fields => {'field1' => 'value1', 'field2' => 'value2'}},
87
+ # {:url => 'url2', :post_fields => {'field1' => 'value1', 'field2' => 'value2'}},
88
+ # {:url => 'url3', :post_fields => {'field1' => 'value1', 'field2' => 'value2'}}],
89
+ # { :follow_location => true, :multipart_form_post => true },
90
+ # {:pipeline => true }) do|easy|
91
+ # easy_handle_on_request_complete
92
+ # end
93
+ #
94
+ # Blocking call to POST multiple form's in parallel.
95
+ #
96
+ # urls_with_config: is a hash of url's pointing to the postfields to send
97
+ # easy_options: are a set of common options to set on all easy handles
98
+ # multi_options: options to set on the Curl::Multi handle
99
+ #
100
+ def post(urls_with_config, easy_options, multi_options, &blk)
101
+ m = Curl::Multi.new
102
+ # configure the multi handle
103
+ multi_options.each do|k,v|
104
+ m.send("#{k}=", v)
105
+ end
106
+
107
+ urls_with_config.each do|conf|
108
+ c = conf.dup # avoid being destructive to input
109
+ url = c.delete(:url)
110
+ fields = c.delete(:post_fields)
111
+ easy = Curl::Easy.new(url)
112
+ # set the post post using the url fields
113
+ easy.post_body = fields.map{|f,k| "#{easy.escape(f)}=#{easy.escape(k)}"}.join('&')
114
+ # configure the easy handle
115
+ easy_options.each do|k,v|
116
+ easy.send("#{k}=",v)
117
+ end
118
+ easy.on_complete {|curl| blk.call curl } if blk
119
+ m.add(easy)
120
+ end
121
+ m.perform
122
+ end
83
123
  end
84
124
  end
85
125
  end
@@ -260,6 +260,23 @@ class TestCurbCurlMulti < Test::Unit::TestCase
260
260
  end
261
261
  end
262
262
 
263
+ def test_multi_easy_post_01
264
+ urls = [
265
+ { :url => TestServlet.url + '?q=1', :post_fields => {'field1' => 'value1', 'k' => 'j'}},
266
+ { :url => TestServlet.url + '?q=2', :post_fields => {'field2' => 'value2', 'foo' => 'bar', 'i' => 'j' }},
267
+ { :url => TestServlet.url + '?q=3', :post_fields => {'field3' => 'value3', 'field4' => 'value4'}}
268
+ ]
269
+ Curl::Multi.post(urls, {:follow_location => true, :multipart_form_post => true}, {:pipeline => true}) do|easy|
270
+ str = easy.body_str
271
+ assert_match /POST/, str
272
+ fields = {}
273
+ str.gsub(/POST\n/,'').split('&').map{|sv| k, v = sv.split('='); fields[k] = v }
274
+ expected = urls.find{|s| s[:url] == easy.last_effective_url }
275
+ assert_equal expected[:post_fields], fields
276
+ #puts "#{easy.last_effective_url} #{fields.inspect}"
277
+ end
278
+ end
279
+
263
280
  include TestServerMethods
264
281
 
265
282
  def setup
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taf2-curb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4.0
4
+ version: 0.4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Bamford
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-07-12 00:00:00 -07:00
13
+ date: 2009-07-18 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -32,18 +32,18 @@ files:
32
32
  - lib/curb.rb
33
33
  - lib/curl.rb
34
34
  - ext/curb.c
35
- - ext/curb_postfield.c
36
- - ext/curb_multi.c
37
- - ext/curb_errors.c
38
35
  - ext/curb_easy.c
36
+ - ext/curb_errors.c
37
+ - ext/curb_multi.c
38
+ - ext/curb_postfield.c
39
39
  - ext/curb_upload.c
40
+ - ext/curb.h
40
41
  - ext/curb_easy.h
41
42
  - ext/curb_errors.h
42
- - ext/curb_upload.h
43
43
  - ext/curb_macros.h
44
- - ext/curb.h
45
- - ext/curb_postfield.h
46
44
  - ext/curb_multi.h
45
+ - ext/curb_postfield.h
46
+ - ext/curb_upload.h
47
47
  has_rdoc: true
48
48
  homepage: http://curb.rubyforge.org/
49
49
  post_install_message:
@@ -73,15 +73,15 @@ signing_key:
73
73
  specification_version: 2
74
74
  summary: Ruby libcurl bindings
75
75
  test_files:
76
- - tests/tc_curl_multi.rb
77
- - tests/tc_curl_postfield.rb
76
+ - tests/alltests.rb
78
77
  - tests/bug_curb_easy_blocks_ruby_threads.rb
79
- - tests/unittests.rb
80
- - tests/bug_require_last_or_segfault.rb
81
78
  - tests/bug_instance_post_differs_from_class_post.rb
82
- - tests/tc_curl_download.rb
83
- - tests/alltests.rb
84
- - tests/helper.rb
85
- - tests/tc_curl_easy.rb
86
79
  - tests/bug_multi_segfault.rb
80
+ - tests/bug_require_last_or_segfault.rb
81
+ - tests/helper.rb
87
82
  - tests/require_last_or_segfault_script.rb
83
+ - tests/tc_curl_download.rb
84
+ - tests/tc_curl_easy.rb
85
+ - tests/tc_curl_multi.rb
86
+ - tests/tc_curl_postfield.rb
87
+ - tests/unittests.rb