Method: Eipiai::Resource#params

Defined in:
lib/eipiai/resources/base.rb

#params(body = request.body.to_s) ⇒ Hash

params

Given a string in JSON format, returns the hash representation of that object.

If the input is invalid JSON, an empty hash is returned.

If no argument is given, ‘request.body` is used as the JSON input.

Examples:

Parse valid JSON request

resource.params('{ "hello": "world" }') # => { 'hello' => 'world' }

Parse invalid JSON request

resource.params('invalid') #=> {}

Parameters:

  • body (String) (defaults to: request.body.to_s)

    JSON provided as a string

Returns:

  • (Hash)

    JSON string, converted to a hash



177
178
179
180
181
# File 'lib/eipiai/resources/base.rb', line 177

def params(body = request.body.to_s)
  @params ||= JSON.parse(body)
rescue JSON::ParserError
  {}
end