brianmario-streamly 0.1.2 → 0.1.3

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/CHANGELOG.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.3 (August 19th, 2009)
4
+ * Fixed a bug where a username or password was specified, but not both
5
+
3
6
  ## 0.1.2 (July 28th, 2009)
4
- * Fixed a bug regarding user credentials being forcefully set to NULL even if they weren't being used.
7
+ * removing call to set CURLOPT_USERPWD to NULL as it would crash in linux
5
8
 
6
9
  ## 0.1.1 (July 27th, 2009)
7
10
  * Version bump for Github's gem builder
data/README.rdoc CHANGED
@@ -14,26 +14,76 @@ Install it like any other gem hosted at the Githubs like so:
14
14
 
15
15
  == Example of use
16
16
 
17
+ === A basic HEAD request
18
+
19
+ Streamly.head('www.somehost.com')
20
+
21
+ Or streaming
22
+
23
+ Streamly.head('www.somehost.com') do |header_chunk|
24
+ # do something with header_chunk
25
+ end
26
+
27
+ You can also pass a Hash of headers
28
+
29
+ Streamly.head('www.somehost.com', {"User-Agent" => "all your base are belong to us"})
30
+
17
31
  === A basic GET request
18
32
 
19
33
  Streamly.get('www.somehost.com')
20
34
 
21
- === A streaming GET request
35
+ Or streaming
22
36
 
23
- Streamly.get('www.somehost.com') do |chunk|
24
- # do something with _chunk_
37
+ Streamly.get('www.somehost.com') do |body_chunk|
38
+ # do something with body_chunk
25
39
  end
26
40
 
41
+ You can also pass a Hash of headers
42
+
43
+ Streamly.get('www.somehost.com', {"User-Agent" => "all your base are belong to us"})
44
+
27
45
  === A basic POST request
28
46
 
29
47
  Streamly.post('www.somehost.com', 'blah=foo')
30
48
 
31
- === A streaming POST request
49
+ Or streaming
32
50
 
33
- Streamly.post('www.somehost.com', 'blah=foo') do |chunk|
34
- # do something with _chunk_
51
+ Streamly.post('www.somehost.com', 'blah=foo') do |body_chunk|
52
+ # do something with body_chunk
35
53
  end
36
54
 
55
+ You can also pass a Hash of headers
56
+
57
+ Streamly.post('www.somehost.com', 'blah=foo', {"User-Agent" => "all your base are belong to us"})
58
+
59
+ === A basic PUT request
60
+
61
+ Streamly.put('www.somehost.com', 'blah=foo')
62
+
63
+ Or streaming
64
+
65
+ Streamly.put('www.somehost.com', 'blah=foo') do |body_chunk|
66
+ # do something with body_chunk
67
+ end
68
+
69
+ You can also pass a Hash of headers
70
+
71
+ Streamly.put('www.somehost.com', 'blah=foo', {"User-Agent" => "all your base are belong to us"})
72
+
73
+ === A basic DELETE request
74
+
75
+ Streamly.delete('www.somehost.com')
76
+
77
+ Or streaming
78
+
79
+ Streamly.delete('www.somehost.com') do |body_chunk|
80
+ # do something with body_chunk
81
+ end
82
+
83
+ You can also pass a Hash of headers
84
+
85
+ Streamly.delete('www.somehost.com', {"User-Agent" => "all your base are belong to us"})
86
+
37
87
  == Benchmarks
38
88
 
39
89
  Fetching 2,405,005 bytes of JSON from a local lighttpd server
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 1
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 0
@@ -10,17 +10,17 @@ require 'benchmark'
10
10
  url = ARGV[0]
11
11
 
12
12
  Benchmark.bm do |x|
13
- puts "Shell out to curl"
13
+ puts "Streamly"
14
14
  x.report do
15
15
  (ARGV[1] || 1).to_i.times do
16
- `curl -s --compressed #{url}`
16
+ Streamly.get(url)
17
17
  end
18
18
  end
19
19
 
20
- puts "Streamly"
20
+ puts "Shell out to curl"
21
21
  x.report do
22
22
  (ARGV[1] || 1).to_i.times do
23
- Streamly.get(url)
23
+ `curl -s --compressed #{url}`
24
24
  end
25
25
  end
26
26
 
@@ -11,27 +11,29 @@ require 'benchmark'
11
11
  url = ARGV[0]
12
12
 
13
13
  Benchmark.bm do |x|
14
- puts "Shell out to curl"
14
+ puts "Streamly"
15
15
  parser = Yajl::Parser.new
16
+ parser.on_parse_complete = lambda {|obj| }
16
17
  x.report do
17
18
  (ARGV[1] || 1).to_i.times do
18
- parser.parse `curl -s --compressed #{url}`
19
+ Streamly.get(url) do |chunk|
20
+ parser << chunk
21
+ end
19
22
  end
20
23
  end
21
24
 
22
- puts "Streamly"
25
+ puts "Shell out to curl"
23
26
  parser = Yajl::Parser.new
24
27
  parser.on_parse_complete = lambda {|obj| }
25
28
  x.report do
26
29
  (ARGV[1] || 1).to_i.times do
27
- Streamly.get(url) do |chunk|
28
- parser << chunk
29
- end
30
+ parser.parse `curl -s --compressed #{url}`
30
31
  end
31
32
  end
32
33
 
33
34
  puts "rest-client"
34
35
  parser = Yajl::Parser.new
36
+ parser.on_parse_complete = lambda {|obj| }
35
37
  x.report do
36
38
  (ARGV[1] || 1).to_i.times do
37
39
  parser.parse RestClient.get(url, {"Accept-Encoding" => "identity, deflate, gzip"})
