Class: Dwolla::Response::ParseJson

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

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



4
5
6
7
8
# File 'lib/dwolla/response/parse_json.rb', line 4

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

#parse(body) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dwolla/response/parse_json.rb', line 10

def parse(body)
  case body
  when ''
    nil
  else
    response_hash = ::MultiJson.load(body)

    raise Dwolla::RequestException, response_hash["Message"] if response_hash["Success"] == false

    response_hash["Response"] ||
      response_hash["SendResult"] ||
        response_hash["RequestResult"] ||
          response_hash
  end
end