Fix non-nullable API token
Change-Id: I2ed2090884f827a8930f921ce1841f69a32bcf36
diff --git a/R/KorAPConnection.R b/R/KorAPConnection.R
index d1f55aa..53fbc1c 100644
--- a/R/KorAPConnection.R
+++ b/R/KorAPConnection.R
@@ -1,3 +1,8 @@
+################################################################################
+# Use setClassUnion to define the unholy NULL-data union as a virtual class.
+################################################################################
+setClassUnion("characterOrNULL", c("character", "NULL"))
+
#' Class KorAPConnection
#'
#' \code{KorAPConnection} objects represent the connection to a KorAP server.
@@ -7,7 +12,7 @@
#' @import utils
#' @import methods
#' @export
-KorAPConnection <- setClass("KorAPConnection", slots=c(KorAPUrl="character", apiVersion="character", apiUrl="character", apiToken="character", userAgent="character", timeout="numeric", verbose="logical", cache="logical"))
+KorAPConnection <- setClass("KorAPConnection", slots=c(KorAPUrl="character", apiVersion="character", apiUrl="character", apiToken="characterOrNULL", userAgent="character", timeout="numeric", verbose="logical", cache="logical"))
#' @param .Object KorAPConnection object
#' @param KorAPUrl the URL of the KorAP server instance you want to access.
@@ -114,9 +119,11 @@
#' @import keyring
getApiToken <- function(KorAPUrl) {
- ifelse("keyring" %in% installed.packages()[,1 ]&& has_keyring_support()
- && KorAPUrl %in% key_list(service = "RKorAPClientAPIToken"),
- key_get("RKorAPClientAPIToken", KorAPUrl), NULL)
+ if ("keyring" %in% installed.packages()[,1 ]&& has_keyring_support()
+ && KorAPUrl %in% key_list(service = "RKorAPClientAPIToken"))
+ key_get("RKorAPClientAPIToken", KorAPUrl)
+ else
+ NULL
}
KorAPCacheSubDir <- function() {