R/meta.R

Defines functions eccc_queryables eccc_collections

Documented in eccc_collections eccc_queryables

#' eccc_collections
#' @description Lists collections available for query via the ECCC Geomet API
#' @return \code{tibble} containing collection titles and ids
#' @export
#' @examples
#' eccc_collections()
#'
eccc_collections <- function(){
  req <- eccc_request(path = "collections")

  dplyr::tibble(
    collection = req$content$collections$title,
    collection_id = req$content$collections$id
  )
}

#' eccc_queryables
#'
#' @description Provides queryable parameters for API requests
#' @param collection Which collection to get informatio for.
#' See \code{eccc_collections}
#' @return \code{tibble} containing possible queryables and their expected type
#' @export
#' @examples
#' eccc_queryables("hydrometric-stations")
#'
eccc_queryables <- function(collection){
  query_path <- paste0("/collections/", collection, "/queryables")

  req <- eccc_request(path = query_path)

  parsed_req <- req$content$properties

  purrr::map_df(
    parsed_req,
    ~{
      dplyr::tibble(queryable = .x$title, type = .x$type)
    }
  )

}
rywhale/ecccgeometR documentation built on Dec. 22, 2021, 8:19 p.m.