Class: Redd::Response::ParseJson
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Redd::Response::ParseJson
- Defined in:
- lib/redd/response/parse_json.rb
Overview
Faraday Middleware that parses JSON using Oj.
Instance Method Summary collapse
-
#call(faraday) ⇒ Object
Call the middleware.
-
#parse(body) ⇒ Hash
private
Parse a JSON string and return a symbolized hash.
Instance Method Details
#call(faraday) ⇒ Object
Call the middleware.
12 13 14 15 16 |
# File 'lib/redd/response/parse_json.rb', line 12 def call(faraday) @app.call(faraday).on_complete do |env| env[:body] = parse(env[:body]) end end |
#parse(body) ⇒ Hash (private)
Parse a JSON string and return a symbolized hash.
24 25 26 27 28 |
# File 'lib/redd/response/parse_json.rb', line 24 def parse(body) MultiJson.load(body, symbolize_keys: true) rescue MultiJson::ParseError body end |