Replace " UTC" and "-00" in all dates
To reflect Matomo and lubridate API changes (???)
Change-Id: I840fe1517b9aeb9fb8da9fd989cead1bdaca0a25
diff --git a/Changelog.md b/Changelog.md
index aa4fabc..fd952d1 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -4,6 +4,7 @@
* improve error handling:
* show error if token is empty
* pass all errors reported by the API to the user
+* replace " UTC" with "" and "-00" with "-01" in all dates
## 0.1.9000
* adds function `getUserCountry`
diff --git a/DESCRIPTION b/DESCRIPTION
index c01bfb7..954d79d 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -22,6 +22,7 @@
lubridate,
jsonlite,
keyring,
+ stringr,
utils,
httr,
Suggests:
diff --git a/NAMESPACE b/NAMESPACE
index 144768c..5840a09 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -30,6 +30,8 @@
importFrom(jsonlite,fromJSON)
importFrom(lubridate,year)
importFrom(magrittr,"%>%")
+importFrom(stringr,str_replace)
+importFrom(stringr,str_replace_all)
importFrom(tibble,as_tibble)
importFrom(tibble,rownames_to_column)
importFrom(tidyr,complete)
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")
}
diff --git a/R/usercountry.R b/R/usercountry.R
index 9eb3638..0ea414c 100644
--- a/R/usercountry.R
+++ b/R/usercountry.R
@@ -6,6 +6,8 @@
#'
#' @inheritParams matomoQuery
#'
+#' @importFrom stringr str_replace str_replace_all
+#'
#' @examples
#' \dontrun{
#' df <- getUserCountry("https://demo.matomo.org/", siteId=3, period="day", date="last60")
@@ -22,7 +24,7 @@
matomoQuery(matomoUrl = matomoUrl,
siteId = siteId,
period = period,
- date = date,
+ date = str_replace_all(str_replace_all(date, " *UTC", ""), "-00", "-01"),
removeFirst = FALSE,
removeLast = FALSE,
accessToken = accessToken,