class Her::Middleware::SecondLevelParseJSON

This middleware expects the resource/collection data to be contained in the ‘data` key of the JSON object

Public Instance Methods

on_complete(env) click to toggle source

This method is triggered when the response has been received. It modifies the value of ‘env`.

@param [Hash] env The response environment

# File lib/her/middleware/second_level_parse_json.rb, line 23
def on_complete(env)
  env[:body] = parse(env[:body])
end
parse(body) click to toggle source

Parse the response body

@param [String] body The response body @return [Mixed] the parsed response

# File lib/her/middleware/second_level_parse_json.rb, line 10
def parse(body)
  json = MultiJson.load(body, :symbolize_keys => true)
  {
    :data => json[:data],
    :errors => json[:errors],
    :metadata => json[:metadata]
  }
end