curb 0.1.4 → 0.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -1,106 +1,177 @@
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
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)
5
6
 
6
7
  Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for the
7
8
  libcurl(3), a fully-featured client-side URL transfer library.
8
- cURL and libcurl live at http://curl.haxx.se/ .
9
+ cURL and libcurl live at [http://curl.haxx.se/](http://curl.haxx.se/) .
9
10
 
10
- Curb is a work-in-progress, and currently only supports libcurl's 'easy' mode.
11
+ Curb is a work-in-progress, and currently only supports libcurl's 'easy' and 'multi' modes.
11
12
 
12
- === License
13
+ ## License
13
14
 
14
15
  Curb is copyright (c)2006 Ross Bamford, and released under the terms of the
15
16
  Ruby license. See the LICENSE file for the gory details.
16
17
 
17
- === You will need
18
+ ## You will need
18
19
 
19
- * A working Ruby installation (1.8+, tested with 1.8.5)
20
- * A working (lib)curl installation, with development stuff (7.5+, tested with 7.15)
21
- * A sane build environment
20
+ + A working Ruby installation (1.8+, tested with 1.8.6, 1.8.7, 1.9.1, and 1.9.2)
21
+ + A working (lib)curl installation, with development stuff (7.5+, tested with 7.19.x)
22
+ + A sane build environment (e.g. gcc, make)
22
23
 
23
- === Installation...
24
+ ## Installation...
24
25
 
25
26
  ... will usually be as simple as:
26
27
 
27
- $ gem install curb
28
+ $ gem install curb
28
29
 
29
30
  Or, if you downloaded the archive:
30
31
 
31
- $ rake install
32
+ $ rake install
32
33
 
33
34
  If you have a wierd setup, you might need extconf options. In this case, pass
34
35
  them like so:
35
36
 
36
- $ 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'
37
38
 
38
- Currently, Curb is tested only on GNU/Linux x86 - YMMV on other platforms.
39
+ Curb is tested only on GNU/Linux x86 and Mac OSX - YMMV on other platforms.
39
40
  If you do use another platform and experience problems, or if you can
40
- expand on the above instructions, please get in touch via the mailing
41
- list on Curb's Rubyforge page.
41
+ expand on the above instructions, please report the issue at http://github.com/taf2/curb/issues
42
42
 
43
43
  Curb has fairly extensive RDoc comments in the source. You can build the
44
44
  documentation with:
45
45
 
46
- $ rake doc
46
+ $ rake doc
47
47
 
48
- === Examples
48
+ ## Usage & examples
49
49
 
50
- Simple fetch via HTTP:
50
+ Curb provides two classes:
51
51
 
52
- c = Curl::Easy.perform("http://www.google.co.uk")
53
- puts c.body_str
52
+ + Curl::Easy - simple API, for day-to-day tasks.
53
+ + Curl::Multi - more advanced API, for operating on multiple URLs simultaneously.
54
54
 
55
- Same thing, more manual:
55
+ ### Simple fetch via HTTP:
56
56
 
57
- c = Curl::Easy.new("http://www.google.co.uk")
58
- c.perform
59
- puts c.body_str
57
+ c = Curl::Easy.perform("http://www.google.co.uk")
58
+ puts c.body_str
60
59
 
61
- Additional config:
60
+ Same thing, more manual:
62
61
 
63
- Curl::Easy.perform("http://www.google.co.uk") do |curl|
64
- curl.headers["User-Agent"] = "myapp-0.0"
65
- curl.verbose = true
66
- end
62
+ c = Curl::Easy.new("http://www.google.co.uk")
63
+ c.perform
64
+ puts c.body_str
67
65
 
68
- Same thing, more manual:
66
+ ### Additional config:
69
67
 
70
- c = Curl::Easy.new("http://www.google.co.uk") do |curl|
71
- curl.headers["User-Agent"] = "myapp-0.0"
72
- curl.verbose = true
73
- end
74
-
75
- c.perform
68
+ Curl::Easy.perform("http://www.google.co.uk") do |curl|
69
+ curl.headers["User-Agent"] = "myapp-0.0"
70
+ curl.verbose = true
71
+ end
76
72
 
77
- Supplying custom handlers:
73
+ Same thing, more manual:
78
74
 
79
- c = Curl::Easy.new("http://www.google.co.uk")
80
-
81
- c.on_body { |data| print(data) }
82
- c.on_header { |data| print(data) }
75
+ c = Curl::Easy.new("http://www.google.co.uk") do |curl|
76
+ curl.headers["User-Agent"] = "myapp-0.0"
77
+ curl.verbose = true
78
+ end
83
79
 
84
- c.perform
85
-
86
- Reusing Curls:
80
+ c.perform
87
81
 
88
- c = Curl::Easy.new
82
+ ### HTTP basic authentication:
89
83
 
90
- ["http://www.google.co.uk", "http://www.ruby-lang.org/"].map do |url|
91
- c.url = url
84
+ c = Curl::Easy.new("http://github.com/")
85
+ c.http_auth_types = :basic
86
+ c.username = 'foo'
87
+ c.password = 'bar'
92
88
  c.perform
93
- c.body_str
94
- end
95
-
96
- HTTP POST form:
97
89
 
98
- c = Curl::Easy.http_post("http://my.rails.box/thing/create",
99
- Curl::PostField.content('thing[name]', 'box',
100
- Curl::PostField.content('thing[type]', 'storage')
90
+ ### Supplying custom handlers:
101
91
 
102
- HTTP POST file upload:
92
+ c = Curl::Easy.new("http://www.google.co.uk")
93
+
94
+ c.on_body { |data| print(data) }
95
+ c.on_header { |data| print(data) }
96
+
97
+ c.perform
103
98
 
104
- c = Curl::Easy.new("http://my.rails.box/files/upload")
105
- c.multipart_form_post = true
106
- c.http_post(Curl::PostField.file('myfile.rb'))
99
+ ### Reusing Curls:
100
+
101
+ c = Curl::Easy.new
102
+
103
+ ["http://www.google.co.uk", "http://www.ruby-lang.org/"].map do |url|
104
+ c.url = url
105
+ c.perform
106
+ c.body_str
107
+ end
108
+
109
+ ### HTTP POST form:
110
+
111
+ c = Curl::Easy.http_post("http://my.rails.box/thing/create",
112
+ Curl::PostField.content('thing[name]', 'box'),
113
+ Curl::PostField.content('thing[type]', 'storage'))
114
+
115
+ ### HTTP POST file upload:
116
+
117
+ c = Curl::Easy.new("http://my.rails.box/files/upload")
118
+ c.multipart_form_post = true
119
+ c.http_post(Curl::PostField.file('myfile.rb'))
120
+
121
+ ### Multi Interface (Basic HTTP GET):
122
+
123
+ # make multiple GET requests
124
+ easy_options = {:follow_location => true}
125
+ multi_options = {:pipeline => true}
126
+
127
+ Curl::Multi.get('url1','url2','url3','url4','url5', easy_options, multi_options) do|easy|
128
+ # do something interesting with the easy response
129
+ puts easy.last_effective_url
130
+ end
131
+
132
+ ### Multi Interface (Basic HTTP POST):
133
+
134
+ # make multiple POST requests
135
+ easy_options = {:follow_location => true, :multipart_form_post => true}
136
+ multi_options = {:pipeline => true}
137
+
138
+ url_fields = [
139
+ { :url => 'url1', :post_fields => {'f1' => 'v1'} },
140
+ { :url => 'url2', :post_fields => {'f1' => 'v1'} },
141
+ { :url => 'url3', :post_fields => {'f1' => 'v1'} }
142
+ ]
143
+
144
+ Curl::Multi.post(url_fields, easy_options, multi_options) do|easy|
145
+ # do something interesting with the easy response
146
+ puts easy.last_effective_url
147
+ end
148
+
149
+ ### Multi Interface (Advanced):
150
+
151
+ responses = {}
152
+ requests = ["http://www.google.co.uk/", "http://www.ruby-lang.org/"]
153
+ m = Curl::Multi.new
154
+ # add a few easy handles
155
+ requests.each do |url|
156
+ responses[url] = ""
157
+ c = Curl::Easy.new(url) do|curl|
158
+ curl.follow_location = true
159
+ curl.on_body{|data| responses[url] << data; data.size }
160
+ curl.on_success {|easy| puts "success, add more easy handles" }
161
+ end
162
+ m.add(c)
163
+ end
164
+
165
+ m.perform do
166
+ puts "idling... can do some work here"
167
+ end
168
+
169
+ requests.each do|url|
170
+ puts responses[url]
171
+ end
172
+
173
+ ### Easy Callbacks
174
+
175
+ on_success: is called when the response code is 20x
176
+ on_failure: is called when the response code is not success, including redirects e.g. 30x
177
+ on_complete: is called in all cases.
data/Rakefile CHANGED
@@ -4,12 +4,6 @@ require 'rake/clean'
4
4
  require 'rake/testtask'
5
5
  require 'rake/rdoctask'
6
6
 
7
- begin
8
- require 'rake/gempackagetask'
9
- rescue LoadError
10
- $stderr.puts("Rubygems support disabled")
11
- end
12
-
13
7
  CLEAN.include '**/*.o'
14
8
  CLEAN.include "**/*.#{Config::MAKEFILE_CONFIG['DLEXT']}"
15
9
  CLOBBER.include 'doc'
@@ -21,8 +15,8 @@ def announce(msg='')
21
15
  $stderr.puts msg
22
16
  end
23
17
 
24
- desc "Default Task (Build packages)"
25
- task :default => :package
18
+ desc "Default Task (Test project)"
19
+ task :default => :test
26
20
 
27
21
  # Determine the current version of the software
28
22
  if File.read('ext/curb.h') =~ /\s*CURB_VERSION\s*['"](\d.+)['"]/
@@ -42,7 +36,8 @@ task :test_ver do
42
36
  end
43
37
 
44
38
  # Make tasks -----------------------------------------------------
45
- MAKECMD = ENV['MAKE_CMD'] || 'make'
39
+ make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
40
+ MAKECMD = ENV['MAKE_CMD'] || make_program
46
41
  MAKEOPTS = ENV['MAKE_OPTS'] || ''
47
42
 
48
43
  CURB_SO = "ext/curb_core.#{Config::MAKEFILE_CONFIG['DLEXT']}"
@@ -61,13 +56,18 @@ def make(target = '')
61
56
  end
62
57
 
63
58
  # Let make handle dependencies between c/o/so - we'll just run it.
64
- file CURB_SO => 'ext/Makefile' do
59
+ file CURB_SO => (['ext/Makefile'] + Dir['ext/*.c'] + Dir['ext/*.h']) do
65
60
  m = make
66
61
  fail "Make failed (status #{m})" unless m == 0
67
62
  end
68
63
 
69
64
  desc "Compile the shared object"
70
- task :compile => CURB_SO
65
+ task :compile => [CURB_SO]
66
+
67
+ desc "Create the markdown file"
68
+ task :markdown do
69
+ cp "README", "README.markdown"
70
+ end
71
71
 
72
72
  desc "Install to your site_ruby directory"
73
73
  task :install => :alltests do
@@ -78,7 +78,11 @@ end
78
78
  # Test Tasks ---------------------------------------------------------
79
79
  task :ta => :alltests
80
80
  task :tu => :unittests
81
- task :test => :unittests
81
+ task :test => [:rmpid,:unittests]
82
+
83
+ task :rmpid do
84
+ FileUtils.rm_rf Dir.glob("tests/server_lock-*")
85
+ end
82
86
 
83
87
  if ENV['RELTEST']
84
88
  announce "Release task testing - not running regression tests on alltests"
@@ -96,7 +100,7 @@ Rake::TestTask.new(:bugtests) do |t|
96
100
  t.test_files = FileList['tests/bug_*.rb']
97
101
  t.verbose = false
98
102
  end
99
-
103
+
100
104
  #Rake::TestTask.new(:funtests) do |t|
101
105
  # t.test_files = FileList['test/func_*.rb']
102
106
  #t.warning = true
@@ -106,6 +110,25 @@ end
106
110
  task :unittests => :compile
107
111
  task :bugtests => :compile
108
112
 
113
+ def has_gem?(file,name)
114
+ begin
115
+ require file
116
+ has_http_persistent = true
117
+ rescue LoadError => e
118
+ puts "Skipping #{name}"
119
+ end
120
+ end
121
+
122
+ desc "Benchmark curl against http://127.0.0.1/zeros-2k - will fail if /zeros-2k or 127.0.0.1 are missing"
123
+ task :bench do
124
+ sh "ruby bench/curb_easy.rb"
125
+ sh "ruby bench/curb_multi.rb"
126
+ sh "ruby bench/nethttp_test.rb" if has_gem?("net/http/persistent","net-http-persistent")
127
+ sh "ruby bench/patron_test.rb" if has_gem?("patron","patron")
128
+ sh "ruby bench/typhoeus_test.rb" if has_gem?("typhoeus","typhoeus")
129
+ sh "ruby bench/typhoeus_hydra_test.rb" if has_gem?("typhoeus","typhoeus")
130
+ end
131
+
109
132
  # RDoc Tasks ---------------------------------------------------------
110
133
  desc "Create the RDOC documentation"
111
134
  task :doc do
@@ -130,73 +153,63 @@ task :doc_upload => [ :doc ] do
130
153
  end
131
154
  end
132
155
 
133
- # Packaging ------------------------------------------------
134
- PKG_FILES = FileList[
135
- 'ext/*.rb',
136
- 'ext/*.c',
137
- 'ext/*.h',
138
- 'tests/**/*',
139
- 'samples/**/*',
140
- 'doc.rb',
141
- '[A-Z]*',
142
- ]
143
-
144
156
  if ! defined?(Gem)
145
157
  warn "Package Target requires RubyGEMs"
146
158
  else
147
- spec = Gem::Specification.new do |s|
148
-
149
- #### Basic information.
150
-
151
- s.name = 'curb'
152
- s.version = PKG_VERSION
153
- s.summary = "Ruby bindings for the libcurl(3) URL transfer library."
154
- s.description = <<-EOF
155
- C-language Ruby bindings for the libcurl(3) URL transfer library.
156
- EOF
157
- s.extensions = 'ext/extconf.rb'
159
+ desc 'Generate gem specification'
160
+ task :gemspec do
161
+ require 'erb'
162
+ tspec = ERB.new(File.read(File.join(File.dirname(__FILE__),'lib','curb.gemspec.erb')))
163
+ File.open(File.join(File.dirname(__FILE__),'curb.gemspec'),'wb') do|f|
164
+ f << tspec.result
165
+ end
166
+ end
158
167
 
159
- #### Which files are to be included in this gem?
168
+ desc 'Build gem'
169
+ task :package => :gemspec do
170
+ require 'rubygems/specification'
171
+ spec_source = File.read File.join(File.dirname(__FILE__),'curb.gemspec')
172
+ spec = nil
173
+ # see: http://gist.github.com/16215
174
+ Thread.new { spec = eval("$SAFE = 3\n#{spec_source}") }.join
175
+ spec.validate
176
+ Gem::Builder.new(spec).build
177
+ end
160
178
 
161
- s.files = PKG_FILES.to_a
179
+ task :static do
180
+ ENV['STATIC_BUILD'] = '1'
181
+ end
162
182
 
163
- #### Load-time details
164
- s.require_path = 'lib'
165
-
166
- #### Documentation and testing.
167
- s.has_rdoc = true
168
- s.extra_rdoc_files = Dir['ext/*.c'] << 'ext/curb.rb' << 'README' << 'LICENSE'
169
- s.rdoc_options <<
170
- '--title' << 'Curb API' <<
171
- '--main' << 'README'
172
-
173
- s.test_files = Dir.glob('tests/tc_*.rb')
174
-
175
- #### Author and project details.
183
+ task :binary_gemspec => [:static, :compile] do
184
+ require 'erb'
185
+ ENV['BINARY_PACKAGE'] = '1'
186
+ tspec = ERB.new(File.read(File.join(File.dirname(__FILE__),'lib','curb.gemspec.erb')))
176
187
 
177
- s.author = "Ross Bamford"
178
- s.email = "curb-devel@rubyforge.org"
179
- s.homepage = "http://curb.rubyforge.org"
180
- s.rubyforge_project = "curb"
188
+ File.open(File.join(File.dirname(__FILE__),'curb-binary.gemspec'),'wb') do|f|
189
+ f << tspec.result
190
+ end
181
191
  end
182
-
183
- # Quick fix for Ruby 1.8.3 / YAML bug
184
- if (RUBY_VERSION == '1.8.3')
185
- def spec.to_yaml
186
- out = super
187
- out = '--- ' + out unless out =~ /^---/
188
- out
189
- end
192
+
193
+ desc 'Strip extra strings from Binary'
194
+ task :binary_strip do
195
+ strip = '/usr/bin/strip'
196
+ if File.exist?(strip) and `#{strip} -h 2>&1`.match(/GNU/)
197
+ sh "#{strip} #{CURB_SO}"
198
+ end
190
199
  end
191
200
 
192
- package_task = Rake::GemPackageTask.new(spec) do |pkg|
193
- pkg.need_zip = true
194
- pkg.need_tar_gz = true
195
- pkg.package_dir = 'pkg'
196
- end
201
+ desc 'Build gem'
202
+ task :binary_package => [:binary_gemspec, :binary_strip] do
203
+ require 'rubygems/specification'
204
+ spec_source = File.read File.join(File.dirname(__FILE__),'curb-binary.gemspec')
205
+ spec = nil
206
+ # see: http://gist.github.com/16215
207
+ Thread.new { spec = eval("$SAFE = 3\n#{spec_source}") }.join
208
+ spec.validate
209
+ Gem::Builder.new(spec).build
210
+ end
197
211
  end
198
212
 
199
-
200
213
  # --------------------------------------------------------------------
201
214
  # Creating a release
202
215
  desc "Make a new release (Requires SVN commit / webspace access)"
data/doc.rb CHANGED
@@ -34,7 +34,7 @@ begin
34
34
  end
35
35
  end
36
36
 
37
- system("rdoc --title='Curb - libcurl bindings for ruby' --main=README #{pp_srcdir}/*.c README LICENSE ext/curb.rb")
37
+ system("rdoc --title='Curb - libcurl bindings for ruby' --main=README #{pp_srcdir}/*.c README LICENSE lib/curb.rb")
38
38
  ensure
39
39
  rm_rf(tmpdir)
40
40
  end