~hrbrmstr/epidata

ref: e12c13d229ba5f2ca9a4300ed38971676e68b20f epidata/R/epi_query.r -rw-r--r-- 527 bytes
e12c13d2hrbrmstr fixed CRAN checks; added 4 new functions; added UA 1 year, 7 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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/wordpress/wp-admin/admin-ajax.php",
    httr::add_headers(`X-Requested-With`="XMLHttpRequest"),
    .EPIDATA_UA,
    encode = "form",
    body = list(
      action = "epi_getdata",
      queryString = qs
    )
  ) -> res

  httr::stop_for_status(res)

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

}