Class: ZendeskAPI::Middleware::Response::ParseJson

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/zendesk_api/middleware/response/parse_json.rb

Constant Summary collapse

CONTENT_TYPE =
'Content-Type'.freeze

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/zendesk_api/middleware/response/parse_json.rb', line 10

def on_complete(env)
  type = env[:response_headers][CONTENT_TYPE].to_s
  type = type.split(';', 2).first if type.index(';')

  return unless type == 'application/json'

  unless env[:body].strip.empty?
    env[:body] = JSON.parse(env[:body])
  end
end