R/getIndicators.R

Defines functions getIndicators

Documented in getIndicators

#' List the indicators that the user is permitted to alter
#'
#' Based on access to the Nature Index database through a token generated by
#' \code{getToken}, this function lists the indicators (ID and names) that the user
#' is responsible for
#'
#' @encoding UTF-8
#' @author Jens Åström
#' @name getIndicators
#'
#' @import httr
#' @importFrom plyr ldply
#'
#' @return A data frame containing indicator IDs and names.
#' The indicator IDs are entered as parameters to the function \code{getIndicatorValues}
#' in order to retrieve the current values for a given indicator.
#'
#' @seealso \code{\link{getIndicatorValues}} and \code{\link{getToken}}.
#'
#' @examples
#' \dontrun{
#' getIndicators()
#' }
#'
#' @export
#'


getIndicators <- function() {

  url = .url
  token = .niToken
  indicator_path <- "/Indicators"
  combinedURL <- paste0(url, indicator_path)

  httr::set_config(httr::config(ssl_verifypeer = 0L)) #Fix "Peer certificate error"

  auth_string <- paste("bearer", token, sep = " ")

  myIndicators <- httr::GET(url = combinedURL,
                            encode = "json",
                            httr::add_headers(Authorization = auth_string))

  rawContent <- httr::content(myIndicators, as = "parsed")

  indicators <- plyr::ldply(rawContent, data.frame, stringsAsFactors = F)

  return(indicators)

}
NINAnor/NIcalc documentation built on Oct. 26, 2023, 9:37 a.m.