Skip to content

Commit

Permalink
RS-3782: Encode URL parameters, switch to app.displayr endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremytay90 committed Sep 27, 2019
1 parent 93a75f4 commit 6195d9a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -33,6 +33,7 @@ importFrom(mime,guess_type)
importFrom(readxl,read_excel)
importFrom(rgeolocate,maxmind)
importFrom(tools,file_ext)
importFrom(utils,URLencode)
importFrom(utils,download.file)
importFrom(utils,read.csv)
importFrom(utils,write.csv)
15 changes: 10 additions & 5 deletions R/DataMart.R
Expand Up @@ -7,13 +7,14 @@
#' @return TRUE if the file exists, otherwise FALSE
#'
#' @importFrom httr HEAD add_headers
#' @importFrom utils URLencode
#'
#' @export
QFileExists <- function(filename)
{
companySecret <- ifelse(exists("companySecret") && !identical(companySecret, NULL), companySecret, "")
clientId <- ifelse(exists("clientId") && !identical(clientId, NULL), gsub("[^0-9]", "", clientId), "")
res <- try(HEAD(paste0("https://test.displayr.com/api/DataMart?filename=", filename),
res <- try(HEAD(paste0("https://app.displayr.com/api/DataMart?filename=", URLencode(filename, TRUE)),
config=add_headers("X-Q-Company-Secret" = companySecret,
"X-Q-Project-ID" = clientId)))

Expand Down Expand Up @@ -47,6 +48,7 @@ QFileExists <- function(filename)
#' @importFrom curl curl new_handle handle_setheaders
#' @importFrom httr POST upload_file add_headers handle
#' @importFrom tools file_ext
#' @importFrom utils URLencode
#'
#' @export
QFileOpen <- function(filename, open = "r", blocking = TRUE,
Expand All @@ -63,7 +65,7 @@ QFileOpen <- function(filename, open = "r", blocking = TRUE,
"X-Q-Company-Secret" = companySecret,
"X-Q-Project-ID" = clientId
)
conn <- try(curl(paste0("https://test.displayr.com/api/DataMart?filename=", filename),
conn <- try(curl(paste0("https://app.displayr.com/api/DataMart?filename=", URLencode(filename, TRUE)),
open = mode,
handle = h),
silent = TRUE)
Expand Down Expand Up @@ -105,6 +107,7 @@ QFileOpen <- function(filename, open = "r", blocking = TRUE,
#'
#' @importFrom httr POST add_headers upload_file
#' @importFrom mime guess_type
#' @importFrom utils URLencode
#'
#' @export
close.qpostconn = function(conn, ...)
Expand All @@ -116,7 +119,7 @@ close.qpostconn = function(conn, ...)

companySecret <- ifelse(exists("companySecret") && !identical(companySecret, NULL), companySecret, "")
clientId <- ifelse(exists("clientId") && !identical(clientId, NULL), gsub("[^0-9]", "", clientId), "")
res <- try(POST(paste0("https://test.displayr.com/api/DataMart?filename=", filename),
res <- try(POST(paste0("https://app.displayr.com/api/DataMart?filename=", URLencode(filename, TRUE)),
config = add_headers("Content-Type" = guess_type(filename),
"X-Q-Company-Secret" = companySecret,
"X-Q-Project-ID" = clientId),
Expand All @@ -139,6 +142,7 @@ close.qpostconn = function(conn, ...)
#'
#' @importFrom httr GET add_headers write_disk
#' @importFrom tools file_ext
#' @importFrom utils URLencode
#'
#' @export
QLoadData <- function(filename)
Expand All @@ -149,7 +153,7 @@ QLoadData <- function(filename)
tmpfile <- tempfile()
companySecret <- ifelse(exists("companySecret") && !identical(companySecret, NULL), companySecret, "")
clientId <- ifelse(exists("clientId") && !identical(clientId, NULL), gsub("[^0-9]", "", clientId), "")
req <- try(GET(paste0("https://test.displayr.com/api/DataMart?filename=", filename),
req <- try(GET(paste0("https://app.displayr.com/api/DataMart?filename=", URLencode(filename, TRUE)),
config=add_headers("X-Q-Company-Secret" = companySecret,
"X-Q-Project-ID" = clientId),
write_disk(tmpfile, overwrite = TRUE)))
Expand Down Expand Up @@ -177,6 +181,7 @@ QLoadData <- function(filename)
#'
#' @importFrom httr POST add_headers upload_file
#' @importFrom tools file_ext
#' @importFrom utils URLencode
#'
#' @export
QSaveData <- function(object, filename)
Expand All @@ -193,7 +198,7 @@ QSaveData <- function(object, filename)

companySecret <- ifelse(exists("companySecret") && !identical(companySecret, NULL), companySecret, "")
clientId <- ifelse(exists("clientId") && !identical(clientId, NULL), gsub("[^0-9]", "", clientId), "")
res <- try(POST(paste0("https://test.displayr.com/api/DataMart?filename=", filename),
res <- try(POST(paste0("https://app.displayr.com/api/DataMart?filename=", URLencode(filename, TRUE)),
config = add_headers("Content-Type" = "application/x-gzip", # default is gzip for saveRDS
"X-Q-Company-Secret" = companySecret,
"X-Q-Project-ID" = clientId),
Expand Down

0 comments on commit 6195d9a

Please sign in to comment.