curb 0.6.5.0 → 0.8.4

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
@@ -40,19 +40,41 @@ Curb is tested only on GNU/Linux x86 and Mac OSX - YMMV on other platforms.
40
40
  If you do use another platform and experience problems, or if you can
41
41
  expand on the above instructions, please report the issue at http://github.com/taf2/curb/issues
42
42
 
43
+ On Ubuntu, the dependencies can be satisfied by installing the following packages:
44
+
45
+ $ sudo apt-get install libcurl3 libcurl3-gnutls libcurl4-openssl-dev
46
+
43
47
  Curb has fairly extensive RDoc comments in the source. You can build the
44
48
  documentation with:
45
49
 
46
50
  $ rake doc
47
51
 
48
- ## Examples
52
+ ## Usage & examples
53
+
54
+ Curb provides two classes:
55
+
56
+ + Curl::Easy - simple API, for day-to-day tasks.
57
+ + Curl::Multi - more advanced API, for operating on multiple URLs simultaneously.
58
+
59
+ ### Super simple API (less typing)
60
+
61
+ http = Curl.get("http://www.google.com/")
62
+ puts http.body_str
63
+
64
+ http = Curl.post("http://www.google.com/", {:foo => "bar"})
65
+ puts http.body_str
66
+
67
+ http = Curl.get("http://www.google.com/") do|http|
68
+ http.headers['Cookie'] = 'foo=1;bar=2'
69
+ end
70
+ puts http.body_str
49
71
 
50
72
  ### Simple fetch via HTTP:
51
73
 
52
74
  c = Curl::Easy.perform("http://www.google.co.uk")
53
75
  puts c.body_str
54
76
 
55
- ### Same thing, more manual:
77
+ Same thing, more manual:
56
78
 
57
79
  c = Curl::Easy.new("http://www.google.co.uk")
58
80
  c.perform
@@ -65,7 +87,7 @@ documentation with:
65
87
  curl.verbose = true
66
88
  end
67
89
 
68
- ### Same thing, more manual:
90
+ Same thing, more manual:
69
91
 
70
92
  c = Curl::Easy.new("http://www.google.co.uk") do |curl|
71
93
  curl.headers["User-Agent"] = "myapp-0.0"
@@ -74,6 +96,14 @@ documentation with:
74
96
 
75
97
  c.perform
76
98
 
99
+ ### HTTP basic authentication:
100
+
101
+ c = Curl::Easy.new("http://github.com/")
102
+ c.http_auth_types = :basic
103
+ c.username = 'foo'
104
+ c.password = 'bar'
105
+ c.perform
106
+
77
107
  ### Supplying custom handlers:
78
108
 
79
109
  c = Curl::Easy.new("http://www.google.co.uk")
@@ -103,7 +133,7 @@ documentation with:
103
133
 
104
134
  c = Curl::Easy.new("http://my.rails.box/files/upload")
105
135
  c.multipart_form_post = true
106
- c.http_post(Curl::PostField.file('myfile.rb'))
136
+ c.http_post(Curl::PostField.file('thing[file]', 'myfile.rb'))
107
137
 
108
138
  ### Multi Interface (Basic HTTP GET):
109
139
 
@@ -144,14 +174,21 @@ documentation with:
144
174
  c = Curl::Easy.new(url) do|curl|
145
175
  curl.follow_location = true
146
176
  curl.on_body{|data| responses[url] << data; data.size }
177
+ curl.on_success {|easy| puts "success, add more easy handles" }
147
178
  end
148
179
  m.add(c)
149
180
  end
150
181
 
151
182
  m.perform do
152
- puts "idling... can do some work here, including add new requests"
183
+ puts "idling... can do some work here"
153
184
  end
154
185
 
155
186
  requests.each do|url|
156
187
  puts responses[url]
157
188
  end
189
+
190
+ ### Easy Callbacks
191
+
192
+ on_success: is called when the response code is 20x
193
+ on_failure: is called when the response code is not success, including redirects e.g. 30x
194
+ on_complete: is called in all cases.
data/Rakefile CHANGED
@@ -2,10 +2,14 @@
2
2
  #
3
3
  require 'rake/clean'
4
4
  require 'rake/testtask'
5
- require 'rake/rdoctask'
5
+ begin
6
+ require 'rdoc/task'
7
+ rescue LoadError => e
8
+ require 'rake/rdoctask'
9
+ end
6
10
 
7
11
  CLEAN.include '**/*.o'
8
- CLEAN.include "**/*.#{Config::MAKEFILE_CONFIG['DLEXT']}"
12
+ CLEAN.include "**/*.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
9
13
  CLOBBER.include 'doc'
10
14
  CLOBBER.include '**/*.log'
11
15
  CLOBBER.include '**/Makefile'
@@ -40,7 +44,7 @@ make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
40
44
  MAKECMD = ENV['MAKE_CMD'] || make_program
41
45
  MAKEOPTS = ENV['MAKE_OPTS'] || ''
42
46
 
43
- CURB_SO = "ext/curb_core.#{Config::MAKEFILE_CONFIG['DLEXT']}"
47
+ CURB_SO = "ext/curb_core.#{(defined?(RbConfig) ? RbConfig : Config)::MAKEFILE_CONFIG['DLEXT']}"
44
48
 
45
49
  file 'ext/Makefile' => 'ext/extconf.rb' do
46
50
  Dir.chdir('ext') do
@@ -100,7 +104,7 @@ Rake::TestTask.new(:bugtests) do |t|
100
104
  t.test_files = FileList['tests/bug_*.rb']
101
105
  t.verbose = false
102
106
  end
103
-
107
+
104
108
  #Rake::TestTask.new(:funtests) do |t|
105
109
  # t.test_files = FileList['test/func_*.rb']
106
110
  #t.warning = true
@@ -110,6 +114,25 @@ end
110
114
  task :unittests => :compile
111
115
  task :bugtests => :compile
112
116
 
117
+ def has_gem?(file,name)
118
+ begin
119
+ require file
120
+ has_http_persistent = true
121
+ rescue LoadError => e
122
+ puts "Skipping #{name}"
123
+ end
124
+ end
125
+
126
+ desc "Benchmark curl against http://127.0.0.1/zeros-2k - will fail if /zeros-2k or 127.0.0.1 are missing"
127
+ task :bench do
128
+ sh "ruby bench/curb_easy.rb"
129
+ sh "ruby bench/curb_multi.rb"
130
+ sh "ruby bench/nethttp_test.rb" if has_gem?("net/http/persistent","net-http-persistent")
131
+ sh "ruby bench/patron_test.rb" if has_gem?("patron","patron")
132
+ sh "ruby bench/typhoeus_test.rb" if has_gem?("typhoeus","typhoeus")
133
+ sh "ruby bench/typhoeus_hydra_test.rb" if has_gem?("typhoeus","typhoeus")
134
+ end
135
+
113
136
  # RDoc Tasks ---------------------------------------------------------
114
137
  desc "Create the RDOC documentation"
115
138
  task :doc do