Class: VCR::HTTPInteraction
- Inherits:
-
Struct
- Object
- Struct
- VCR::HTTPInteraction
- Defined in:
- lib/vcr/structs.rb
Overview
Represents a single interaction over HTTP, containing a request and a response.
Direct Known Subclasses
Defined Under Namespace
Classes: HookAware
Instance Attribute Summary collapse
-
#recorded_at ⇒ Time
when this HTTP interaction was recorded.
-
#request ⇒ Request
the request.
-
#response ⇒ Response
the response.
Class Method Summary collapse
-
.from_hash(hash) ⇒ HTTPInteraction
Constructs a new instance from a hash.
Instance Method Summary collapse
-
#hook_aware ⇒ HookAware
An instance with additional capabilities suitable for use in
before_recordandbefore_playbackhooks. -
#initialize(*args) ⇒ HTTPInteraction
constructor
A new instance of HTTPInteraction.
-
#to_hash ⇒ Hash
Builds a serializable hash from the HTTP interaction data.
Constructor Details
#initialize(*args) ⇒ HTTPInteraction
Returns a new instance of HTTPInteraction.
439 440 441 442 |
# File 'lib/vcr/structs.rb', line 439 def initialize(*args) super self.recorded_at ||= Time.now end |
Instance Attribute Details
#recorded_at ⇒ Time
when this HTTP interaction was recorded
438 439 440 |
# File 'lib/vcr/structs.rb', line 438 def recorded_at @recorded_at end |
#request ⇒ Request
the request
438 439 440 |
# File 'lib/vcr/structs.rb', line 438 def request @request end |
#response ⇒ Response
the response
438 439 440 |
# File 'lib/vcr/structs.rb', line 438 def response @response end |
Class Method Details
.from_hash(hash) ⇒ HTTPInteraction
Constructs a new instance from a hash.
463 464 465 466 467 |
# File 'lib/vcr/structs.rb', line 463 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_aware ⇒ HookAware
Returns an instance with additional capabilities
suitable for use in before_record and before_playback hooks.
471 472 473 |
# File 'lib/vcr/structs.rb', line 471 def hook_aware HookAware.new(self) end |
#to_hash ⇒ Hash
Builds a serializable hash from the HTTP interaction data.
449 450 451 452 453 454 455 456 457 |
# File 'lib/vcr/structs.rb', line 449 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 |