class VCR::HTTPInteraction

Represents a single interaction over HTTP, containing a request and a response.

@attr [Request] request the request @attr [Response] response the response @attr [Time] recorded_at when this HTTP interaction was recorded

Public Class Methods

from_hash(hash) click to toggle source

Constructs a new instance from a hash.

@param [Hash] hash the hash to use to construct the instance. @return [HTTPInteraction] the HTTP interaction

# File lib/vcr/structs.rb, line 493
def self.from_hash(hash)
  new Request.from_hash(hash.fetch('request', {})),
      Response.from_hash(hash.fetch('response', {})),
      Time.httpdate(hash.fetch('recorded_at'))
end
new(*args) click to toggle source
Calls superclass method
# File lib/vcr/structs.rb, line 469
def initialize(*args)
  super
  self.recorded_at ||= Time.now
end

Public Instance Methods

hook_aware() click to toggle source

@return [HookAware] an instance with additional capabilities

suitable for use in `before_record` and `before_playback` hooks.
# File lib/vcr/structs.rb, line 501
def hook_aware
  HookAware.new(self)
end
to_hash() click to toggle source

Builds a serializable hash from the HTTP interaction data.

@return [Hash] hash that represents this HTTP interaction

and can be easily serialized.

@see ::from_hash

# File lib/vcr/structs.rb, line 479
def to_hash
  {
    'request'     => request.to_hash,
    'response'    => response.to_hash,
    'recorded_at' => recorded_at.httpdate
  }.tap do |hash|
    OrderedHashSerializer.apply_to(hash, members)
  end
end