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



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

def parser
  @parser
end

Instance Attribute Details

#parsernil, .parse

Returns an optional custom parser.

Returns:

  • (nil, .parse)

    an optional custom parser



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

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:



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

def_delegator :to_h, :dig

#parseObject

Note:

Delegates to #to_h if no custom parser is set

Parses the response body



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

def parse
  parser&.parse(body) || to_h
end

#to_hHash

Casts body to Hash

Returns:

  • (Hash)


44
45
46
# File 'lib/vacuum/response.rb', line 44

def to_h
  JSON.parse(body)
end