class SparkApi::Authentication::OAuth2Impl::SparkbarFaradayMiddleware
OAuth2
Faraday response middleware¶ ↑
HTTP Response after filter to package oauth2 responses and bubble up basic api errors.
Public Class Methods
new(app)
click to toggle source
Calls superclass method
# File lib/spark_api/authentication/oauth2_impl/faraday_middleware.rb, line 43 def initialize(app) super(app) end
Public Instance Methods
on_complete(env)
click to toggle source
# File lib/spark_api/authentication/oauth2_impl/faraday_middleware.rb, line 47 def on_complete(env) body = MultiJson.decode(env[:body]) SparkApi.logger.debug{ "[sparkbar] Response Body: #{body.inspect}" } unless body.is_a?(Hash) raise InvalidResponse, "The server response could not be understood" end case env[:status] when 200..299 SparkApi.logger.debug{ "[sparkbar] Success!" } if body.include?("token") env[:body] = body return end end raise ClientError, {:message => "Unable to process sparkbar token #{body.inspect}", :code =>0, :status => env[:status], :request_path => env[:url]} end