fotonauts-curb 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,51 @@
1
+ Copyright (c) 2006 Ross Bamford (rosco AT roscopeco DOT co DOT uk).
2
+ Curb is free software licensed under the following terms:
3
+
4
+ 1. You may make and give away verbatim copies of the source form of the
5
+ software without restriction, provided that you duplicate all of the
6
+ original copyright notices and associated disclaimers.
7
+
8
+ 2. You may modify your copy of the software in any way, provided that
9
+ you do at least ONE of the following:
10
+
11
+ a) place your modifications in the Public Domain or otherwise
12
+ make them Freely Available, such as by posting said
13
+ modifications to Usenet or an equivalent medium, or by allowing
14
+ the author to include your modifications in the software.
15
+
16
+ b) use the modified software only within your corporation or
17
+ organization.
18
+
19
+ c) give non-standard binaries non-standard names, with
20
+ instructions on where to get the original software distribution.
21
+
22
+ d) make other distribution arrangements with the author.
23
+
24
+ 3. You may distribute the software in object code or binary form,
25
+ provided that you do at least ONE of the following:
26
+
27
+ a) distribute the binaries and library files of the software,
28
+ together with instructions (in the manual page or equivalent)
29
+ on where to get the original distribution.
30
+
31
+ b) accompany the distribution with the machine-readable source of
32
+ the software.
33
+
34
+ c) give non-standard binaries non-standard names, with
35
+ instructions on where to get the original software distribution.
36
+
37
+ d) make other distribution arrangements with the author.
38
+
39
+ 4. You may modify and include the part of the software into any other
40
+ software (possibly commercial).
41
+
42
+ 5. The scripts and library files supplied as input to or produced as
43
+ output from the software do not automatically fall under the
44
+ copyright of the software, but belong to whomever generated them,
45
+ and may be sold commercially, and may be aggregated with this
46
+ software.
47
+
48
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
49
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
50
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51
+ PURPOSE.
data/README ADDED
@@ -0,0 +1,158 @@
1
+ # Curb - Libcurl bindings for Ruby
2
+
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
+
7
+ Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for the
8
+ libcurl(3), a fully-featured client-side URL transfer library.
9
+ cURL and libcurl live at [http://curl.haxx.se/](http://curl.haxx.se/) .
10
+
11
+ Curb is a work-in-progress, and currently only supports libcurl's 'easy' and 'multi' modes.
12
+
13
+ ## License
14
+
15
+ Curb is copyright (c)2006 Ross Bamford, and released under the terms of the
16
+ Ruby license. See the LICENSE file for the gory details.
17
+
18
+ ## You will need
19
+
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)
23
+
24
+ ## Installation...
25
+
26
+ ... will usually be as simple as:
27
+
28
+ $ gem install curb
29
+
30
+ Or, if you downloaded the archive:
31
+
32
+ $ rake install
33
+
34
+ If you have a wierd setup, you might need extconf options. In this case, pass
35
+ them like so:
36
+
37
+ $ rake install EXTCONF_OPTS='--with-curl-dir=/path/to/libcurl --prefix=/what/ever'
38
+
39
+ Curb is tested only on GNU/Linux x86 and Mac OSX - YMMV on other platforms.
40
+ If you do use another platform and experience problems, or if you can
41
+ expand on the above instructions, please report the issue at http://github.com/taf2/curb/issues
42
+
43
+ Curb has fairly extensive RDoc comments in the source. You can build the
44
+ documentation with:
45
+
46
+ $ rake doc
47
+
48
+ ## Examples
49
+
50
+ ### Simple fetch via HTTP:
51
+
52
+ c = Curl::Easy.perform("http://www.google.co.uk")
53
+ puts c.body_str
54
+
55
+ ### Same thing, more manual:
56
+
57
+ c = Curl::Easy.new("http://www.google.co.uk")
58
+ c.perform
59
+ puts c.body_str
60
+
61
+ ### Additional config:
62
+
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
67
+
68
+ ### Same thing, more manual:
69
+
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
76
+
77
+ ### Supplying custom handlers:
78
+
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) }
83
+
84
+ c.perform
85
+
86
+ ### Reusing Curls:
87
+
88
+ c = Curl::Easy.new
89
+
90
+ ["http://www.google.co.uk", "http://www.ruby-lang.org/"].map do |url|
91
+ c.url = url
92
+ c.perform
93
+ c.body_str
94
+ end
95
+
96
+ ### HTTP POST form:
97
+
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'))
101
+
102
+ ### HTTP POST file upload:
103
+
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'))
107
+
108
+ ### Multi Interface (Basic HTTP GET):
109
+
110
+ # make multiple GET requests
111
+ easy_options = {:follow_location => true}
112
+ multi_options = {:pipeline => true}
113
+
114
+ Curl::Multi.get('url1','url2','url3','url4','url5', easy_options, multi_options) do|easy|
115
+ # do something interesting with the easy response
116
+ puts easy.last_effective_url
117
+ end
118
+
119
+ ### Multi Interface (Basic HTTP POST):
120
+
121
+ # make multiple POST requests
122
+ easy_options = {:follow_location => true, :multipart_form_post => true}
123
+ multi_options = {:pipeline => true}
124
+
125
+ url_fields = [
126
+ { :url => 'url1', :post_fields => {'f1' => 'v1'} },
127
+ { :url => 'url2', :post_fields => {'f1' => 'v1'} },
128
+ { :url => 'url3', :post_fields => {'f1' => 'v1'} }
129
+ ]
130
+
131
+ Curl::Multi.post(url_fields, easy_options, multi_options) do|easy|
132
+ # do something interesting with the easy response
133
+ puts easy.last_effective_url
134
+ end
135
+
136
+ ### Multi Interface (Advanced):
137
+
138
+ responses = {}
139
+ requests = ["http://www.google.co.uk/", "http://www.ruby-lang.org/"]
140
+ m = Curl::Multi.new
141
+ # add a few easy handles
142
+ requests.each do |url|
143
+ responses[url] = ""
144
+ c = Curl::Easy.new(url) do|curl|
145
+ curl.follow_location = true
146
+ curl.on_body{|data| responses[url] << data; data.size }
147
+ curl.on_success {|easy| puts "success, add more easy handles" }
148
+ end
149
+ m.add(c)
150
+ end
151
+
152
+ m.perform do
153
+ puts "idling... can do some work here"
154
+ end
155
+
156
+ requests.each do|url|
157
+ puts responses[url]
158
+ end
data/Rakefile ADDED
@@ -0,0 +1,316 @@
1
+ # $Id$
2
+ #
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/rdoctask'
6
+
7
+ CLEAN.include '**/*.o'
8
+ CLEAN.include "**/*.#{Config::MAKEFILE_CONFIG['DLEXT']}"
9
+ CLOBBER.include 'doc'
10
+ CLOBBER.include '**/*.log'
11
+ CLOBBER.include '**/Makefile'
12
+ CLOBBER.include '**/extconf.h'
13
+
14
+ def announce(msg='')
15
+ $stderr.puts msg
16
+ end
17
+
18
+ desc "Default Task (Test project)"
19
+ task :default => :test
20
+
21
+ # Determine the current version of the software
22
+ if File.read('ext/curb.h') =~ /\s*CURB_VERSION\s*['"](\d.+)['"]/
23
+ CURRENT_VERSION = $1
24
+ else
25
+ CURRENT_VERSION = "0.0.0"
26
+ end
27
+
28
+ if ENV['REL']
29
+ PKG_VERSION = ENV['REL']
30
+ else
31
+ PKG_VERSION = CURRENT_VERSION
32
+ end
33
+
34
+ task :test_ver do
35
+ puts PKG_VERSION
36
+ end
37
+
38
+ # Make tasks -----------------------------------------------------
39
+ make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
40
+ MAKECMD = ENV['MAKE_CMD'] || make_program
41
+ MAKEOPTS = ENV['MAKE_OPTS'] || ''
42
+
43
+ CURB_SO = "ext/curb_core.#{Config::MAKEFILE_CONFIG['DLEXT']}"
44
+
45
+ file 'ext/Makefile' => 'ext/extconf.rb' do
46
+ Dir.chdir('ext') do
47
+ ruby "extconf.rb #{ENV['EXTCONF_OPTS']}"
48
+ end
49
+ end
50
+
51
+ def make(target = '')
52
+ Dir.chdir('ext') do
53
+ pid = system("#{MAKECMD} #{MAKEOPTS} #{target}")
54
+ $?.exitstatus
55
+ end
56
+ end
57
+
58
+ # Let make handle dependencies between c/o/so - we'll just run it.
59
+ file CURB_SO => (['ext/Makefile'] + Dir['ext/*.c'] + Dir['ext/*.h']) do
60
+ m = make
61
+ fail "Make failed (status #{m})" unless m == 0
62
+ end
63
+
64
+ desc "Compile the shared object"
65
+ task :compile => [CURB_SO]
66
+
67
+ desc "Create the markdown file"
68
+ task :markdown do
69
+ cp "README", "README.markdown"
70
+ end
71
+
72
+ desc "Install to your site_ruby directory"
73
+ task :install => :alltests do
74
+ m = make 'install'
75
+ fail "Make install failed (status #{m})" unless m == 0
76
+ end
77
+
78
+ # Test Tasks ---------------------------------------------------------
79
+ task :ta => :alltests
80
+ task :tu => :unittests
81
+ task :test => [:rmpid,:unittests]
82
+
83
+ task :rmpid do
84
+ FileUtils.rm_rf Dir.glob("tests/server_lock-*")
85
+ end
86
+
87
+ if ENV['RELTEST']
88
+ announce "Release task testing - not running regression tests on alltests"
89
+ task :alltests => [:unittests]
90
+ else
91
+ task :alltests => [:unittests, :bugtests]
92
+ end
93
+
94
+ Rake::TestTask.new(:unittests) do |t|
95
+ t.test_files = FileList['tests/tc_*.rb']
96
+ t.verbose = false
97
+ end
98
+
99
+ Rake::TestTask.new(:bugtests) do |t|
100
+ t.test_files = FileList['tests/bug_*.rb']
101
+ t.verbose = false
102
+ end
103
+
104
+ #Rake::TestTask.new(:funtests) do |t|
105
+ # t.test_files = FileList['test/func_*.rb']
106
+ #t.warning = true
107
+ #t.warning = true
108
+ #end
109
+
110
+ task :unittests => :compile
111
+ task :bugtests => :compile
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
+
132
+ # RDoc Tasks ---------------------------------------------------------
133
+ desc "Create the RDOC documentation"
134
+ task :doc do
135
+ ruby "doc.rb #{ENV['DOC_OPTS']}"
136
+ end
137
+
138
+ desc "Publish the RDoc documentation to project web site"
139
+ task :doc_upload => [ :doc ] do
140
+ if ENV['RELTEST']
141
+ announce "Release Task Testing, skipping doc upload"
142
+ else
143
+ unless ENV['RUBYFORGE_ACCT']
144
+ raise "Need to set RUBYFORGE_ACCT to your rubyforge.org user name (e.g. 'fred')"
145
+ end
146
+
147
+ require 'rake/contrib/sshpublisher'
148
+ Rake::SshDirPublisher.new(
149
+ "#{ENV['RUBYFORGE_ACCT']}@rubyforge.org",
150
+ "/var/www/gforge-projects/curb",
151
+ "doc"
152
+ ).upload
153
+ end
154
+ end
155
+
156
+ if ! defined?(Gem)
157
+ warn "Package Target requires RubyGEMs"
158
+ else
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
167
+
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
178
+
179
+ task :static do
180
+ ENV['STATIC_BUILD'] = '1'
181
+ end
182
+
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')))
187
+
188
+ File.open(File.join(File.dirname(__FILE__),'curb-binary.gemspec'),'wb') do|f|
189
+ f << tspec.result
190
+ end
191
+ 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
199
+ end
200
+
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
211
+ end
212
+
213
+ # --------------------------------------------------------------------
214
+ # Creating a release
215
+ desc "Make a new release (Requires SVN commit / webspace access)"
216
+ task :release => [
217
+ :prerelease,
218
+ :clobber,
219
+ :alltests,
220
+ :update_version,
221
+ :package,
222
+ :tag,
223
+ :doc_upload] do
224
+
225
+ announce
226
+ announce "**************************************************************"
227
+ announce "* Release #{PKG_VERSION} Complete."
228
+ announce "* Packages ready to upload."
229
+ announce "**************************************************************"
230
+ announce
231
+ end
232
+
233
+ # Validate that everything is ready to go for a release.
234
+ task :prerelease do
235
+ announce
236
+ announce "**************************************************************"
237
+ announce "* Making RubyGem Release #{PKG_VERSION}"
238
+ announce "* (current version #{CURRENT_VERSION})"
239
+ announce "**************************************************************"
240
+ announce
241
+
242
+ # Is a release number supplied?
243
+ unless ENV['REL']
244
+ fail "Usage: rake release REL=x.y.z [REUSE=tag_suffix]"
245
+ end
246
+
247
+ # Is the release different than the current release.
248
+ # (or is REUSE set?)
249
+ if PKG_VERSION == CURRENT_VERSION && ! ENV['REUSE']
250
+ fail "Current version is #{PKG_VERSION}, must specify REUSE=tag_suffix to reuse version"
251
+ end
252
+
253
+ # Are all source files checked in?
254
+ if ENV['RELTEST']
255
+ announce "Release Task Testing, skipping checked-in file test"
256
+ else
257
+ announce "Checking for unchecked-in files..."
258
+ data = `svn status`
259
+ unless data =~ /^$/
260
+ fail "SVN status is not clean ... do you have unchecked-in files?"
261
+ end
262
+ announce "No outstanding checkins found ... OK"
263
+ end
264
+
265
+ announce "Doc will try to use GNU cpp if available"
266
+ ENV['DOC_OPTS'] = "--cpp"
267
+ end
268
+
269
+ # Used during release packaging if a REL is supplied
270
+ task :update_version do
271
+ unless PKG_VERSION == CURRENT_VERSION
272
+ pkg_vernum = PKG_VERSION.tr('.','').sub(/^0*/,'')
273
+ pkg_vernum << '0' until pkg_vernum.length > 2
274
+
275
+ File.open('ext/curb.h.new','w+') do |f|
276
+ maj, min, mic, patch = /(\d+)\.(\d+)(?:\.(\d+))?(?:\.(\d+))?/.match(PKG_VERSION).captures
277
+ f << File.read('ext/curb.h').
278
+ gsub(/CURB_VERSION\s+"(\d.+)"/) { "CURB_VERSION \"#{PKG_VERSION}\"" }.
279
+ gsub(/CURB_VER_NUM\s+\d+/) { "CURB_VER_NUM #{pkg_vernum}" }.
280
+ gsub(/CURB_VER_MAJ\s+\d+/) { "CURB_VER_MAJ #{maj}" }.
281
+ gsub(/CURB_VER_MIN\s+\d+/) { "CURB_VER_MIN #{min}" }.
282
+ gsub(/CURB_VER_MIC\s+\d+/) { "CURB_VER_MIC #{mic || 0}" }.
283
+ gsub(/CURB_VER_PATCH\s+\d+/) { "CURB_VER_PATCH #{patch || 0}" }
284
+ end
285
+ mv('ext/curb.h.new', 'ext/curb.h')
286
+ if ENV['RELTEST']
287
+ announce "Release Task Testing, skipping commiting of new version"
288
+ else
289
+ sh %{svn commit -m "Updated to version #{PKG_VERSION}" ext/curb.h}
290
+ end
291
+ end
292
+ end
293
+
294
+ # "Create a new SVN tag with the latest release number (REL=x.y.z)"
295
+ task :tag => [:prerelease] do
296
+ reltag = "curb-#{PKG_VERSION}"
297
+ reltag << ENV['REUSE'] if ENV['REUSE']
298
+ announce "Tagging SVN with [#{reltag}]"
299
+ if ENV['RELTEST']
300
+ announce "Release Task Testing, skipping SVN tagging"
301
+ else
302
+ # need to get current base URL
303
+ s = `svn info`
304
+ if s =~ /URL:\s*([^\n]*)\n/
305
+ svnroot = $1
306
+ if svnroot =~ /^(.*)\/trunk/i
307
+ svnbase = $1
308
+ sh %{svn cp #{svnroot} #{svnbase}/TAGS/#{reltag} -m "Release #{PKG_VERSION}"}
309
+ else
310
+ fail "Please merge to trunk before making a release"
311
+ end
312
+ else
313
+ fail "Unable to determine repository URL from 'svn info' - is this a working copy?"
314
+ end
315
+ end
316
+ end