data/ext/streamly.c CHANGED
@@ -1,4 +1,4 @@
1
- // static size_t put_data_handler(char * stream, size_t size, size_t nmemb, VALUE upload_stream) {
1
+ // static size_t upload_data_handler(char * stream, size_t size, size_t nmemb, VALUE upload_stream) {
2
2
  // size_t result = 0;
3
3
  //
4
4
  // // TODO
@@ -62,17 +62,13 @@ void streamly_instance_free(struct curl_instance * instance) {
62
62
  static VALUE each_http_header(VALUE header, VALUE self) {
63
63
  struct curl_instance * instance;
64
64
  GetInstance(self, instance);
65
- VALUE name, value, header_str = Qnil;
66
-
67
- name = rb_obj_as_string(rb_ary_entry(header, 0));
68
- value = rb_obj_as_string(rb_ary_entry(header, 1));
69
-
70
- header_str = rb_str_plus(name, rb_str_new2(": "));
71
- header_str = rb_str_plus(header_str, value);
65
+ VALUE header_str = rb_str_new2("");
66
+
67
+ rb_str_buf_cat(header_str, RSTRING_PTR(rb_ary_entry(header, 0)), RSTRING_LEN(rb_ary_entry(header, 0)));
68
+ rb_str_buf_cat(header_str, ": ", 2);
69
+ rb_str_buf_cat(header_str, RSTRING_PTR(rb_ary_entry(header, 1)), RSTRING_LEN(rb_ary_entry(header, 1)));
72
70
 
73
71
  instance->request_headers = curl_slist_append(instance->request_headers, RSTRING_PTR(header_str));
74
- rb_gc_mark(name);
75
- rb_gc_mark(value);
76
72
  rb_gc_mark(header_str);
77
73
  return Qnil;
78
74
  }
@@ -230,7 +226,7 @@ VALUE rb_streamly_init(int argc, VALUE * argv, VALUE self) {
230
226
  // curl_easy_setopt(instance->handle, CURLOPT_HTTPPOST, 1);
231
227
 
232
228
  // TODO: get streaming upload working
233
- // curl_easy_setopt(instance->handle, CURLOPT_READFUNCTION, &put_data_handler);
229
+ // curl_easy_setopt(instance->handle, CURLOPT_READFUNCTION, &upload_data_handler);
234
230
  // curl_easy_setopt(instance->handle, CURLOPT_READDATA, &instance->upload_stream);
235
231
  // curl_easy_setopt(instance->handle, CURLOPT_INFILESIZE, len);
236
232
  } else if (instance->request_method == sym_put) {
@@ -240,7 +236,7 @@ VALUE rb_streamly_init(int argc, VALUE * argv, VALUE self) {
240
236
 
241
237
  // TODO: get streaming upload working
242
238
  // curl_easy_setopt(instance->handle, CURLOPT_UPLOAD, 1);
243
- // curl_easy_setopt(instance->handle, CURLOPT_READFUNCTION, &put_data_handler);
239
+ // curl_easy_setopt(instance->handle, CURLOPT_READFUNCTION, &upload_data_handler);
244
240
  // curl_easy_setopt(instance->handle, CURLOPT_READDATA, &instance->upload_stream);
245
241
  // curl_easy_setopt(instance->handle, CURLOPT_INFILESIZE, len);
246
242
  } else if (instance->request_method == sym_delete) {
@@ -263,12 +259,16 @@ VALUE rb_streamly_init(int argc, VALUE * argv, VALUE self) {
263
259
  curl_easy_setopt(instance->handle, CURLOPT_WRITEDATA, instance->response_body_handler);
264
260
  }
265
261
 
266
- // curl_easy_setopt(instance, CURLOPT_USERPWD, NULL);
262
+ curl_easy_setopt(instance, CURLOPT_USERPWD, NULL);
267
263
  if (!NIL_P(username) || !NIL_P(password)) {
268
264
  credentials = rb_str_new2("");
269
- rb_str_buf_cat(credentials, RSTRING_PTR(username), RSTRING_LEN(username));
265
+ if (!NIL_P(username)) {
266
+ rb_str_buf_cat(credentials, RSTRING_PTR(username), RSTRING_LEN(username));
267
+ }
270
268
  rb_str_buf_cat(credentials, credential_sep, 1);
271
- rb_str_buf_cat(credentials, RSTRING_PTR(password), RSTRING_LEN(password));
269
+ if (!NIL_P(password)) {
270
+ rb_str_buf_cat(credentials, RSTRING_PTR(password), RSTRING_LEN(password));
271
+ }
272
272
  curl_easy_setopt(instance->handle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST);
273
273
  curl_easy_setopt(instance->handle, CURLOPT_USERPWD, RSTRING_PTR(credentials));
274
274
  rb_gc_mark(credentials);
data/lib/streamly.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'streamly_ext'
3
3
 
4
4
  module Streamly
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
6
6
 
7
7
  class Request
8
8
  # A helper method to make your fire-and-forget requests easier
data/streamly.gemspec CHANGED
@@ -1,12 +1,15 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
1
4
  # -*- encoding: utf-8 -*-
2
5
 
3
6
  Gem::Specification.new do |s|
4
7
  s.name = %q{streamly}
5
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
6
9
 
7
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
11
  s.authors = ["Brian Lopez"]
9
- s.date = %q{2009-07-28}
12
+ s.date = %q{2009-08-19}
10
13
  s.email = %q{seniorlopez@gmail.com}
11
14
  s.extensions = ["ext/extconf.rb"]
12
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brianmario-streamly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lopez
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-28 00:00:00 -07:00
12
+ date: 2009-08-19 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15