Skip to content

Commit

Permalink
Use MultiXML and MultiJSON for parsing instead of Crack
Browse files Browse the repository at this point in the history
  • Loading branch information
Brennan Frydl committed Jul 7, 2011
1 parent 2d2856b commit 05cacfe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions httparty.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Gem::Specification.new do |s|
s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}

s.add_dependency 'crack', HTTParty::CRACK_DEPENDENCY
s.add_dependency 'multi_json'
s.add_dependency 'multi_xml'

s.add_development_dependency "activesupport", "~> 2.3"
s.add_development_dependency "cucumber", "~> 0.7"
Expand Down
2 changes: 2 additions & 0 deletions lib/httparty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require 'uri'
require 'zlib'
require 'crack'
require 'multi_xml'
require 'multi_json'

require 'httparty/module_inheritable_attributes'
require 'httparty/cookie_hash'
Expand Down
4 changes: 2 additions & 2 deletions lib/httparty/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ def parse
protected

def xml
Crack::XML.parse(body)
MultiXml.parse(body)
end

def json
Crack::JSON.parse(body)
MultiJson.decode(body)
end

def yaml
Expand Down
8 changes: 4 additions & 4 deletions spec/httparty/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ def self.name; 'AtomParser'; end
HTTParty::Parser.new('body', nil)
end

it "parses xml with Crack" do
Crack::XML.should_receive(:parse).with('body')
it "parses xml with MultiXml" do
MultiXml.should_receive(:parse).with('body')
subject.send(:xml)
end

it "parses json with Crack" do
Crack::JSON.should_receive(:parse).with('body')
it "parses json with MultiJson" do
MultiJson.should_receive(:decode).with('body')
subject.send(:json)
end

Expand Down

0 comments on commit 05cacfe

Please sign in to comment.