~hrbrmstr/epidata

ref: b99e51f6d2da14a0131119506974dde735e6adb1 epidata/R/epi_query.r -rw-r--r-- 473 bytes
b99e51f6boB Rudis v0.2.0 is on CRAN\! 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Do the hard work of formatting the parameters and issuing the query
epi_query <- function(args) {

  qs <- paste(sprintf("%s=%s", names(args), args), collapse="&")

  httr::POST(
    "https://www.epi.org/wp-admin/admin-ajax.php",
    httr::add_headers(`X-Requested-With`="XMLHttpRequest"),
    encode="form",
    body=list(action="epi_getdata", queryString = qs)) -> res

  httr::stop_for_status(res)

  jsonlite::fromJSON(httr::content(res, as="text"), flatten=TRUE)

}