R/get_sensors.R

Defines functions get_sensors

Documented in get_sensors

#' Retrieve list of available sensors for given station from GIOS API
#'
#' @param stationId id of a station
#'
#' @return data.frame all sensors available for a given station
#'
#' @examples
#' \dontrun{
#' stations <- get_stations()
#' subset(stations, city.name == "Wrocław")
#' get_sensors(129)
#' }
#'
#' @export
get_sensors <- function(stationId){

  request = GET(url = paste("http://api.gios.gov.pl/pjp-api/rest/station/sensors/", stationId, sep=""))

  if(status_code(request) != 200){
    stop(paste("Problem z API:\n", http_status(request)$message))
  }

  sensors <- content(request)
  sensors <- lapply(sensors, function(x) t(data.frame(unlist(x))))
  sensors <- do.call(rbind.data.frame, sensors)
  rownames(sensors) <- NULL

  return(sensors)
}
psobczyk/giosAPI documentation built on May 26, 2019, 10:33 a.m.