Class: SparkApi::Authentication::OAuth2Impl::SparkbarFaradayMiddleware
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- SparkApi::Authentication::OAuth2Impl::SparkbarFaradayMiddleware
- Defined in:
- lib/spark_api/authentication/oauth2_impl/faraday_middleware.rb
Overview
OAuth2 Faraday response middleware
HTTP Response after filter to package oauth2 responses and bubble up basic api errors.
Instance Method Summary collapse
-
#initialize(app) ⇒ SparkbarFaradayMiddleware
constructor
A new instance of SparkbarFaradayMiddleware.
- #on_complete(env) ⇒ Object
Constructor Details
#initialize(app) ⇒ SparkbarFaradayMiddleware
Returns a new instance of SparkbarFaradayMiddleware.
47 48 49 |
# File 'lib/spark_api/authentication/oauth2_impl/faraday_middleware.rb', line 47 def initialize(app) super(app) end |
Instance Method Details
#on_complete(env) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/spark_api/authentication/oauth2_impl/faraday_middleware.rb', line 51 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 |