yajl-ruby 0.6.8 → 0.6.9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yajl-ruby might be problematic. Click here for more details.

data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.9 (January 26th, 2010)
4
+ * HttpStream patches merged in from Luke Redpath <contact@lukeredpath.co.uk>
5
+ * Changed how Yajl::Parser was calling IO#read to better conform to the Rack spec and thus can be used to directly parse a rack.input stream
6
+
3
7
  ## 0.6.8 (January 1st, 2010)
4
8
  * A couple of small performance patches
5
9
  * Allow passing a string to Yajl::HttpStream methods instead of only a URI
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008-2009 Brian Lopez - http://github.com/brianmario
1
+ Copyright (c) 2008-2010 Brian Lopez - http://github.com/brianmario
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ begin
15
15
  gem.rubyforge_project = "yajl-ruby"
16
16
  end
17
17
  rescue LoadError
18
- puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler -s http://gems.github.com"
19
19
  end
20
20
 
21
21
  require 'rake'
data/VERSION.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
- :patch: 8
2
+ :patch: 9
3
3
  :major: 0
4
4
  :minor: 6
5
+ :build:
data/ext/yajl_ext.c CHANGED
@@ -441,7 +441,7 @@ static VALUE rb_yajl_parser_parse(int argc, VALUE * argv, VALUE self) {
441
441
  } else if (rb_respond_to(input, intern_eof)) {
442
442
  VALUE parsed = rb_str_new2("");
443
443
  while (rb_funcall(input, intern_eof, 0) != Qtrue) {
444
- rb_funcall(input, intern_io_read, 2, rbufsize, parsed);
444
+ parsed = rb_funcall(input, intern_io_read, 1, rbufsize);
445
445
  cptr = RSTRING_PTR(parsed);
446
446
  yajl_parse_chunk((const unsigned char*)cptr, (unsigned int)strlen(cptr), wrapper->parser);
447
447
  }
data/lib/yajl.rb CHANGED
@@ -13,7 +13,7 @@ require 'yajl_ext'
13
13
  #
14
14
  # Ruby bindings to the excellent Yajl (Yet Another JSON Parser) ANSI C library.
15
15
  module Yajl
16
- VERSION = "0.6.8"
16
+ VERSION = "0.6.9"
17
17
 
18
18
  # For compatibility, has the same signature of Yajl::Parser.parse
19
19
  def self.load(str_or_io, options={}, read_bufsize=nil, &block)
@@ -11,6 +11,15 @@ module Yajl
11
11
  # This Exception is thrown when an HTTP response isn't in ALLOWED_MIME_TYPES
12
12
  # and therefore cannot be parsed.
13
13
  class InvalidContentType < Exception; end
14
+ class HttpError < StandardError
15
+
16
+ attr_reader :message, :headers
17
+
18
+ def initialize(message, headers)
19
+ @message = message
20
+ @headers = headers
21
+ end
22
+ end
14
23
 
15
24
  # The mime-type we expect the response to be. If it's anything else, we can't parse it
16
25
  # and an InvalidContentType is raised.
@@ -90,7 +99,7 @@ module Yajl
90
99
  end
91
100
 
92
101
  socket = opts.has_key?(:socket) ? opts.delete(:socket) : TCPSocket.new(uri.host, uri.port)
93
- trap("INT") {
102
+ original_trap = trap("INT") {
94
103
  return
95
104
  }
96
105
  request = "#{method} #{uri.path}#{uri.query ? "?"+uri.query : nil} HTTP/1.1\r\n"
@@ -131,6 +140,11 @@ module Yajl
131
140
  end
132
141
  end
133
142
  end
143
+
144
+ if (response_head[:code] != 200)
145
+ raise HttpError.new("Code 200 expected got #{response_head[:code]}", response_head[:headers])
146
+ end
147
+
134
148
  parser = Yajl::Parser.new(opts)
135
149
  parser.on_parse_complete = block if block_given?
136
150
  if response_head[:headers]["Transfer-Encoding"] == 'chunked'
@@ -169,6 +183,7 @@ module Yajl
169
183
  end
170
184
  end
171
185
  ensure
186
+ trap("INT", original_trap) if original_trap
172
187
  socket.close if !socket.nil? and !socket.closed?
173
188
  end
174
189
 
@@ -0,0 +1,12 @@
1
+ HTTP/1.1 404 NOT FOUND
2
+ Vary: Accept-Encoding
3
+ Content-Type: text/html
4
+ Accept-Ranges: bytes
5
+ ETag: "-1274243775"
6
+ Last-Modified: Thu, 30 Apr 2009 04:36:11 GMT
7
+ Content-Length: 32444
8
+ Date: Wed, 24 Jun 2009 06:02:18 GMT
9
+ Server: lighttpd/1.4.22
10
+ Transfer-Encoding: chunked
11
+
12
+ <html>THIS PAGE COULD NOT BE FOUND!</html>
@@ -1,4 +1,4 @@
1
- HTTP/1.1 406 Not Acceptable
1
+ HTTP/1.1 200 Not Acceptable
2
2
  Content-Type: text/html; charset=iso-8859-1
3
3
  Server: Jetty(6.1.17)
4
4
 
@@ -91,4 +91,9 @@ describe "Yajl HTTP DELETE request" do
91
91
  prepare_mock_request_dump :gzip
92
92
  @template_hash_symbolized.should == Yajl::HttpStream.delete(@uri, :symbolize_keys => true)
93
93
  end
94
+
95
+ it "should raise when an HTTP code that isn't 200 is returned" do
96
+ prepare_mock_request_dump :error
97
+ lambda { Yajl::HttpStream.delete(@uri) }.should raise_exception(Yajl::HttpStream::HttpError)
98
+ end
94
99
  end
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
3
+ begin
4
+ require 'yajl/bzip2'
5
+ rescue
6
+ warn "Couldn't load yajl/bzip2, maybe you don't have bzip2-ruby installed? Continuing without running bzip2 specs."
7
+ end
8
+ require 'yajl/gzip'
9
+ require 'yajl/deflate'
10
+ require 'yajl/http_stream'
11
+
12
+ describe "Yajl HTTP error" do
13
+ before(:all) do
14
+ @request = File.new(File.expand_path(File.dirname(__FILE__) + "/fixtures/http.error.dump"), 'r')
15
+ @uri = 'file://'+File.expand_path(File.dirname(__FILE__) + "/fixtures/http/http.error.dump")
16
+ TCPSocket.should_receive(:new).and_return(@request)
17
+ @request.should_receive(:write)
18
+
19
+ begin
20
+ Yajl::HttpStream.get(@uri)
21
+ rescue Yajl::HttpStream::HttpError => e
22
+ @error = e
23
+ end
24
+ end
25
+
26
+ it "should contain the error code in the message" do
27
+ @error.message.should match(/404/)
28
+ end
29
+
30
+ it "should provide the HTTP response headers" do
31
+ @error.headers.keys.should include('ETag', 'Content-Length', 'Server')
32
+ end
33
+ end
@@ -102,4 +102,9 @@ describe "Yajl HTTP GET request" do
102
102
  prepare_mock_request_dump :gzip
103
103
  @template_hash_symbolized.should == Yajl::HttpStream.get(@uri, :symbolize_keys => true)
104
104
  end
105
- end
105
+
106
+ it "should raise when an HTTP code that isn't 200 is returned" do
107
+ prepare_mock_request_dump :error
108
+ lambda { Yajl::HttpStream.get(@uri) }.should raise_exception(Yajl::HttpStream::HttpError)
109
+ end
110
+ end
@@ -116,4 +116,9 @@ describe "Yajl HTTP POST request" do
116
116
  prepare_mock_request_dump :html
117
117
  lambda {Yajl::HttpStream.post(@uri, @body)}.should raise_error(Yajl::HttpStream::InvalidContentType)
118
118
  end
119
+
120
+ it "should raise when an HTTP code that isn't 200 is returned" do
121
+ prepare_mock_request_dump :error
122
+ lambda { Yajl::HttpStream.post(@uri, @body) }.should raise_exception(Yajl::HttpStream::HttpError)
123
+ end
119
124
  end
@@ -98,4 +98,9 @@ describe "Yajl HTTP PUT request" do
98
98
  prepare_mock_request_dump :gzip
99
99
  @template_hash_symbolized.should == Yajl::HttpStream.put(@uri, @body, :symbolize_keys => true)
100
100
  end
101
+
102
+ it "should raise when an HTTP code that isn't 200 is returned" do
103
+ prepare_mock_request_dump :error
104
+ lambda { Yajl::HttpStream.put(@uri, @body) }.should raise_exception(Yajl::HttpStream::HttpError)
105
+ end
101
106
  end
data/spec/spec_helper.rb CHANGED
@@ -3,4 +3,4 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
3
3
 
4
4
  require 'rubygems'
5
5
  require 'yajl'
6
- require 'active_support/core_ext/kernel/reporting'
6
+ require 'active_support/core_ext/kernel/reporting'
data/yajl-ruby.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{yajl-ruby}
8
- s.version = "0.6.8"
8
+ s.version = "0.6.9"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brian Lopez", "Lloyd Hilaiel"]
12
- s.date = %q{2010-01-01}
12
+ s.date = %q{2010-01-26}
13
13
  s.email = %q{seniorlopez@gmail.com}
14
14
  s.extensions = ["ext/extconf.rb"]
15
15
  s.extra_rdoc_files = [
@@ -83,10 +83,12 @@ Gem::Specification.new do |s|
83
83
  "spec/http/fixtures/http.bzip2.dump",
84
84
  "spec/http/fixtures/http.chunked.dump",
85
85
  "spec/http/fixtures/http.deflate.dump",
86
+ "spec/http/fixtures/http.error.dump",
86
87
  "spec/http/fixtures/http.gzip.dump",
87
88
  "spec/http/fixtures/http.html.dump",
88
89
  "spec/http/fixtures/http.raw.dump",
89
90
  "spec/http/http_delete_spec.rb",
91
+ "spec/http/http_error_spec.rb",
90
92
  "spec/http/http_get_spec.rb",
91
93
  "spec/http/http_post_spec.rb",
92
94
  "spec/http/http_put_spec.rb",
@@ -167,6 +169,7 @@ Gem::Specification.new do |s|
167
169
  "spec/encoding/encoding_spec.rb",
168
170
  "spec/global/global_spec.rb",
169
171
  "spec/http/http_delete_spec.rb",
172
+ "spec/http/http_error_spec.rb",
170
173
  "spec/http/http_get_spec.rb",
171
174
  "spec/http/http_post_spec.rb",
172
175
  "spec/http/http_put_spec.rb",
@@ -196,3 +199,4 @@ Gem::Specification.new do |s|
196
199
  else
197
200
  end
198
201
  end
202
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yajl-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Lopez
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-01 00:00:00 -08:00
13
+ date: 2010-01-26 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -90,10 +90,12 @@ files:
90
90
  - spec/http/fixtures/http.bzip2.dump
91
91
  - spec/http/fixtures/http.chunked.dump
92
92
  - spec/http/fixtures/http.deflate.dump
93
+ - spec/http/fixtures/http.error.dump
93
94
  - spec/http/fixtures/http.gzip.dump
94
95
  - spec/http/fixtures/http.html.dump
95
96
  - spec/http/fixtures/http.raw.dump
96
97
  - spec/http/http_delete_spec.rb
98
+ - spec/http/http_error_spec.rb
97
99
  - spec/http/http_get_spec.rb
98
100
  - spec/http/http_post_spec.rb
99
101
  - spec/http/http_put_spec.rb
@@ -196,6 +198,7 @@ test_files:
196
198
  - spec/encoding/encoding_spec.rb
197
199
  - spec/global/global_spec.rb
198
200
  - spec/http/http_delete_spec.rb
201
+ - spec/http/http_error_spec.rb
199
202
  - spec/http/http_get_spec.rb
200
203
  - spec/http/http_post_spec.rb
201
204
  - spec/http/http_put_spec.rb