class DeskApi::Response::ParseJson

The {DeskApi::Response::ParseJson} middleware parses the json response body

@author Thomas Stachl <tstachl@salesforce.com> @copyright Copyright © 2013-2016 Salesforce.com @license BSD 3-Clause License

Public Instance Methods

on_complete(env) click to toggle source

Parses the response only if the content type is set and includes application/json

# File lib/desk_api/response/parse_json.rb, line 42
def on_complete(env)
  content_type = env[:response_headers]['content-type']
  if content_type && content_type.include?('application/json') \
    && !env[:body].strip.empty?
    env[:body] = ::JSON.parse(env[:body])
  end
end