-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
consultas POST de georef API #13
Comments
basandome en el codigo para GET propongo: base_url <- "http://apis.datos.gob.ar/georef/api/"
post_endpoint <- function(endpoint, args) {
# Obtener el token de la variable de entorno
token <- Sys.getenv("GEOREFAR_TOKEN")
url <- paste0(base_url, endpoint)
load <- as.data.frame(x = args) %>%
list() %>%
setNames(., endpoint)
body <- jsonlite::toJSON(load, auto_unbox = T)
# Comprobar si el token está presente
if (is.null(token) | token == "") {
response <- httr::POST(url, body = body,
encode = "raw",
httr::add_headers("Content-Type" = "application/json")
)
} else {
response <- httr::POST(url, body = body,
encode = "raw",
httr::add_headers(Authorization = paste("Bearer",
token),
"Content-Type" = "application/json"))
}
check_status(response)
jsonlite::fromJSON(httr::content(response, "text"))[["resultados"]][endpoint] %>%
tidyr::unnest(cols = c(calles)) %>%
jsonlite::flatten(recursive = T) %>%
dplyr::rename_with(.fn = function(x) {gsub(pattern = "\\$|\\.", replacement = "_", x = x)}) %>%
suppressMessages()
}
#' Obtener Calles
post_calles <- function(id = NULL, nombre = NULL, tipo = NULL, provincia = NULL, departamento = NULL, aplanar = TRUE, campos = NULL, max = NULL, exacto = NULL){
args <- purrr::compact(list(id = id, nombre = nombre, tipo = tipo, provincia = provincia, departamento = departamento, aplanar = aplanar, campos = campos, max = max, exacto = exacto))
endpoint <- "calles"
check_internet()
post_endpoint(endpoint = endpoint, args = args)
}
|
@TuQmano @pdelboca estaba pensando que en vez de armar toda una nueva tanda de funciones
Tener:
¿qué les parece? |
A mi me gusta. Ver de no agregar muchas mas funciones exportables y que cada endpoint tenga un par segun param que defina el metodo. Ahi surgiría una decision:
|
|
Sería conveniente agregar funciones que faciliten las consultas por método POST a la API de georef-ar como mencionó @gonzaloazuaga2021 en #12 (comment)_
The text was updated successfully, but these errors were encountered: