Module: Eson::ResponseParser

Defined in:
lib/eson/modules/response_parser.rb

Overview

A plugins that parses HTTP responses as json and returns the json

Defined Under Namespace

Classes: JSONParseError

Instance Method Summary collapse

Instance Method Details

#call(*args) ⇒ Hash, Array

Evaluate the plugin.

Parameters:

  • args (Array<Object>)

    Any number of args used for calling the endpoint.

Returns:

  • (Hash, Array)

    the parsed json

Raises:



15
16
17
# File 'lib/eson/modules/response_parser.rb', line 15

def call(*args)
  parse(super)
end

#parse(response) ⇒ Hash, Array

Parse the response.

Parameters:

  • response (#body)

    The response

Returns:

  • (Hash, Array)

    the parsed json

Raises:



24
25
26
27
28
29
30
31
32
# File 'lib/eson/modules/response_parser.rb', line 24

def parse(response)
  begin
    MultiJson.decode(response.body) if response.body
  rescue MultiJson::DecodeError => e
    error = JSONParseError.new(e.message, response)
    error.source = response.body
    raise error
  end
end