Replace " UTC" and "-00" in all dates
To reflect Matomo and lubridate API changes (???)
Change-Id: I840fe1517b9aeb9fb8da9fd989cead1bdaca0a25
diff --git a/R/matomoquery.R b/R/matomoquery.R
index e530d4b..28ad2f0 100644
--- a/R/matomoquery.R
+++ b/R/matomoquery.R
@@ -22,6 +22,7 @@
#' @importFrom dplyr mutate rowwise bind_rows select summarise n
#' @import tibble
#' @importFrom magrittr %>%
+#' @importFrom stringr str_replace str_replace_all
#' @importFrom utils head tail
#'
#' @examples
@@ -50,7 +51,6 @@
call. = FALSE
)
}
-
httr::GET(
url = matomoUrl,
query = list(
@@ -58,7 +58,7 @@
method = getMethod,
format = "json",
idSite = paste0(siteId, collapse = ","),
- date = date,
+ date = str_replace_all(date, " *UTC", ""),
period = period,
filter_limit = filter_limit,
language = "de",
@@ -75,16 +75,18 @@
}
json <- httr::content(res, "text", encoding = "UTF-8")
-
+ warning(json)
l <- jsonlite::fromJSON(json)
+
if("result" %in% colnames(l) && l$result == 'error') {
stop(paste("in api call:", l$message), call. = FALSE)
}
if (period=="range") {
- df <- if (length(siteId) == 1) {
- l %>%
- mutate(site_id=siteId)
+ df <- if (is.list(l) && length(l) == 0) {
+ warning("API call returned an empty list.\n", call. = FALSE)
+ } else if (length(siteId) == 1) {
+ l %>% mutate(site_id=siteId)
} else {
bind_rows(jsonlite::fromJSON(json), .id = "site_id")
}