get_timeseries.R 1.16 KB
Newer Older
Jean-Marie Lepioufle's avatar
Jean-Marie Lepioufle committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#' get_timeseries

#' get_timeseries
#' @param stationIDs stationIDs
#' @param componentName componentName
#' @param fromDateTime fromDateTime
#' @param toDateTime toDateTime
#' @param username username
#' @param password password
#' @keywords eipar
#' @export
#' @examples
#' \dontrun{
#' get_timeseries()
#' }
get_timeseries  <- function(stationIDs=NULL,componentName=NULL,fromDateTime=NULL,toDateTime=NULL,username,password){

    epoint <- endpoints_eipar(api="timeseries")

    url <- url_request(epoint=epoint,stationIDs=stationIDs,componentName=componentName,fromDateTime=fromDateTime,toDateTime=toDateTime)

    tmp <- httr::GET(url,httr::authenticate(user=username, password=password,type="basic"),httr::add_headers("user-agent"="eipar-r-package"))

    status_code <- tmp$status_code
    if (status_code == 200L) {
      tmp <- httr::content(tmp)
      res <- dplyr::bind_rows(lapply(tmp$'_items',function(x) data.frame(t(x))))
      res <- apply(res,2,function(x) unlist(as.character(x)))
      rm(tmp)
    } else res <- NULL


    res <- list(status_code = status_code,
                resp = res)


    class(res) <- c("eipar_get_timeseries",class(res))
    return(res)
}