Skip to content
Browse files

add ResponseHTML middleware

  • Loading branch information...
1 parent 14d1dd3 commit 58b7e121f2c264d983040aad567c758a0248d974 @mislav committed Mar 27, 2011
Showing with 16 additions and 2 deletions.
  1. +4 −2 lib/faraday_stack.rb
  2. +12 −0 lib/faraday_stack/response_html.rb
View
6 lib/faraday_stack.rb
@@ -8,7 +8,8 @@ module FaradayStack
autoload_all 'faraday_stack',
:ResponseMiddleware => 'response_middleware',
:ResponseJSON => 'response_json',
- :ResponseXML => 'response_xml'
+ :ResponseXML => 'response_xml',
+ :ResponseHTML => 'response_html'
# THE ÜBER STACK
def self.default_connection
@@ -27,7 +28,8 @@ def self.build(url = nil, options = {})
builder.request :json
yield builder if block_given?
builder.use ResponseJSON, :content_type => 'application/json'
- builder.use ResponseXML, :content_type => /[+\/]xml$/
+ builder.use ResponseXML, :content_type => /[+\/]xml$/
+ builder.use ResponseHTML, :content_type => 'text/html'
builder.response :raise_error
builder.adapter Faraday.default_adapter
end
View
12 lib/faraday_stack/response_html.rb
@@ -0,0 +1,12 @@
+module FaradayStack
+ class ResponseHTML < ResponseMiddleware
+ dependency do
+ require 'nokogiri'
+ Nokogiri::HTML
+ end
+
+ define_parser do |body|
+ Nokogiri::HTML body
+ end
+ end
+end

0 comments on commit 58b7e12

Please sign in to comment.
Something went wrong with that request. Please try again.