Skip to content

Commit

Permalink
add disk value in RequestSignature class & have set_body() within Res…
Browse files Browse the repository at this point in the history
…ponse account for when disk used #57
  • Loading branch information
sckott committed Jul 25, 2019
1 parent 02f6cc2 commit 6fe9cfb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description: Stubbing and setting expectations on 'HTTP' requests.
'HTTP' method, query parameters, request body, headers and
more. Can be used for unit tests or outside of a testing
context.
Version: 0.3.4.9319
Version: 0.3.4.9320
Authors@R: c(
person("Scott", "Chamberlain", role = c("aut", "cre"), email =
"[email protected]", comment = c(ORCID="0000-0003-1444-9135")),
Expand Down
21 changes: 21 additions & 0 deletions R/RequestSignature.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#' \item headers - headers as a named list
#' \item proxies - proxies as a named list
#' \item auth - authentication details, as a named list
#' \item disk - if writing to disk, the path (character)
#' }
#'
#' @format NULL
Expand Down Expand Up @@ -57,6 +58,17 @@
#' bb$headers
#' bb$body
#' bb$to_s()
#'
#' # with disk path
#' f <- tempfile()
#' bb <- RequestSignature$new(
#' method = "get",
#' uri = "https:/httpbin.org/get",
#' options = list(disk = f)
#' )
#' bb
#' bb$disk
#' bb$to_s()

RequestSignature <- R6::R6Class(
'RequestSignature',
Expand All @@ -68,6 +80,7 @@ RequestSignature <- R6::R6Class(
proxies = NULL,
auth = NULL,
url = NULL,
disk = NULL,

initialize = function(method, uri, options = list()) {
verb <- match.arg(tolower(method), http_verbs)
Expand Down Expand Up @@ -97,6 +110,9 @@ RequestSignature <- R6::R6Class(
cat(" auth: ", sep = "\n")
cat_foo(self$auth)
}
if (!is.null(self$disk)) {
cat(paste0(" disk: ", self$disk), sep = "\n")
}
},

to_s = function() {
Expand Down Expand Up @@ -141,6 +157,11 @@ RequestSignature <- R6::R6Class(
self$auth <- options$auth
}
}
if ('disk' %in% names(options)) {
if (!is.null(options$disk) && length(options)) {
self$disk <- options$disk
}
}
}
)
)
Expand Down
4 changes: 2 additions & 2 deletions R/Response.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ Response <- R6::R6Class(
},
get_respone_headers = function() self$response_headers,

set_body = function(body) {
set_body = function(body, disk = FALSE) {
self$body <- body
self$content <- if (!is.null(body) && is.character(body)) {
charToRaw(body)
if (disk) body else charToRaw(body)
} else {
raw(0)
}
Expand Down
12 changes: 12 additions & 0 deletions man/RequestSignature.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6fe9cfb

Please sign in to comment.