diff --git a/R/retrieve-credential.R b/R/retrieve-credential.R index c5614dc0..d4eed6ac 100644 --- a/R/retrieve-credential.R +++ b/R/retrieve-credential.R @@ -34,7 +34,7 @@ #' ) #' #' @param path_credential The file path to the CSV containing the credentials. -#' Required. +#' Required. #' @param project_id The ID assigned to the project withing REDCap. This #' allows the user to store tokens to multiple REDCap projects in one file. #' Required diff --git a/playgrounds/HttrPlayground.R b/playgrounds/HttrPlayground.R deleted file mode 100644 index 5d8d2e88..00000000 --- a/playgrounds/HttrPlayground.R +++ /dev/null @@ -1,153 +0,0 @@ -rm(list=ls(all=TRUE)) #Clear the variables from previous runs. - -library(httr) - -redcap_uri <- "https://www.redcapplugins.org/redcap_v6.5.0/API/" -token <- "D96029BFCE8FFE76737BFC33C2BCC72E" #For `UnitTestPhiFree` account and the simple project (pid 27) on Vandy's test server. - - -redcap_uri <- "https://bbmc.ouhsc.edu/redcap/api/" -token <- "9A81268476645C4E5F03428B8AC3AA7B" - -raw_or_label <- "raw" -export_data_access_groups_string <- "true" -records_collapsed <- "1,2,5" -fields_collapsed <- NULL -events_collapsed <- NULL - -config_options <- list(cainfo = system.file("cacert.pem", package="openssl")) -# config_options <- RCurl::curlOptions(ssl.verifypeer = FALSE) -config_options <- httr::config(ssl_verifypeer=FALSE) -# config_options <- list() - -post_body <- list( - token = token, - content = 'record', - format = 'csv', - type = 'flat', - rawOrLabel = raw_or_label, - exportDataAccessGroups = export_data_access_groups_string, - records = records_collapsed, - fields = fields_collapsed, - events = events_collapsed -) - -result <- httr::POST( - url = redcap_uri, - body = post_body, - config = config_options -) - - -result$status_code -result$headers$status -result$headers$statusmessage -raw_text <- httr::content(result, "text") - -result <- httr::POST( - url = "https://httpbin.org/post", - body = "A simple text string", - config = httr::config(ssl_verifypeer=FALSE) -) -httr::content(result, "text") - -ds <- utils::read.csv(text=raw_text) #Convert the raw text to a dataset. - -# -# raw_text2 <- RCurl::postForm( -# uri = redcap_uri -# , token = token -# , content = 'record' -# , format = 'csv' -# , type = 'flat' -# , rawOrLabel = raw_or_label -# , exportDataAccessGroups = export_data_access_groups_string -# , records = records_collapsed -# , fields = fields_collapsed -# , .opts = RCurl::curlOptions(ssl.verifypeer = FALSE) -# ) -# ds2 <- utils::read.csv(text=raw_text2) #Convert the raw text to a dataset. - -# result <- redcap_read_oneshot(redcap_uri="https://bbmc.ouhsc.edu/redcap/api/", token = "9A81268476645C4E5F03428B8AC3AA7B") -# dput(result$data) -dsToWrite <- structure(list(record_id = 1:5, name_first = c("Nutmeg", "Tumtum", - "Marcus", "Trudy", "John Lee"), name_last = c("Nutmouse", "Nutmouse", - "Wood", "DAG", "Walker"), address = c("14 Rose Cottage St.\nKenning UK, 323232", - "14 Rose Cottage Blvd.\nKenning UK 34243", "243 Hill St.\nGuthrie OK 73402", - "342 Elm\nDuncanville TX, 75116", "Hotel Suite\nNew Orleans LA, 70115" - ), telephone = c("(432) 456-4848", "(234) 234-2343", "(433) 435-9865", - "(987) 654-3210", "(333) 333-4444"), email = c("nutty@mouse.com", - "tummy@mouse.comm", "mw@mwood.net", "peroxide@blonde.com", "left@hippocket.com" - ), dob = c("2003-08-30", "2003-03-10", "1934-04-09", "1952-11-02", - "1955-04-15"), age = c(10L, 10L, 79L, 61L, 58L), ethnicity = c(1L, - 1L, 0L, 1L, 1L), race = c(2L, 6L, 4L, 4L, 4L), sex = c(0L, 1L, - 1L, 0L, 1L), height = c(5, 6, 180, 165, 193.04), weight = c(1L, - 1L, 80L, 54L, 104L), bmi = c(400, 277.8, 24.7, 19.8, 27.9), comments = c("Character in a book, with some guessing", - "A mouse character from a good book", "completely made up", "This record doesn't have a DAG assigned\n\nSo call up Trudy on the telephone\nSend her a letter in the mail", - "Had a hand for trouble and a eye for cash\n\nHe had a gold watch chain and a black mustache" - ), demographics_complete = c(2L, 2L, 2L, 2L, 2L)), .Names = c("record_id", - "name_first", "name_last", "address", "telephone", "email", "dob", - "age", "ethnicity", "race", "sex", "height", "weight", "bmi", - "comments", "demographics_complete"), class = "data.frame", row.names = c(NA, - -5L)) -dsToWrite$age <- NULL; dsToWrite$bmi <- NULL #Drop the calculated fields -# dsToWrite <- dsToWrite[1:3, ] -# result <- REDCapR::redcap_write_oneshot(ds=dsToWrite, redcap_uri="https://bbmc.ouhsc.edu/redcap/api/", token = "9A81268476645C4E5F03428B8AC3AA7B") - -con <- base::textConnection(object='csvElements', open='w', local=TRUE) -utils::write.csv(dsToWrite, con, row.names = FALSE, na="") -close(con) - -csv <- paste(csvElements, collapse="\n") -csvForPostman <- gsub(pattern="[\\]", replacement="", x=csv) -csvForPostman - -post_body <- list( - token = token, - content = 'record', - format = 'csv', - type = 'flat', - rawOrLabel = raw_or_label, - exportDataAccessGroups = export_data_access_groups_string, - records = records_collapsed, - fields = fields_collapsed, - - #These next values separate the import from the export API call - data = csv, - overwriteBehavior = 'overwrite', #overwriteBehavior: *normal* - blank/empty values will be ignored [default]; *overwrite* - blank/empty values are valid and will overwrite data - returnContent = 'ids', - returnFormat = 'csv' -) - -result <- httr::POST( - url = redcap_uri, - body = post_body, - .opts = config_options -) -result - -status_code <- result$status_code -status_message <- result$headers$statusmessage -return_content <- httr::content(result, type="text") - -# returnContent <- RCurl::postForm( -# uri = redcap_uri, -# token = token, -# content = 'record', -# format = 'csv', -# type = 'flat', -# returnContent = "ids", -# overwriteBehavior = 'overwrite', #overwriteBehavior: *normal* - blank/empty values will be ignored [default]; *overwrite* - blank/empty values are valid and will overwrite data -# data = csv, -# .opts = curl_options -# ) - -(was_successful <- !httr::http_error("https://bbmc.ouhsc.edu/redcap/plugins/redcapr/no_auth_test.php")) - -RCurl::httpHEAD(url = "https://bbmc.ouhsc.edu/redcap/plugins/redcapr/no_auth_test.php", .opts = RCurl::curlOptions(ssl.verifypeer = FALSE)) -RCurl::httpGET(url = "https://bbmc.ouhsc.edu/redcap/plugins/redcapr/no_auth_test.php", .opts = RCurl::curlOptions(ssl.verifypeer = FALSE)) - - -cert_location <- system.file("cacert.pem", package="openssl") -file.exists(cert_location) -httr::url_ok("https://bbmc.ouhsc.edu/redcap/plugins/redcapr/no_auth_test.php", config=list(cainfo=cert_location, sslversion=3)) diff --git a/playgrounds/LinuxPlayground.R b/playgrounds/LinuxPlayground.R deleted file mode 100644 index dd8ae149..00000000 --- a/playgrounds/LinuxPlayground.R +++ /dev/null @@ -1,44 +0,0 @@ -rm(list=ls(all=TRUE)) #Clear the variables from previous runs. -library(RCurl) -library(httr) - -redcap_uri <- "https://bbmc.ouhsc.edu/redcap/api/" -token <- "9A81268476645C4E5F03428B8AC3AA7B" - - -# curl_options <- RCurl::curlOptions(ssl.verifypeer = FALSE) -curl_options <- list(cainfo = system.file("cacert.pem", package="openssl") - -raw_text2 <- RCurl::postForm( - uri = redcap_uri - , token = token - , content = 'record' - , format = 'csv' - , type = 'flat' - , .opts = curl_options -) -raw_text2 - -#Returns -# [1] "record_id,name_first,name_last,address,telephone,email,dob,age,ethnicity,race,sex,height,weight,bmi,comments,demographics_complete\n\"1\",\"Nutmeg\",\"Nutmouse\",\"14 Rose Cottage St.\r\nKenning UK, 323232\",\"(432) 456-4848\",\"nutty@mouse.com\",\"2003-08-30\",10,1,2,0,5,1,400,\"Character in a book, with some guessing\",2\n\"2\",\"Tumtum\",\"Nutmouse\",\"14 Rose Cottage Blvd.\r\nKenning UK 34243\",\"(234) 234-2343\",\"tummy@mouse.comm\",\"2003-03-10\",11,1,6,1,6,1,277.8,\"A mouse character from a good book\",2\n\"3\",\"Marcus\",\"Wood\",\"243 Hill St.\r\nGuthrie OK 73402\",\"(433) 435-9865\",\"mw@mwood.net\",\"1934-04-09\",79,0,4,1,180,80,24.7,\"completely made up\",2\n\"4\",\"Trudy\",\"DAG\",\"342 Elm\r\nDuncanville TX, 75116\",\"(987) 654-3210\",\"peroxide@blonde.com\",\"1952-11-02\",61,1,4,0,165,54,19.8,\"This record doesn't have a DAG assigned\r\n\r\nSo call up Trudy on the telephone\r\nSend her a letter in the mail\",2\n\"5\",\"John Lee\",\"Walker\",\"Hotel Suite\r\nNew Orleans LA, 70115\",\"(333) 333-4444\",\"left@hippocket.com\",\"1955-04-15\",58,1,4,1,193.04,104,27.9,\"Had a hand for trouble and a eye for cash\r\n\r\nHe had a gold watch chain and a black mustache\",2\n" -# attr(,"Content-Type") -# charset -# "text/html" "utf-8" - -raw_text <- httr::POST( - url = redcap_uri - , body = list( - token = token - , content = 'record' - , format = 'csv' - , type = 'flat' - ), - #, .opts = RCurl::curlOptions(ssl.verifypeer = FALSE) - , .opts = curl_options - , httr::verbose() -) -raw_text - -#Returns -# Error in function (type, msg, asError = TRUE) : -# Unknown SSL protocol error in connection to bbmc.ouhsc.edu:443 \ No newline at end of file diff --git a/playgrounds/MetadataPlayground.R b/playgrounds/MetadataPlayground.R deleted file mode 100644 index 90f62f85..00000000 --- a/playgrounds/MetadataPlayground.R +++ /dev/null @@ -1,124 +0,0 @@ -rm(list=ls(all=TRUE)) -library(REDCapR) -uri <- "https://bbmc.ouhsc.edu/redcap/api/" -token <- "9A81268476645C4E5F03428B8AC3AA7B" #The version that is relatively static (and isn't repeatedly deleted). -# token <- "D70F9ACD1EDD6F151C6EA78683944E98" #The version that is repeatedly deleted and rewritten for most unit tests. - -d <- redcap_metadata_read(redcap_uri=uri, token=token)$data -# redcap_metadata_read(redcap_uri=uri, token=token, fields=c("record_id", "name_last")) -# redcap_metadata_read(redcap_uri=uri, token=token, fields_collapsed = "record_id, name_last") -# redcap_metadata_read(redcap_uri=uri, token=token, forms = c("health")) -# redcap_metadata_read(redcap_uri=uri, token=token, forms_collapsed = "health") -choices <- d[d$field_name=="race", "select_choices_or_calculations"] - -# pattern <- "(?<=\\A| \\| )(?\\d{1,}), (?