Main R6 class that is called from the main user facing
function use_cassette()
Points of webmockr integration
initialize()
: webmockr is used in theinitialize()
method to create webmockr stubs. stubs are created on call toCassette$new()
withininsert_cassette()
, but then on exitinguse_cassette()
, or callingeject()
onCassette
class frominsert_cassette()
, stubs are cleaned up.eject()
method:webmockr::disable()
is called before exiting eject to disable webmock so that webmockr does not affect any HTTP requests that happen afterwardscall_block()
method: call_block is used in theuse_cassette()
function to evaluate whatever code is passed to it; within call_blockwebmockr::webmockr_allow_net_connect()
is run before we evaluate the code block to allow real HTTP requests, thenwebmockr::webmockr_disable_net_connect()
is called after evalulating the code block to disallow real HTTP requestsmake_http_interaction()
method:webmockr::pluck_body()
utility function is used to pull the request body out of the HTTP requestserialize_to_crul()
method: method: webmockr::RequestSignature and webmockr::Response are used to build a request and response, respectively, then passed towebmockr::build_crul_response()
to make a completecrul
HTTP response object
Public fields
name
(character) cassette name
record
(character) record mode
manfile
(character) cassette file path
recorded_at
(character) date/time recorded at
serialize_with
(character) serializer to use (yaml|json)
serializer
(character) serializer to use (yaml|json)
persist_with
(character) persister to use (FileSystem only)
persister
(character) persister to use (FileSystem only)
match_requests_on
(character) matchers to use default: method & uri
re_record_interval
(numeric) the re-record interval
tag
ignored, not used right now
tags
ignored, not used right now
root_dir
root dir, gathered from
vcr_configuration()
update_content_length_header
(logical) Whether to overwrite the
Content-Length
headerallow_playback_repeats
(logical) Whether to allow a single HTTP interaction to be played back multiple times
allow_unused_http_interactions
(logical) ignored, not used right now
exclusive
(logical) ignored, not used right now
preserve_exact_body_bytes
(logical) Whether to base64 encode the bytes of the requests and responses
args
(list) internal use
http_interactions_
(list) internal use
new_recorded_interactions
(list) internal use
clean_outdated_http_interactions
(logical) Should outdated interactions be recorded back to file
to_return
(logical) internal use
cassette_opts
(list) various cassette options
Methods
Method new()
Create a new Cassette
object
Usage
Cassette$new(
name,
record,
serialize_with,
persist_with,
match_requests_on,
re_record_interval,
tag,
tags,
update_content_length_header,
allow_playback_repeats,
allow_unused_http_interactions,
exclusive,
preserve_exact_body_bytes,
clean_outdated_http_interactions
)
Arguments
name
The name of the cassette. vcr will sanitize this to ensure it is a valid file name.
record
The record mode. Default: "once". In the future we'll support "once", "all", "none", "new_episodes". See recording for more information
serialize_with
(character) Which serializer to use. Valid values are "yaml" (default), the only one supported for now.
persist_with
(character) Which cassette persister to use. Default: "file_system". You can also register and use a custom persister.
match_requests_on
List of request matchers to use to determine what recorded HTTP interaction to replay. Defaults to
["method", "uri"]
. The built-in matchers are "method", "uri", "headers" and "body" ("host" and "path" not supported yet, but should be in a future version)re_record_interval
(numeric) When given, the cassette will be re-recorded at the given interval, in seconds.
tag, tags
tags ignored, not used right now
update_content_length_header
(logical) Whether or not to overwrite the
Content-Length
header of the responses to match the length of the response body. Default:FALSE
allow_playback_repeats
(logical) Whether or not to allow a single HTTP interaction to be played back multiple times. Default:
FALSE
.allow_unused_http_interactions
(logical) ignored, not used right now
exclusive
(logical) ignored, not used right now
preserve_exact_body_bytes
(logical) Whether or not to base64 encode the bytes of the requests and responses for this cassette when serializing it. See also
preserve_exact_body_bytes
invcr_configure()
. Default:FALSE
clean_outdated_http_interactions
(logical) Should outdated interactions be recorded back to file. Default:
FALSE
Method print()
print method for Cassette
objects
Method up_to_date_interactions()
Cleans out any old interactions based on the re_record_interval and clean_outdated_http_interactions settings
Arguments
interactions
list of http interactions, of class HTTPInteraction
Method http_interactions()
make HTTPInteractionList object, assign to http_interactions_ var
Method make_http_interaction()
Make an HTTPInteraction
object
Returns
an object of class HTTPInteraction
Examples
if (FALSE) { # \dontrun{
library(vcr)
vcr_configure(dir = tempdir())
res <- Cassette$new(name = "bob")
res$file()
res$originally_recorded_at()
res$recording()
res$serializable_hash()
res$eject()
res$should_remove_matching_existing_interactions()
res$storage_key()
res$match_requests_on
# record all requests
res <- Cassette$new("foobar", record = "all")
res$eject()
# cleanup
unlink(file.path(tempdir(), c("bob.yml", "foobar.yml")))
library(vcr)
vcr_configure(dir = tempdir())
res <- Cassette$new(name = "jane")
library(crul)
# HttpClient$new("https://hb.opencpu.org")$get("get")
} # }