File: http_interactions.R

package info (click to toggle)
r-cran-vcr 0.6.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,360 kB
  • sloc: cpp: 15; sh: 13; makefile: 2
file content (36 lines) | stat: -rw-r--r-- 1,082 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#' Get the http interactions of the current cassette
#'
#' @export
#' @return object of class `HTTPInteractionList` if there is a current
#' cassette in use, or `NullList` if no cassette in use
#' @examples \dontrun{
#' vcr_configure(dir = tempdir())
#' insert_cassette("foo_bar")
#' webmockr::webmockr_allow_net_connect()
#' library(crul)
#' cli <- crul::HttpClient$new("https://eu.httpbin.org/get")
#' one <- cli$get(query = list(a = 5))
#' z <- http_interactions()
#' z
#' z$interactions
#' z$used_interactions
#' # on eject, request written to the cassette
#' eject_cassette("foo_bar")
#' 
#' # insert cassette again
#' insert_cassette("foo_bar")
#' # now interactions will be present 
#' z <- http_interactions()
#' z$interactions
#' z$used_interactions
#' invisible(cli$get(query = list(a = 5)))
#' z$used_interactions
#' 
#' # cleanup
#' unlink(file.path(tempdir(), "foo_bar.yml"))
#' }
http_interactions <- function() {
  trycurr <- tryCatch(current_cassette(), error = function(e) e)
  if (!inherits(trycurr, "error")) return(trycurr$http_interactions_)
  NullList$new()
}