Sha256: 17ef29da6f31d0d1c16a8baecc8648bb3fa77d25dfdcf15ee0e63e30567006c9
Contents?: true
Size: 858 Bytes
Versions: 11
Compression:
Stored size: 858 Bytes
Contents
module Her module Middleware # This middleware expects the resource/collection data to be contained in the `data` # key of the JSON object class SecondLevelParseJSON < Faraday::Response::Middleware # Parse the response body # # @param [String] body The response body # @return [Mixed] the parsed response def parse(body) # {{{ json = MultiJson.load(body, :symbolize_keys => true) { :data => json[:data], :errors => json[:errors], :metadata => json[:metadata] } end # }}} # This method is triggered when the response has been received. It modifies # the value of `env[:body]`. # # @param [Hash] env The response environment def on_complete(env) # {{{ env[:body] = parse(env[:body]) end # }}} end end end
Version data entries
11 entries across 11 versions & 1 rubygems