taf2-curb 0.2.4 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  * http://curb.rubyforge.org/
4
4
  * http://rubyforge.org/projects/curb
5
+ * http://groups.google.com/group/curb---ruby-libcurl-bindings
6
+ * http://github.com/taf2/curb/tree/master
5
7
 
6
8
  Curb (probably CUrl-RuBy or something) provides Ruby-language bindings for the
7
9
  libcurl(3), a fully-featured client-side URL transfer library.
data/ext/curb.h CHANGED
@@ -20,7 +20,7 @@
20
20
  #include "curb_macros.h"
21
21
 
22
22
  // These should be managed from the Rake 'release' task.
23
- #define CURB_VERSION "0.2.4.1"
23
+ #define CURB_VERSION "0.2.7.2"
24
24
  #define CURB_VER_NUM 224
25
25
  #define CURB_VER_MAJ 0
26
26
  #define CURB_VER_MIN 2
data/ext/curb_easy.c CHANGED
@@ -35,6 +35,23 @@ static size_t default_data_handler(char *stream,
35
35
  return size * nmemb;
36
36
  }
37
37
 
38
+ // size_t function( void *ptr, size_t size, size_t nmemb, void *stream);
39
+ static size_t read_data_handler(char *stream,
40
+ size_t size,
41
+ size_t nmemb,
42
+ char **buffer) {
43
+ size_t result = 0;
44
+
45
+ if (buffer != NULL && *buffer != NULL) {
46
+ int len = size * nmemb;
47
+ char *s1 = strncpy(stream, *buffer, len);
48
+ result = strlen(s1);
49
+ *buffer += result;
50
+ }
51
+
52
+ return result;
53
+ }
54
+
38
55
  static size_t proc_data_handler(char *stream,
39
56
  size_t size,
40
57
  size_t nmemb,
@@ -1575,9 +1592,12 @@ static VALUE ruby_curl_easy_perform_delete(VALUE self) {
1575
1592
  curl = rbce->curl;
1576
1593
 
1577
1594
  curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
1578
- // curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
1579
1595
 
1580
- return handle_perform(self,rbce);
1596
+ VALUE retval = handle_perform(self,rbce);
1597
+
1598
+ curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, NULL);
1599
+
1600
+ return retval;
1581
1601
  }
1582
1602
 
1583
1603
  /*
@@ -1679,10 +1699,17 @@ static VALUE ruby_curl_easy_perform_post(int argc, VALUE *argv, VALUE self) {
1679
1699
  * method always returns true, or raises an exception (defined under
1680
1700
  * Curl::Err) on error.
1681
1701
  *
1682
- * TODO Not yet implemented
1683
1702
  */
