Skip to content

Commit

Permalink
remaining sanitize_token() holdovers
Browse files Browse the repository at this point in the history
See #144
  • Loading branch information
wibeasley committed Mar 25, 2017
1 parent 5a41ae0 commit 3985324
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
42 changes: 21 additions & 21 deletions R/project-simple.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@

populate_project_simple <- function( batch = FALSE ) {
if( !requireNamespace("testthat") ) stop("The function REDCapR:::populate_project_simple() cannot run if the `testthat` package is not installed. Please install it and try again.")

#Declare the server & user information
# uri <- "https://www.redcapplugins.org/api/"
uri <- "https://bbmc.ouhsc.edu/redcap/api/"

# token <- "D96029BFCE8FFE76737BFC33C2BCC72E" #For `UnitTestPhiFree` account and the simple project (pid 27) on Vandy's test server.
# token <- "9A81268476645C4E5F03428B8AC3AA7B" #For `UnitTestPhiFree` account and the simple project (pid 153)
token <- "D70F9ACD1EDD6F151C6EA78683944E98" #For `UnitTestPhiFree` account and the simple project (pid 213)

project <- REDCapR::redcap_project$new(redcap_uri=uri, token=token)
path_in_simple <- base::file.path(devtools::inst(name="REDCapR"), "test-data/project-simple/simple-data.csv")

#Write the file to disk (necessary only when you wanted to change the data). Don't uncomment; just run manually.
# returned_object <- redcap_read_oneshot(redcap_uri=uri, token=token, raw_or_label="raw")
# utils::write.csv(returned_object$data, file="./inst/test-data/project-simple/simple-data.csv", row.names=FALSE)
# returned_object_metadata <- redcap_metadata_read(redcap_uri=uri, token=token)
# utils::write.csv(returned_object_metadata$data, file="./inst/test-data/project-simple/simple-metadata.csv", row.names=FALSE)

#Read in the data in R's memory from a csv file.
dsToWrite <- utils::read.csv(file=path_in_simple, stringsAsFactors=FALSE)
# dsToWrite <- utils::read.csv(file="./inst/test-data/project-simple/simple-data.csv", stringsAsFactors=FALSE)

#Remove the calculated variables.
dsToWrite$age <- NULL
dsToWrite$bmi <- NULL

#Import the data into the REDCap project
testthat::expect_message(
if( batch ) {
Expand All @@ -37,12 +37,12 @@ populate_project_simple <- function( batch = FALSE ) {
}
)
# For internal inspection: REDCapR::redcap_read_oneshot(redcap_uri=uri, token=token, verbose=TRUE)

#If uploading the data was successful, then upload the image files.
if( returned_object$success) {
upload_file_simple(redcap_uri=uri, token=token)
}

#Print a message and return a boolean value
base::message(base::sprintf("populate_project_simple success: %s.", returned_object$success))
return( list(is_success=returned_object$success, redcap_project=project) )
Expand All @@ -52,12 +52,12 @@ clear_project_simple <- function( verbose = TRUE ) {
pathDeleteTestRecord <- "https://bbmc.ouhsc.edu/redcap/plugins/redcapr/delete_redcapr_simple.php"

# httr::url_ok(pathDeleteTestRecord)

#Returns a boolean value if successful
(was_successful <- !httr::http_error(pathDeleteTestRecord))#, config=config_options))

#Print a message and return a boolean value
if( verbose )
if( verbose )
base::message(base::sprintf("clear_project_simple success: %s.", was_successful))
return( was_successful )
}
Expand All @@ -66,35 +66,35 @@ clean_start_simple <- function( batch = FALSE, delay_in_seconds = 1 ) {
if( !requireNamespace("testthat") ) stop("The function REDCapR:::populate_project_simple() cannot run if the `testthat` package is not installed. Please install it and try again.")
testthat::expect_message(
clear_result <- clear_project_simple(),
regexp = "clear_project_simple success: TRUE."
regexp = "clear_project_simple success: TRUE."
)
testthat::expect_true(clear_result, "Clearing the results from the simple project should be successful.")
base::Sys.sleep(delay_in_seconds) #Pause after deleting records.

testthat::expect_message(
populate_result <- populate_project_simple(batch=batch),
regexp = "populate_project_simple success: TRUE."
regexp = "populate_project_simple success: TRUE."
)
testthat::expect_true(populate_result$is_success, "Population the the simple project should be successful.")
base::Sys.sleep(delay_in_seconds) #Pause after writing records.

return( populate_result )
}

upload_file_simple <- function( redcap_uri, token=token ) {
records <- 1:5
file_paths <- base::file.path(devtools::inst(name="REDCapR"), paste0("test-data/mugshot-", records, ".jpg"))

field <- "mugshot"
event <- "" # only for longitudinal events
token <- sub("\\n", "", token)

token <- sanitize_token(token)

for( i in seq_along(records) ) {
record <- records[i]
file_path <- file_paths[i]
redcap_upload_file_oneshot(file_name=file_path, record=record, field=field, redcap_uri=redcap_uri, token=token)
}
}
}

# populate_project_simple()
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 @@ -76,7 +76,7 @@ redcap_download_file_oneshot <- function( file_name=NULL, directory=NULL, overwr
if( missing(token) )
stop("The required parameter `token` was missing from the call to `redcap_download_file_oneshot()`.")

token <- sub("\\n", "", token)
token <- sanitize_token(token)

post_body <- list(
token = token,
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-metadata-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ redcap_metadata_read <- function(
if( missing(token) )
stop("The required parameter `token` was missing from the call to `redcap_read_oneshot()`.")

token <- sub("\\n", "", token)
token <- sanitize_token(token)

if( nchar(forms_collapsed)==0 )
forms_collapsed <- ifelse(is.null(forms), "", paste0(forms, collapse=",")) #This is an empty string if `forms` is NULL.
Expand Down

0 comments on commit 3985324

Please sign in to comment.