taf2-curb 0.5.2.0 → 0.5.4.0

Sign up to get free protection for your applications and to get access to all the features.
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.5.2.0"
24
- #define CURB_VER_NUM 520
23
+ #define CURB_VERSION "0.5.4.0"
24
+ #define CURB_VER_NUM 540
25
25
  #define CURB_VER_MAJ 0
26
26
  #define CURB_VER_MIN 5
27
- #define CURB_VER_MIC 2
27
+ #define CURB_VER_MIC 4
28
28
  #define CURB_VER_PATCH 0
29
29
 
30
30
 
@@ -2599,13 +2599,17 @@ static VALUE ruby_curl_easy_inspect(VALUE self) {
2599
2599
  * converted to their "URL escaped" version (%NN where NN is a
2600
2600
  * two-digit hexadecimal number).
2601
2601
  */
2602
- static VALUE ruby_curl_easy_escape(VALUE self, VALUE str) {
2602
+ static VALUE ruby_curl_easy_escape(VALUE self, VALUE svalue) {
2603
2603
  ruby_curl_easy *rbce;
2604
2604
  char *result;
2605
2605
  VALUE rresult;
2606
+ VALUE str = svalue;
2606
2607
 
2607
2608
  Data_Get_Struct(self, ruby_curl_easy, rbce);
2608
2609
 
2610
+ /* NOTE: make sure the value is a string, if not call to_s */
2611
+ if( rb_type(str) != T_STRING ) { str = rb_funcall(str,rb_intern("to_s"),0); }
2612
+
2609
2613
  #if (LIBCURL_VERSION_NUM >= 0x070f04)
2610
2614
  result = (char*)curl_easy_escape(rbce->curl, StringValuePtr(str), RSTRING_LEN(str));
2611
2615
  #else
@@ -63,22 +63,11 @@ module Curl
63
63
  #
64
64
  # Blocking call to fetch multiple url's in parallel.
65
65
  def get(urls, easy_options={}, multi_options={}, &blk)
66
- m = Curl::Multi.new
67
- # configure the multi handle
68
- multi_options.each do|k,v|
69
- m.send("#{k}=", v)
70
- end
71
-
72
- # create and configure each easy handle
66
+ url_confs = []
73
67
  urls.each do|url|
74
- c = Curl::Easy.new(url)
75
- easy_options.each do|k,v|
76
- c.send("#{k}=",v)
77
- end
78
- c.on_complete {|curl| blk.call curl } if blk
79
- m.add(c)
68
+ url_confs << {:url => url, :method => :get}.merge(easy_options)
80
69
  end
81
- m.perform
70
+ self.http(url_confs, multi_options) {|c,code,method| blk.call(c) }
82
71
  end
83
72
 
84
73
  # call-seq:
@@ -97,36 +86,39 @@ module Curl
97
86
  # easy_options: are a set of common options to set on all easy handles
98
87
  # multi_options: options to set on the Curl::Multi handle
99
88
  #
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)
89
+ def post(urls_with_config, easy_options={}, multi_options={}, &blk)
90
+ url_confs = []
91
+ urls_with_config.each do|uconf|
92
+ url_confs << uconf.merge(:method => :post).merge(easy_options)
105
93
  end
94
+ self.http(url_confs, multi_options) {|c,code,method| blk.call(c) }
95
+ end
106
96
 
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
- headers = c.delete(:headers)
112
-
113
- easy = Curl::Easy.new(url)
114
- # set the post post using the url fields
115
- easy.post_body = fields.map{|f,k| "#{easy.escape(f)}=#{easy.escape(k)}"}.join('&')
116
- # configure the easy handle
117
- easy_options.each do|k,v|
118
- easy.send("#{k}=",v)
119
- end
120
-
121
- # headers is a special key
122
- headers.each {|k,v| easy.headers[k] = v } if headers
123
-
124
- easy.on_complete {|curl| blk.call curl } if blk
125
- m.add(easy)
97
+ # call-seq:
98
+ #
99
+ # Curl::Multi.put([{:url => 'url1', :put_data => "some message"},
100
+ # {:url => 'url2', :put_data => IO.read('filepath')},
101
+ # {:url => 'url3', :put_data => "maybe another string or socket?"],
102
+ # {:follow_location => true},
103
+ # {:pipeline => true }) do|easy|
104
+ # easy_handle_on_request_complete
105
+ # end
106
+ #
107
+ # Blocking call to POST multiple form's in parallel.
108
+ #
109
+ # urls_with_config: is a hash of url's pointing to the postfields to send
110
+ # easy_options: are a set of common options to set on all easy handles
111
+ # multi_options: options to set on the Curl::Multi handle
112
+ #
113
+ def put(urls_with_config, easy_options={}, multi_options={}, &blk)
114
+ url_confs = []
115
+ urls_with_config.each do|uconf|
116
+ url_confs << uconf.merge(:method => :put).merge(easy_options)
126
117
  end
127
- m.perform
118
+ self.http(url_confs, multi_options) {|c,code,method| blk.call(c) }
128
119
  end
129
120
 
121
+
130
122
  # call-seq:
131
123
  #
132
124
  # Curl::Multi.http( [
@@ -144,7 +136,7 @@ module Curl
144
136
  # multi_options: options for the multi handle
145
137
  # blk: a callback, that yeilds when a handle is completed
146
138
  #
147
- def http(urls_with_config, multi_options, &blk)
139
+ def http(urls_with_config, multi_options={}, &blk)
148
140
  m = Curl::Multi.new
149
141
  # configure the multi handle
150
142
  multi_options.each { |k,v| m.send("#{k}=", v) }
@@ -325,6 +325,17 @@ class TestCurbCurlMulti < Test::Unit::TestCase
325
325
  end
326
326
  end
327
327
 
328
+ def test_multi_easy_put_01
329
+ urls = [{ :url => TestServlet.url, :method => :put, :put_data => "message",
330
+ :headers => {'Content-Type' => 'application/json' } },
331
+ { :url => TestServlet.url, :method => :put, :put_data => "message",
332
+ :headers => {'Content-Type' => 'application/json' } }]
333
+ Curl::Multi.put(urls, {}, {:pipeline => true}) do|easy|
334
+ assert_match /PUT/, easy.body_str
335
+ assert_match /message/, easy.body_str
336
+ end
337
+ end
338
+
328
339
  def test_multi_easy_http_01
329
340
  urls = [
330
341
  { :url => TestServlet.url + '?q=1', :method => :post, :post_fields => {'field1' => 'value1', 'k' => 'j'}},
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.5.2.0
4
+ version: 0.5.4.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-08-23 00:00:00 -07:00
13
+ date: 2009-09-23 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies: []
16
16