class Podio::Middleware::JsonResponse
Public Instance Methods
is_json?(env)
click to toggle source
# File lib/podio/middleware/json_response.rb, line 20 def is_json?(env) env[:response_headers]['content-type'] =~ /application\/json/ end
on_complete(env)
click to toggle source
# File lib/podio/middleware/json_response.rb, line 9 def on_complete(env) if env[:body].is_a?(String) && is_json?(env) && should_unmarshal?(env) && env[:status] != 500 env[:body] = parse(env[:body]) end end
parse(body)
click to toggle source
# File lib/podio/middleware/json_response.rb, line 24 def parse(body) return nil if body !~ /\S/ # json gem doesn't like decoding blank strings MultiJson.decode(body) rescue Object => err raise Faraday::Error::ParsingError.new(err) end
should_unmarshal?(env)
click to toggle source
# File lib/podio/middleware/json_response.rb, line 15 def should_unmarshal?(env) # don't unmarshal data from the API with a content-disposition header. not env[:response_headers]['content-disposition'] =~ /filename=/ end