frostlyr_get.R 1.78 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#' frostlyr_get_data

#' frostlyr_get_data
#' @param x request object
#' @param username username
#' @param password password
#' @keywords frostlyr
#' @export
#' @examples
#' \dontrun{
#' frostlyr_get_data()
#' }
frostlyr_get_data <- function(x,username=NULL,password=NULL) {

  api <- frostr::api(httpauth = 1,userpwd=paste0(username,":",password))

  if (!is.null(x$stationObj$locationName)){
    meta <- frostlyr_get_meta(x=x,username=username,password=password)
    station_id <- meta$ID
  } else if (!is.null(x$stationObj$station_id)) {
    station_id <- x$stationObj$station_id
  }

  from <- timemanip::posixlt2char(x$timeObj$fromDateTime(),ISO8601=TRUE)
  to <- timemanip::posixlt2char(x$timeObj$toDateTime(),ISO8601=TRUE)
  referencetime <- paste0(from,"/",to)

  res <- frostr::get_short_data(frostObj=api,stations=station_id,referencetime=referencetime,elements=x$elementObj$element_id)

  return(res)
}

#' frostlyr_get_meta

#' frostlyr_get_meta
#' @param x request object
#' @param username username
#' @param password password
#' @keywords frostlyr
#' @export
#' @examples
#' \dontrun{
#' frostlyr_get_meta()
#' }
frostlyr_get_meta <- function(x,username=NULL,password=NULL) {
  api <- frostr::api(httpauth = 1,userpwd=paste0(username,":",password))
  res <- frostr::get_short_meta_station_with_element(frostObj=api,stations=x$stationObj$station_id,west=x$stationObj$west,south=x$stationObj$south,east=x$stationObj$east,north=x$stationObj$north,elements=x$elementObj$element_id)

  return(res)
}

#' frostlyr_get_qa

#' frostlyr_get_qa
#' @param x request object
#' @param username username
#' @param password password
#' @keywords frostlyr
#' @export
#' @examples
#' \dontrun{
#' frostlyr_get_qa()
#' }
frostlyr_get_qa <- function(x,username=NULL,password=NULL) {
  stop("qa gathering not implemented")
}