Sha256: e1af240f4f90b49454450e6aec2c4deab9e9fd525d467d36f709dd0390ad68fa

Contents?: true

Size: 552 Bytes

Versions: 1

Compression:

Stored size: 552 Bytes

Contents

# frozen_string_literal: true

require 'delegate'
require 'forwardable'
require 'json'

module Vacuum
  # A wrapper around the API response
  class Response < SimpleDelegator
    extend Forwardable

    # @!method dig(*key)
    #   Delegates to {Response#to_h} to extract a nested value specified by the
    #     sequence of keys
    #   @param [String] key
    #   @see https://ruby-doc.org/core/Hash.html#method-i-dig
    def_delegator :to_h, :dig

    # Casts body to Hash
    # @return [Hash]
    def to_h
      JSON.parse(body)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vacuum-3.1.0 lib/vacuum/response.rb