Skip to content

Commit

Permalink
remove last references to httr
Browse files Browse the repository at this point in the history
outside of `kernel_api()`.  The only exceptions are (a) `httr::upload_file()` and (b) testing structure.

ref #213
  • Loading branch information
wibeasley committed May 30, 2018
1 parent c821898 commit 2522527
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions R/kernel-api.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ kernel_api <- function( redcap_uri, post_body, config_options ) {

status_code <- result$status
success <- (status_code==200L)
raw_text <- httr::content(result, "text")
raw_text <- gsub("\r\n", "\n", raw_text) # Convert all line-ending to linux-style
raw_text <- as.character(httr::content(result, "text"))
raw_text <- gsub("\r\n", "\n", raw_text) # Convert all line-endings to linux-style
elapsed_seconds <- as.numeric(difftime(Sys.time(), start_time, units="secs"))

# example: raw_text <- "The hostname (redcap-db.hsc.net.ou.edu) / username (redcapsql) / password (XXXXXX) combination could not connect to the MySQL server. \r\n\t\tPlease check their values."
regex_cannot_connect <- "^The hostname \\((.+)\\) / username \\((.+)\\) / password \\((.+)\\) combination could not connect.+"
regex_empty <- "^\\s+$"

success <- (success & !any(grepl(regex_cannot_connect, raw_text)) & !any(grepl(regex_empty, raw_text)))
if(
any(grepl(regex_cannot_connect, raw_text)) |
any(grepl(regex_empty , raw_text))
) {
success <- FALSE # Overwrite the success flag if the raw_text is bad.
}

return( list(
status_code = status_code,
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-download-file-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ redcap_download_file_oneshot <- function(
outcome_message <- "file NOT downloaded."
records_affected_count <- 0L
record_id <- character(0) # Return an empty vector.
raw_text <- httr::content(kernel$result, type="text")
raw_text <- kernel$raw_text
file_path <- character(0)
}

Expand Down
2 changes: 1 addition & 1 deletion R/redcap-upload-file-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ redcap_upload_file_oneshot <- function(
record_id <- as.character(record)
kernel$raw_text <- ""
} else { #If the returned content wasn't recognized as valid IDs, then
raw_text <- httr::content(kernel$result, type="text") # TODO: would this be stored as kernal$raw_text?
raw_text <- kernel$raw_text
outcome_message <- paste0("file NOT uploaded ")
records_affected_count <- 0L
record_id <- character(0) # Return an empty vector.
Expand Down

0 comments on commit 2522527

Please sign in to comment.