Class: Luchadeer::Middleware::ParseJSON

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

Constant Summary collapse

WHITESPACE_REGEX =
/\A^\s*$\z/

Instance Method Summary collapse

Instance Method Details

#on_complete(response) ⇒ Object



20
21
22
# File 'lib/luchadeer/middleware/parse_json.rb', line 20

def on_complete(response)
  response.body = parse(response.body)
end

#parse(body) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/luchadeer/middleware/parse_json.rb', line 11

def parse(body)
  case body
  when WHITESPACE_REGEX, nil
    nil
  else
    JSON.parse(body, symbolize_names: true)
  end
end