Commit 22a9efad authored by Marek Ostaszewski's avatar Marek Ostaszewski
Browse files

Merge branch 'repo_update' into 'master'

updated ask_GET

See merge request !290
parents 925311bb 746aa04c
......@@ -16,7 +16,19 @@ ask_GET <- function(fask_url, verbose = F, encoding = "UTF-8") {
resp <- httr::GET(url = URLencode(fask_url),
httr::add_headers('Content-Type' = "application/x-www-form-urlencoded"))
if(httr::status_code(resp) == 200) {
return(httr::content(resp, as = "text", encoding = encoding))
### when the content is sent as a zip file, it needs to be handled differently,
### i.e. saved to a tmp file and unzipped
if(headers(resp)$`content-type` == "application/zip") {
tmp <- tempfile()
tmpc <- file(tmp, "wb")
writeBin(httr::content(resp, as = "raw"), con = tmpc)
close(tmpc)
unzipped <- unzip(tmp)
file.remove(tmp)
return(unzipped)
} else {
return(httr::content(resp, as = "text", encoding = encoding))
}
}
return(NULL)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment