diff --git a/R/archive.R b/R/archive.R index 7fad533..8f9609a 100644 --- a/R/archive.R +++ b/R/archive.R @@ -1,12 +1,12 @@ # client for archive.opensensemap.org # in this archive, CSV files for measurements of each sensor per day is provided. +default_archive_url = 'https://archive.opensensemap.org/' + #' Returns the default endpoint for the archive *download* #' While the front end domain is archive.opensensemap.org, file downloads #' are provided via sciebo. -osem_archive_endpoint = function () { - 'https://uni-muenster.sciebo.de/index.php/s/HyTbguBP4EkqBcp/download?path=/data' -} +osem_archive_endpoint = function () default_archive_url #' Fetch day-wise measurements for a single box from the openSenseMap archive. #' @@ -93,6 +93,8 @@ osem_measurements_archive.sensebox = function (x, fromDate, toDate = fromDate, s #' @param progress whether to print progress #' @return A \code{tbl_df} containing observations of all selected sensors for each time stamp. archive_fetch_measurements = function (box, sensorId, fromDate, toDate, progress) { + osem_ensure_archive_available() + dates = list() from = fromDate while (from <= toDate) { @@ -150,3 +152,22 @@ osem_box_to_archivename = function (box) { name = gsub('[^A-Za-z0-9._-]', '_', box$name) paste(box$X_id, name, sep = '-') } + +#' Check if the given openSenseMap archive endpoint is available +#' @param endpoint The archive base URL to check, defaulting to \code{\link{osem_archive_endpoint}} +#' @return \code{TRUE} if the archive is available, otherwise \code{stop()} is called. +osem_ensure_archive_available = function(endpoint = osem_archive_endpoint()) { + code = FALSE + try({ + code = httr::status_code(httr::GET(endpoint)) + }, silent = TRUE) + + if (code == 200) + return(TRUE) + + errtext = paste('The archive at', endpoint, 'is currently not available.') + if (code != FALSE) + errtext = paste0(errtext, ' (HTTP code ', code, ')') + stop(paste(errtext, collapse='\n '), call. = FALSE) + FALSE +} \ No newline at end of file diff --git a/man/osem_ensure_archive_available.Rd b/man/osem_ensure_archive_available.Rd new file mode 100644 index 0000000..3b6b8c3 --- /dev/null +++ b/man/osem_ensure_archive_available.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/archive.R +\name{osem_ensure_archive_available} +\alias{osem_ensure_archive_available} +\title{Check if the given openSenseMap archive endpoint is available} +\usage{ +osem_ensure_archive_available(endpoint = osem_archive_endpoint()) +} +\arguments{ +\item{endpoint}{The archive base URL to check, defaulting to \code{\link{osem_archive_endpoint}}} +} +\value{ +\code{TRUE} if the archive is available, otherwise \code{stop()} is called. +} +\description{ +Check if the given openSenseMap archive endpoint is available +}