Class: LearnSprout::Response::ParseJson

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

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



4
5
6
7
8
# File 'lib/learnsprout/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
# File 'lib/learnsprout/response/parse_json.rb', line 10

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

    #raise LearnSprout::RequestException, response_hash["message"] if response_hash["message"]
  end
end