Permalink
Browse files

Merge pull request #1 from mathieuravaux/master

Twitter gem conflicts
  • Loading branch information...
jeremyvdw committed May 23, 2011
2 parents 10ee3a0 + 6bc44a5 commit c03de1d9a604125c61f25930f49a89dee75b433e
@@ -1,6 +1,6 @@
require 'faraday_middleware'
-require 'faraday/response/raise_http_4xx'
-require 'faraday/response/raise_http_5xx'
+require 'faraday/disqussion/raise_http_4xx'
+require 'faraday/disqussion/raise_http_5xx'
module Disqussion
# @private
@@ -18,7 +18,7 @@ def connection(raw=false)
Faraday.new(options) do |builder|
builder.use Faraday::Request::Multipart
builder.use Faraday::Request::UrlEncoded
- builder.use Faraday::Response::RaiseHttp4xx
+ builder.use Faraday::Disqussion::RaiseHttp4xx
builder.use Faraday::Response::Rashify unless raw
unless raw
case format.to_s.downcase
@@ -28,7 +28,7 @@ def connection(raw=false)
builder.use Faraday::Response::ParseXml
end
end
- builder.use Faraday::Response::RaiseHttp5xx
+ builder.use Faraday::Disqussion::RaiseHttp5xx
builder.adapter(adapter)
end
end
@@ -0,0 +1,37 @@
+require 'faraday'
+
+# @private
+module Faraday
+ module Disqussion
+ # @private
+ class RaiseHttp4xx < ::Faraday::Response::Middleware
+ def on_complete(env)
+ case env[:status].to_i
+ when 400
+ raise ::Disqussion::BadRequest.new(error_message(env), env[:response_headers])
+ when 401
+ raise ::Disqussion::Unauthorized.new(error_message(env), env[:response_headers])
+ when 403
+ raise ::Disqussion::Forbidden.new(error_message(env), env[:response_headers])
+ when 404
+ raise ::Disqussion::NotFound.new(error_message(env), env[:response_headers])
+ end
+ end
+
+ private
+
+ def error_message(env)
+ "#{env[:method].to_s.upcase} #{env[:url].to_s}: (#{env[:status]}) #{error_body(env[:body])}"
+ end
+
+ def error_body(body)
+ if body['code'] && body['response']
+ "Disqus Error #{body['code']}: #{body['response']}"
+ else
+ nil
+ end
+ end
+ end
+ end
+
+end
@@ -0,0 +1,23 @@
+require 'faraday'
+
+# @private
+module Faraday
+ module Disqussion
+ # @private
+ class RaiseHttp5xx < ::Faraday::Response::Middleware
+ def on_complete(env)
+ case env[:status].to_i
+ when 500
+ raise ::Disqussion::InternalServerError.new(error_message(env, "Something is technically wrong."), env[:response_headers])
+ end
+ end
+
+ private
+
+ def error_message(env, body=nil)
+ "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')} Check http://status.disqus.com/ for updates on the status of the Disqus service."
+ end
+
+ end
+ end
+end
@@ -1,34 +0,0 @@
-require 'faraday'
-
-# @private
-module Faraday
- # @private
- class Response::RaiseHttp4xx < Response::Middleware
- def on_complete(env)
- case env[:status].to_i
- when 400
- raise Disqussion::BadRequest.new(error_message(env), env[:response_headers])
- when 401
- raise Disqussion::Unauthorized.new(error_message(env), env[:response_headers])
- when 403
- raise Disqussion::Forbidden.new(error_message(env), env[:response_headers])
- when 404
- raise Disqussion::NotFound.new(error_message(env), env[:response_headers])
- end
- end
-
- private
-
- def error_message(env)
- "#{env[:method].to_s.upcase} #{env[:url].to_s}: (#{env[:status]}) #{error_body(env[:body])}"
- end
-
- def error_body(body)
- if body['code'] && body['response']
- "Disqus Error #{body['code']}: #{body['response']}"
- else
- nil
- end
- end
- end
-end
@@ -1,20 +0,0 @@
-require 'faraday'
-
-# @private
-module Faraday
- # @private
- class Response::RaiseHttp5xx < Response::Middleware
- def on_complete(env)
- case env[:status].to_i
- when 500
- raise Disqussion::InternalServerError.new(error_message(env, "Something is technically wrong."), env[:response_headers])
- end
- end
-
- private
-
- def error_message(env, body=nil)
- "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')} Check http://status.disqus.com/ for updates on the status of the Disqus service."
- end
- end
-end

0 comments on commit c03de1d

Please sign in to comment.