Class: TheCity::API::Response::ParseJson

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

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



18
19
20
21
22
# File 'lib/the_city/api/response/parse_json.rb', line 18

def on_complete(env)
  if respond_to?(:parse)
    env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
  end
end

#parse(body) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/the_city/api/response/parse_json.rb', line 9

def parse(body)
  case body
  when /\A^\s*$\z/, nil
    nil
  else
    JSON.parse(body, :symbolize_names => true)
  end
end