Class: Tumbz::Middleware::Parse
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- Tumbz::Middleware::Parse
- Defined in:
- lib/tumbz/middleware/parse.rb
Instance Method Summary collapse
-
#on_complete(env) ⇒ Object
This method is triggered when the response has been received.
-
#parse(body) ⇒ Mixed
Parse the response body.
Instance Method Details
#on_complete(env) ⇒ Object
This method is triggered when the response has been received. It modifies the value of ‘env`.
30 31 32 |
# File 'lib/tumbz/middleware/parse.rb', line 30 def on_complete(env) env[:body] = parse(env[:body]) end |
#parse(body) ⇒ Mixed
Parse the response body
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/tumbz/middleware/parse.rb', line 8 def parse(body) json = MultiJson.load(body, :symbolize_keys => true) errors = [] = json.delete(:metadata) || [] if json.is_a?(Hash) and json[:error].present? json.delete(:error) json.delete(:message) errors = [json.delete(:developerMessage)] end { :data => json, :errors => errors, :metadata => } end |