R/get_hotspots.R

Defines functions get_hotspots

Documented in get_hotspots

#' Returns dataframe of birding hotspots for a given region. Must enter the regions code for region, for example if you wanted hotspots
#' in the United States you would enter "region = `US`".
#'
#' @param key The users eBird key
#' @param region The region code for the desired region
#' @param back How many days back to collect data, default is 1
#'
#' @return subregions dataframe
#'
#' @importFrom httr GET add_headers
#' @importFrom jsonlite fromJSON
#' @importFrom glue glue
#'
#' @export
get_hotspots <- function(region, back = 1, key) {
  url <- glue("https://api.ebird.org/v2/ref/hotspot/{region}")
  hotspots <- GET(url,
                 add_headers("x-ebirdapitoken" = key),
                 query = list(back = back,
                              fmt = "json"))
  hotspots <- fromJSON(rawToChar(hotspots$content))
  hotspots
}
sjmarks/Birdr documentation built on May 12, 2020, 5:48 p.m.