Sha256: 6336baff7857bd36cd5383ff0400739c24c3f01fd0c0826c58a6d51195f45a69

Contents?: true

Size: 942 Bytes

Versions: 6

Compression:

Stored size: 942 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 ||= format.parse(self)
    @data
  end

  def effective_url
    raw.effective_url
  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

  def format
    return JsonFormat.new if request.nil?
    request.format
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lhc-3.5.5 lib/lhc/response.rb
lhc-3.5.4 lib/lhc/response.rb
lhc-3.5.3 lib/lhc/response.rb
lhc-3.5.2 lib/lhc/response.rb
lhc-3.5.1 lib/lhc/response.rb
lhc-3.5.0 lib/lhc/response.rb