Permalink
Browse files

add capabilities to use xml parse when the content type is not just *…

…/xml like atom application/atom+xml
  • Loading branch information...
1 parent 11d0ade commit bdb50955eba9aff54b1a9e6dc563e501a462ae71 @shingara shingara committed with sferik Nov 8, 2010
Showing with 14 additions and 1 deletion.
  1. +1 −1 lib/faraday/parse.rb
  2. +13 −0 test/parse_test.rb
View
2 lib/faraday/parse.rb
@@ -13,7 +13,7 @@ def self.register_on_complete(env)
case response[:response_headers].values_at('content-type', 'Content-Type').first
when /\/json/
parse_json(response[:body])
- when /\/xml/
+ when /\/.*xml/
parse_xml(response[:body])
else
''
View
13 test/parse_test.rb
@@ -85,6 +85,19 @@ class ParseTest < Test::Unit::TestCase
end
end
+ context "when there is a ATOM body" do
+ setup do
+ @stubs.get('/me') {[200, {'content-type' => 'application/atom+xml; charset=utf-8'}, '<user><name>Erik Michaels-Ober</name><username>sferik</username></user>']}
+ end
+
+ should 'parse the body as XML' do
+ me = @conn.get("/me").body['user']
+ assert me.is_a?(Hash)
+ assert_equal 'Erik Michaels-Ober', me['name']
+ assert_equal 'sferik', me['username']
+ end
+ end
+
context "when the XML body is empty" do
setup do
@stubs.get('/me') {[200, {'content-type' => 'application/xml; charset=utf-8'}, ""]}

0 comments on commit bdb5095

Please sign in to comment.