ReqVCR.Tape (ReqVCR v0.3.0)

View Source

A struct representing a tape.

Summary

Functions

Builds a new tape from a request and an optional response.

Records a tape to a file.

Replays a tape from a file.

Types

replay()

@type replay() :: %{
  url: String.t(),
  request: map(),
  response: map(),
  recorded_at: DateTime.t()
}

t()

@type t() :: %{
  url: String.t(),
  path: String.t(),
  file: String.t(),
  filename: String.t(),
  request: Req.Request.t(),
  response: Req.Response.t(),
  recorded_at: nil | DateTime.t(),
  opts: keyword()
}

Functions

new(request, response \\ nil)

@spec new(Req.Request.t(), Req.Response.t()) :: t()

Builds a new tape from a request and an optional response.

Parameters

  • request - the original request
  • response - the optional response (default: nil)

Returns

  • a %Tape{} struct representing the tape

record(tape)

@spec record(t()) :: :ok | {:error, any()}

Records a tape to a file.

Parameters

  • tape - the tape to record

Returns

  • :ok if the tape was successfully recorded
  • {:error, reason} if there was an error recording the tape

replay(tape)

@spec replay(t()) :: {:ok, replay()} | {:error, any()}

Replays a tape from a file.

Parameters

  • tape - the tape to replay

Returns

  • {:ok, map()} if the tape was successfully replayed
  • {:error, reason} if there was an error replaying the tape