Class: Capgun::Response::ParseJson

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

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



21
22
23
24
25
# File 'lib/capgun/response/parse_json.rb', line 21

def on_complete(env)
  if respond_to? :parse
    env[:body] = parse(env[:body]) unless env[:request][:raw] or [204,304].index env[:status]
  end
end

#parse(body) ⇒ Object



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

def parse(body)
    case body
    when ''
      nil
    when 'true'
      true
    when 'false'
      false
    else
      MultiJson.load(body)
    end
end