Skip to content

Commit

Permalink
ALS-7264: Update postJSON to be flexible with response type
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Sep 6, 2024
1 parent edd4981 commit 9d68bce
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions R/picsure.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ fetchResources <- function(session, resourceId = FALSE) {
#' @param body A string of JSON data to post to the service
#' @param responseDeserializer A function to deserialize the data returned. Default is deserializeJSON
#' @return a string containing the response from the request, or the result of responseDeserializer, if provided
postJSON <- function(session, path, body, responseDeserializer = deserializeJSON) {
postJSON <- function(session, path, body, responseDeserializer = deserializeJSON, acceptContentType = httr::accept_json()) {
full_url = paste(session$url_picsure, path, sep="")
response = httr::POST(full_url, body=body, httr::content_type_json(), httr::accept_json(), httr::add_headers(Authorization=paste('Bearer',session$token)))
response = httr::POST(full_url, body=body, httr::content_type_json(), acceptContentType, httr::add_headers(Authorization=paste('Bearer',session$token)))

if (response$status_code != 200) {
if (response$status_code == 401) {
Expand Down
4 changes: 2 additions & 2 deletions R/query.R
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ runQuery <- function(query, resultType = NULL) {
#' @export
getResultByQueryUUID <- function(session, queryUUID) {
queryJSON = "{}"
response = postJSON(session, paste("query/", queryUUID, "/result", sep=""), queryJSON, responseDeserializer = NULL)
response = postJSON(session, paste("query/", queryUUID, "/result", sep=""), queryJSON, responseDeserializer = NULL, acceptContentType = httr::accept("application/octet-stream"))
return(read.csv(text=response, sep=',', check.names=FALSE))
}

Expand Down Expand Up @@ -365,7 +365,7 @@ getCount = function(query) {

getResults = function(query) {
queryJSON = generateQueryJSON(query, expectedResultType = 'DATAFRAME')
response = postJSON(query$session, "query/sync/", queryJSON, responseDeserializer = NULL)
response = postJSON(query$session, "query/sync/", queryJSON, responseDeserializer = NULL, acceptContentType = httr::accept("application/octet-stream"))
return(read.csv(text=response, sep=',', check.names=FALSE))
}

Expand Down

0 comments on commit 9d68bce

Please sign in to comment.