curb 0.1.4 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of curb might be problematic. Click here for more details.

@@ -0,0 +1,249 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TestCurbCurlMulti < Test::Unit::TestCase
4
+ def teardown
5
+ # get a better read on memory loss when running in valgrind
6
+ ObjectSpace.garbage_collect
7
+ end
8
+
9
+ def test_new_multi_01
10
+ d1 = ""
11
+ c1 = Curl::Easy.new($TEST_URL) do |curl|
12
+ curl.headers["User-Agent"] = "myapp-0.0"
13
+ curl.on_body {|d| d1 << d; d.length }
14
+ end
15
+
16
+ d2 = ""
17
+ c2 = Curl::Easy.new($TEST_URL) do |curl|
18
+ curl.headers["User-Agent"] = "myapp-0.0"
19
+ curl.on_body {|d| d2 << d; d.length }
20
+ end
21
+
22
+ m = Curl::Multi.new
23
+
24
+ m.add( c1 )
25
+ m.add( c2 )
26
+
27
+ m.perform
28
+
29
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, d1)
30
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, d2)
31
+
32
+ m = nil
33
+
34
+ end
35
+
36
+ def test_perform_block
37
+ c1 = Curl::Easy.new($TEST_URL)
38
+ c2 = Curl::Easy.new($TEST_URL)
39
+
40
+ m = Curl::Multi.new
41
+
42
+ m.add( c1 )
43
+ m.add( c2 )
44
+
45
+ m.perform do
46
+ # idle
47
+ puts "idling..."
48
+ end
49
+
50
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, c1.body_str)
51
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, c2.body_str)
52
+
53
+ m = nil
54
+
55
+ end
56
+
57
+ def test_n_requests
58
+ n = 100
59
+ m = Curl::Multi.new
60
+ responses = []
61
+ n.times do|i|
62
+ responses[i] = ""
63
+ c = Curl::Easy.new($TEST_URL) do|curl|
64
+ curl.on_body{|data| responses[i] << data; data.size }
65
+ end
66
+ m.add c
67
+ end
68
+
69
+ m.perform
70
+
71
+ assert n, responses.size
72
+ n.times do|i|
73
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, responses[i], "response #{i}")
74
+ end
75
+
76
+ m = nil
77
+ end
78
+
79
+ def test_n_requests_with_break
80
+ # process n requests then load the handle again and run it again
81
+ n = 2
82
+ m = Curl::Multi.new
83
+ 5.times do|it|
84
+ responses = []
85
+ n.times do|i|
86
+ responses[i] = ""
87
+ c = Curl::Easy.new($TEST_URL) do|curl|
88
+ curl.on_body{|data| responses[i] << data; data.size }
89
+ end
90
+ m.add c
91
+ end
92
+
93
+ m.perform
94
+
95
+ assert n, responses.size
96
+ n.times do|i|
97
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, responses[i], "response #{i}")
98
+ end
99
+ end
100
+
101
+ m = nil
102
+
103
+ end
104
+
105
+ def test_with_success
106
+ c1 = Curl::Easy.new($TEST_URL)
107
+ c2 = Curl::Easy.new($TEST_URL)
108
+ success_called1 = false
109
+ success_called2 = false
110
+
111
+ c1.on_success do|c|
112
+ success_called1 = true
113
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
114
+ end
115
+
116
+ c2.on_success do|c|
117
+ success_called2 = true
118
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
119
+ end
120
+
121
+ m = Curl::Multi.new
122
+
123
+ m.add( c1 )
124
+ m.add( c2 )
125
+
126
+ m.perform do
127
+ # idle
128
+ puts "idling..."
129
+ end
130
+
131
+ assert success_called2
132
+ assert success_called1
133
+
134
+ m = nil
135
+ end
136
+
137
+ def test_with_success_cb_with_404
138
+ c1 = Curl::Easy.new("#{$TEST_URL.gsub(/file:\/\//,'')}/not_here")
139
+ c2 = Curl::Easy.new($TEST_URL)
140
+ success_called1 = false
141
+ success_called2 = false
142
+
143
+ c1.on_success do|c|
144
+ success_called1 = true
145
+ #puts "success 1 called: #{c.body_str.inspect}"
146
+ #assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
147
+ end
148
+
149
+ c1.on_failure do|c|
150
+ #puts "failure called: #{c.body_str.inspect}"
151
+ end
152
+
153
+ c2.on_success do|c|
154
+ # puts "success 2 called: #{c.body_str.inspect}"
155
+ success_called2 = true
156
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, c.body_str)
157
+ end
158
+
159
+ m = Curl::Multi.new
160
+
161
+ #puts "c1: #{c1.url}"
162
+ m.add( c1 )
163
+ #puts "c2: #{c2.url}"
164
+ m.add( c2 )
165
+
166
+ #puts "calling"
167
+ m.perform do
168
+ # idle
169
+ end
170
+
171
+ assert success_called2
172
+ assert !success_called1
173
+
174
+ m = nil
175
+ end
176
+
177
+ class TestForScope
178
+ attr_reader :buf
179
+
180
+ def t_method
181
+ @buf = ""
182
+ @m = Curl::Multi.new
183
+ 10.times do
184
+ c = Curl::Easy.new($TEST_URL)
185
+ c.on_success{|b| @buf << b.body_str }
186
+ ObjectSpace.garbage_collect
187
+ @m.add(c)
188
+ ObjectSpace.garbage_collect
189
+ end
190
+ ObjectSpace.garbage_collect
191
+ end
192
+
193
+ def t_call
194
+ @m.perform do
195
+ ObjectSpace.garbage_collect
196
+ end
197
+ end
198
+
199
+ def self.test
200
+ ObjectSpace.garbage_collect
201
+ tfs = TestForScope.new
202
+ ObjectSpace.garbage_collect
203
+ tfs.t_method
204
+ ObjectSpace.garbage_collect
205
+ tfs.t_call
206
+ ObjectSpace.garbage_collect
207
+
208
+ tfs.buf
209
+ end
210
+
211
+ end
212
+
213
+ def test_with_garbage_collect
214
+ ObjectSpace.garbage_collect
215
+ buf = TestForScope.test
216
+ ObjectSpace.garbage_collect
217
+ assert_match(/^# DO NOT REMOVE THIS COMMENT/, buf)
218
+ end
219
+
220
+ =begin
221
+ def test_remote_requests
222
+ responses = {}
223
+ requests = ["http://google.co.uk/", "http://ruby-lang.org/"]
224
+ m = Curl::Multi.new
225
+ # add a few easy handles
226
+ requests.each do |url|
227
+ responses[url] = ""
228
+ responses["#{url}-header"] = ""
229
+ c = Curl::Easy.new(url) do|curl|
230
+ curl.follow_location = true
231
+ curl.on_header{|data| responses["#{url}-header"] << data; data.size }
232
+ curl.on_body{|data| responses[url] << data; data.size }
233
+ curl.on_success {
234
+ puts curl.last_effective_url
235
+ }
236
+ end
237
+ m.add(c)
238
+ end
239
+
240
+ m.perform
241
+
242
+ requests.each do|url|
243
+ puts responses["#{url}-header"].split("\r\n").inspect
244
+ #puts responses[url].size
245
+ end
246
+ end
247
+ =end
248
+
249
+ end
metadata CHANGED
@@ -1,80 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
4
2
  name: curb
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.1.4
7
- date: 2007-08-08 00:00:00 +01:00
8
- summary: Ruby bindings for the libcurl(3) URL transfer library.
9
- require_paths:
10
- - lib
11
- email: curb-devel@rubyforge.org
12
- homepage: http://curb.rubyforge.org
13
- rubyforge_project: curb
14
- description: C-language Ruby bindings for the libcurl(3) URL transfer library.
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.3.1
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Ross Bamford
8
+ - Todd A. Fisher
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-03-19 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for the libcurl(3), a fully-featured client-side URL transfer library. cURL and libcurl live at http://curl.haxx.se/
18
+ email: todd.fisher@gmail.com
19
+ executables: []
20
+
21
+ extensions:
22
+ - ext/extconf.rb
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README
31
26
  files:
32
- - ext/curl.rb
27
+ - LICENSE
28
+ - README
29
+ - Rakefile
30
+ - doc.rb
33
31
  - ext/extconf.rb
34
- - ext/curb.rb
32
+ - lib/curb.rb
33
+ - lib/curl.rb
35
34
  - ext/curb.c
36
35
  - ext/curb_easy.c
37
36
  - ext/curb_errors.c
37
+ - ext/curb_multi.c
38
38
  - ext/curb_postfield.c
39
- - ext/curb_macros.h
40
- - ext/curb_postfield.h
41
39
  - ext/curb.h
42
- - ext/curb_errors.h
40
+ - ext/curb_config.h
43
41
  - ext/curb_easy.h
44
- - tests/bug_require_last_or_segfault.rb
45
- - tests/tc_curl_easy.rb
46
- - tests/helper.rb
47
- - tests/alltests.rb
48
- - tests/bug_instance_post_differs_from_class_post.rb
49
- - tests/unittests.rb
50
- - tests/tc_curl_postfield.rb
51
- - tests/require_last_or_segfault_script.rb
52
- - samples/gmail.rb
53
- - doc.rb
54
- - Rakefile
55
- - README
56
- - LICENSE
57
- test_files:
58
- - tests/tc_curl_easy.rb
59
- - tests/tc_curl_postfield.rb
42
+ - ext/curb_errors.h
43
+ - ext/curb_macros.h
44
+ - ext/curb_multi.h
45
+ - ext/curb_postfield.h
46
+ has_rdoc: true
47
+ homepage: http://curb.rubyforge.org/
48
+ post_install_message:
60
49
  rdoc_options:
61
- - --title
62
- - Curb API
63
50
  - --main
64
51
  - README
65
- extra_rdoc_files:
66
- - ext/curb.c
67
- - ext/curb_easy.c
68
- - ext/curb_errors.c
69
- - ext/curb_postfield.c
70
- - ext/curb.rb
71
- - README
72
- - LICENSE
73
- executables: []
74
-
75
- extensions:
76
- - ext/extconf.rb
52
+ require_paths:
53
+ - lib
54
+ - ext
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
77
67
  requirements: []
78
68
 
79
- dependencies: []
80
-
69
+ rubyforge_project: curb
70
+ rubygems_version: 1.3.1
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: Ruby libcurl bindings
74
+ test_files:
75
+ - tests/alltests.rb
76
+ - tests/bug_curb_easy_blocks_ruby_threads.rb
77
+ - tests/bug_instance_post_differs_from_class_post.rb
78
+ - tests/bug_require_last_or_segfault.rb
79
+ - tests/helper.rb
80
+ - tests/require_last_or_segfault_script.rb
81
+ - tests/tc_curl_download.rb
82
+ - tests/tc_curl_easy.rb
83
+ - tests/tc_curl_multi.rb
84
+ - tests/tc_curl_postfield.rb
85
+ - tests/unittests.rb
@@ -1,48 +0,0 @@
1
- # This logs into gmail, up to the point where it hits the
2
- # security redirect implemented as a refresh. It will probably
3
- # stop working altogether when they next change gmail but
4
- # it's still an example of posting with curb...
5
-
6
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'ext'))
7
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
- require 'curb'
9
-
10
- $EMAIL = '<YOUR GMAIL LOGIN>'
11
- $PASSWD = '<YOUR GMAIL PASSWORD>'
12
-
13
- url = 'https://www.google.com/accounts/ServiceLoginAuth'
14
-
15
- fields = [
16
- Curl::PostField.content('ltmpl','m_blanco'),
17
- Curl::PostField.content('ltmplcache', '2'),
18
- Curl::PostField.content('continue',
19
- 'http://mail.google.com/mail/?ui.html&amp;zy=l'),
20
- Curl::PostField.content('service', 'mail'),
21
- Curl::PostField.content('rm', 'false'),
22
- Curl::PostField.content('rmShown', '1'),
23
- Curl::PostField.content('PersistentCookie', ''),
24
- Curl::PostField.content('Email', $EMAIL),
25
- Curl::PostField.content('Passwd', $PASSWD)
26
- ]
27
-
28
- c = Curl::Easy.http_post(url, *fields) do |curl|
29
- # Gotta put yourself out there...
30
- curl.headers["User-Agent"] = "Curl/Ruby"
31
-
32
- # Let's see what happens under the hood
33
- curl.verbose = true
34
-
35
- # Google will redirect us a bit
36
- curl.follow_location = true
37
-
38
- # Google will make sure we retain cookies
39
- curl.enable_cookies = true
40
- end
41
-
42
- puts "FINISHED: HTTP #{c.response_code}"
43
- puts c.body_str
44
-
45
- # As an alternative to passing the PostFields, we could have supplied
46
- # individual pre-encoded option strings, or a single string with the
47
- # entire form data.
48
-