Class: Vacuum::Response

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/vacuum/response.rb

Overview

A wrapper around the API response

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.parsernil, .parse

Returns an optional custom parser.

Returns:

  • (nil, .parse)

    an optional custom parser



21
22
23
# File 'lib/vacuum/response.rb', line 21

def parser
  @parser
end

Instance Attribute Details

#parsernil, .parse

Returns an optional custom parser.

Returns:

  • (nil, .parse)

    an optional custom parser



29
30
31
# File 'lib/vacuum/response.rb', line 29

def parser
  @parser || self.class.parser
end

Instance Method Details

#dig(*key) ⇒ Object

Delegates to the Hash returned by #to_h to extract a nested value specified by the sequence of keys

Parameters:

  • key (String)

    one or more keys

See Also:



17
# File 'lib/vacuum/response.rb', line 17

def_delegator :to_h, :dig

#parseObject

Note:

Delegates to #to_h if no custom parser is set

Parses the response body



36
37
38
# File 'lib/vacuum/response.rb', line 36

def parse
  parser ? parser.parse(body) : to_h
end

#to_hHash

Casts body to Hash

Returns:

  • (Hash)


42
43
44
# File 'lib/vacuum/response.rb', line 42

def to_h
  JSON.parse(body)
end