Class: Goodall::Handler::Json

Inherits:
Base
  • Object
show all
Includes:
TolerateJson
Defined in:
lib/goodall/handler/json.rb

Instance Method Summary collapse

Instance Method Details

#parse_payload(payload) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/goodall/handler/json.rb', line 11

def parse_payload(payload)
  payload = if payload.class == String
    # assue it's a string of json
    begin
      MultiJson.load(payload)
    rescue MultiJson::LoadError
      # probably not JSON, return as-is
      return payload+"\n"
    end
  else
    payload
  end

  # detect "pretty" json by seeing if there are CRs in here
  if (json = MultiJson.dump(payload)) =~ /\n/
    json
  else
    pretty_print_json(json)
    # json
  end
end