Sha256: ddda417c026d17c0169b8eeb36a2ff8c53b8e3e5d6e9ee4e1921fc3f222f9a17

Contents?: true

Size: 840 Bytes

Versions: 2

Compression:

Stored size: 840 Bytes

Contents

require 'typhoeus'

# The response contains the raw response (typhoeus)
# and provides functionality to access response data.
class LHC::Response

  attr_accessor :request

  # A response is initalized with the underlying raw response (typhoeus in our case)
  # and the associated request.
  def initialize(raw, request)
    self.request = request
    self.raw = raw
  end

  # Access response data.
  # Cache parsing.
  def data
    @data ||= JSON.parse(raw.body, object_class: OpenStruct)
    @data
  end

  def body
    raw.body
  end

  def code
    raw.code
  end

  def headers
    raw.headers
  end

  def options
    raw.options
  end

  # Provides response time in ms.
  def time
    (raw.time || 0) * 1000
  end

  def timeout?
    raw.timed_out?
  end

  def success?
    raw.success?
  end

  private

  attr_accessor :raw

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lhc-3.1.1 lib/lhc/response.rb
lhc-3.1.0 lib/lhc/response.rb