1684
- static VALUE ruby_curl_easy_perform_head(VALUE self) {
1685
- rb_raise(eCurlErrError, "Not yet implemented");
1703
+ static VALUE ruby_curl_easy_perform_head(VALUE self) {
1704
+ ruby_curl_easy *rbce;
1705
+ CURL *curl;
1706
+
1707
+ Data_Get_Struct(self, ruby_curl_easy, rbce);
1708
+ curl = rbce->curl;
1709
+
1710
+ curl_easy_setopt(curl, CURLOPT_NOBODY, 1);
1711
+
1712
+ return handle_perform(self,rbce);
1686
1713
  }
1687
1714
 
1688
1715
  /*
@@ -1692,11 +1719,25 @@ static VALUE ruby_curl_easy_perform_head(VALUE self) {
1692
1719
  * PUT the supplied data to the currently configured URL using the
1693
1720
  * current options set for this Curl::Easy instance. This method always
1694
1721
  * returns true, or raises an exception (defined under Curl::Err) on error.
1695
- *
1696
- * TODO Not yet implemented
1697
1722
  */
1698
- static VALUE ruby_curl_easy_perform_put(VALUE self) {
1699
- rb_raise(eCurlErrError, "Not yet implemented");
1723
+ static VALUE ruby_curl_easy_perform_put(VALUE self, VALUE data) {
1724
+ ruby_curl_easy *rbce;
1725
+ CURL *curl;
1726
+ char *buffer;
1727
+ int len;
1728
+
1729
+ Data_Get_Struct(self, ruby_curl_easy, rbce);
1730
+ curl = rbce->curl;
1731
+
1732
+ buffer = StringValuePtr(data);
1733
+ len = RSTRING_LEN(data);
1734
+
1735
+ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);
1736
+ curl_easy_setopt(curl, CURLOPT_READFUNCTION, (curl_read_callback)read_data_handler);
1737
+ curl_easy_setopt(curl, CURLOPT_READDATA, &buffer);
1738
+ curl_easy_setopt(curl, CURLOPT_INFILESIZE, len);
1739
+
1740
+ return handle_perform(self, rbce);
1700
1741
  }
1701
1742
 
1702
1743
  /* =================== DATA FUNCS =============== */
@@ -2385,6 +2426,29 @@ static VALUE ruby_curl_easy_class_perform_delete(int argc, VALUE *argv, VALUE kl
2385
2426
  return c;
2386
2427
  }
2387
2428
 
2429
+ /*
2430
+ * call-seq:
2431
+ * Curl::Easy.http_head(url) { |easy| ... } => #<Curl::Easy...>
2432
+ *
2433
+ * Convenience method that creates a new Curl::Easy instance with
2434
+ * the specified URL and calls +http_head+, before returning the new instance.
2435
+ *
2436
+ * If a block is supplied, the new instance will be yielded just prior to
2437
+ * the +http_head+ call.
2438
+ */
2439
+ static VALUE ruby_curl_easy_class_perform_head(int argc, VALUE *argv, VALUE klass) {
2440
+ VALUE c = ruby_curl_easy_new(argc, argv, klass);
2441
+
2442
+ if (rb_block_given_p()) {
2443
+ rb_yield(c);
2444
+ }
2445
+
2446
+ ruby_curl_easy_perform_head(c);
2447
+ return c;
2448
+ }
2449
+
2450
+ // TODO: add convenience method for http_post
2451
+
2388
2452
  /*
2389
2453
  * call-seq:
2390
2454
  * Curl::Easy.http_post(url, "some=urlencoded%20form%20data&and=so%20on") => true
@@ -2434,6 +2498,7 @@ void init_curb_easy() {
2434
2498
  rb_define_singleton_method(cCurlEasy, "http_delete", ruby_curl_easy_class_perform_delete, -1);
2435
2499
  rb_define_singleton_method(cCurlEasy, "http_get", ruby_curl_easy_class_perform_get, -1);
2436
2500
  rb_define_singleton_method(cCurlEasy, "http_post", ruby_curl_easy_class_perform_post, -1);
2501
+ rb_define_singleton_method(cCurlEasy, "http_head", ruby_curl_easy_class_perform_head, -1);
2437
2502
 
2438
2503
  /* Attributes for config next perform */
2439
2504
  rb_define_method(cCurlEasy, "url=", ruby_curl_easy_url_set, 1);
@@ -2514,7 +2579,7 @@ void init_curb_easy() {
2514
2579
  rb_define_method(cCurlEasy, "http_get", ruby_curl_easy_perform_get, 0);
2515
2580
  rb_define_method(cCurlEasy, "http_post", ruby_curl_easy_perform_post, -1);
2516
2581
  rb_define_method(cCurlEasy, "http_head", ruby_curl_easy_perform_head, 0);
2517
- rb_define_method(cCurlEasy, "http_put", ruby_curl_easy_perform_put, 0);
2582
+ rb_define_method(cCurlEasy, "http_put", ruby_curl_easy_perform_put, 1);
2518
2583
 
2519
2584
  /* Post-perform info methods */
2520
2585
  rb_define_method(cCurlEasy, "body_str", ruby_curl_easy_body_str_get, 0);
data/ext/extconf.rb CHANGED
@@ -71,8 +71,6 @@ have_constant "curle_tftp_unknownid"
71
71
  have_constant "curle_tftp_exists"
72
72
  have_constant "curle_tftp_nosuchuser"
73
73
 
74
- $INSTALLFILES = [["curb.rb", "$(RUBYLIBDIR)", "../ext"], ["curl.rb", "$(RUBYLIBDIR)", "../ext"]]
75
-
76
74
  if try_compile('int main() { return 0; }','-Wall')
77
75
  $CFLAGS << ' -Wall'
78
76
  end
data/tests/helper.rb CHANGED
@@ -60,12 +60,17 @@ class TestServlet < WEBrick::HTTPServlet::AbstractServlet
60
60
  respond_with(:GET,req,res)
61
61
  end
62
62
 
63
+ def do_HEAD(req,res)
64
+ res['Location'] = "/nonexistent"
65
+ respond_with(:HEAD, req, res)
66
+ end
67
+
63
68
  def do_POST(req,res)
64
69
  respond_with(:POST,req,res)
65
70
  end
66
71
 
67
72
  def do_PUT(req,res)
68
- respond_with(:PUT,req,res)
73
+ respond_with("PUT\n#{req.body}",req,res)
69
74
  end
70
75
 
71
76
  def do_DELETE(req,res)
@@ -110,7 +110,8 @@ class TestCurbCurlEasy < Test::Unit::TestCase
110
110
  assert_equal "", c.body_str
111
111
  assert_equal "", c.header_str
112
112
  end
113
-
113
+
114
+
114
115
  def test_last_effective_url_01
115
116
  c = Curl::Easy.new($TEST_URL)
116
117
 
@@ -478,13 +479,23 @@ class TestCurbCurlEasy < Test::Unit::TestCase
478
479
  curl.http_delete
479
480
  assert_equal 'DELETE', curl.body_str
480
481
  end
481
-
482
- # TODO: Curl::Err::CurlError: Not yet implemented
483
- # def test_put_remote
484
- # curl = Curl::Easy.new(TestServlet.url)
485
- # curl.http_put
486
- # assert_equal 'PUT', curl.body_str
487
- # end
482
+
483
+ def test_head_remote
484
+ curl = Curl::Easy.new(TestServlet.url)
485
+ curl.http_head
486
+
487
+ redirect = curl.header_str.match(/Location: (.*)/)
488
+
489
+ assert_equal '', curl.body_str
490
+ assert_match '/nonexistent', redirect[1]
491
+ end
492
+
493
+ def test_put_remote
494
+ curl = Curl::Easy.new(TestServlet.url)
495
+ assert curl.http_put("message")
496
+ assert_match /^PUT/, curl.body_str
497
+ assert_match /message$/, curl.body_str
498
+ end
488
499
 
489
500
  include TestServerMethods
490
501
 
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.2.4
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ross Bamford