class JsonApiClient::Middleware::ParseJson
Public Instance Methods
call(environment)
click to toggle source
# File lib/json_api_client/middleware/parse_json.rb, line 5 def call(environment) @app.call(environment).on_complete do |env| if process_response_type?(response_type(env)) env[:raw_body] = env[:body] env[:body] = parse(env[:body]) end end end
Private Instance Methods
parse(body)
click to toggle source
# File lib/json_api_client/middleware/parse_json.rb, line 16 def parse(body) ::JSON.parse(body) unless body.strip.empty? end
process_response_type?(type)
click to toggle source
# File lib/json_api_client/middleware/parse_json.rb, line 26 def process_response_type?(type) !!type.match(/\bjson$/) end
response_type(env)
click to toggle source
# File lib/json_api_client/middleware/parse_json.rb, line 20 def response_type(env) type = env[:response_headers]['Content-Type'].to_s type = type.split(';', 2).first if type.index(';') type end