13 lines
749 B
R
13 lines
749 B
R
getStationInfo <- function(station, headers,infostat = "information-station",dpclim = "public/DPClim/v1/") {
|
|
# Assuming 'base' and 'dpclim' are defined externally; include 'infostat' parameter appropriately
|
|
url <- httr::modify_url(base, path = paste0(dpclim, infostat), query = list("id-station" = station))
|
|
response <- httr::GET(url, headers)
|
|
# Check if the request was successful
|
|
if (httr::http_status(response)$category == "Success") {
|
|
# Properly parsing the content as CSV by directly reading the response text
|
|
data <- read.csv(text = httr::content(response, as = "text"), sep = ";", header = TRUE)
|
|
return(data)
|
|
}
|
|
stop(sprintf("Failed to get station info from the API. Status code: %s", response$status_code))
|
|
}
|
|
|