Class: VCR::HTTPInteraction

Inherits:
Struct
  • Object
show all
Defined in:
lib/vcr/structs.rb

Overview

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

Direct Known Subclasses

HookAware

Defined Under Namespace

Classes: HookAware

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ HTTPInteraction

Returns a new instance of HTTPInteraction



469
470
471
472
# File 'lib/vcr/structs.rb', line 469

def initialize(*args)
  super
  self.recorded_at ||= Time.now
end

Instance Attribute Details

#recorded_atTime

when this HTTP interaction was recorded

Returns:

  • (Time)

    the current value of recorded_at



468
469
470
# File 'lib/vcr/structs.rb', line 468

def recorded_at
  @recorded_at
end

#requestRequest

the request

Returns:

  • (Request)

    the current value of request



468
469
470
# File 'lib/vcr/structs.rb', line 468

def request
  @request
end

#responseResponse

the response

Returns:

  • (Response)

    the current value of response



468
469
470
# File 'lib/vcr/structs.rb', line 468

def response
  @response
end

Class Method Details

.from_hash(hash) ⇒ HTTPInteraction

Constructs a new instance from a hash.

Parameters:

  • hash (Hash)

    the hash to use to construct the instance.

Returns:



493
494
495
496
497
# 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

Instance Method Details

#hook_awareHookAware

Returns an instance with additional capabilities suitable for use in before_record and before_playback hooks.

Returns:

  • (HookAware)

    an instance with additional capabilities suitable for use in before_record and before_playback hooks.



501
502
503
# File 'lib/vcr/structs.rb', line 501

def hook_aware
  HookAware.new(self)
end

#to_hashHash

Builds a serializable hash from the HTTP interaction data.

Returns:

  • (Hash)

    hash that represents this HTTP interaction and can be easily serialized.

See Also:



479
480
481
482
483
484
485
486
487
# 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