blob: 5ecd11ce90c706510ea8aa88e83020d370cd07c2 [file] [log] [blame]
Marc Kupietz5bbc9db2019-08-30 16:30:45 +02001#' @import jsonlite
2#' @import curl
3
Marc Kupietz5bbc9db2019-08-30 16:30:45 +02004defaultKorAPUrl <- "https://korap.ids-mannheim.de/"
5
Marc Kupietz7915dc42019-09-12 17:44:58 +02006#' Connect to a KorAP server.
Marc Kupietz632cbd42019-09-06 16:04:51 +02007#' @param KorAPUrl instead of providing the query and vc string parameters, you can also simply copy a KorAP query URL from your browser and use it here (and in \code{KorAPConnection}) to provide all necessary information for the query.
Marc Kupietz7915dc42019-09-12 17:44:58 +02008#' @return object that contains all connection information and can be used with \code{\link{KorAPQuery}}
9#'
10#' @note Currently it is not possible to authenticate the client
11#'
Marc Kupietz632cbd42019-09-06 16:04:51 +020012#' @export
Marc Kupietzf568f3f2019-09-16 17:03:46 +020013KorAPConnection <- function(KorAPUrl=defaultKorAPUrl, apiVersion='v1.0', apiUrl) {
Marc Kupietz632cbd42019-09-06 16:04:51 +020014 m <-regexpr("https?://[^?]+", KorAPUrl, perl = TRUE)
15 KorAPUrl <- regmatches(KorAPUrl, m)
16 if (!endsWith(KorAPUrl, '/')) {
17 KorAPUrl <- paste0(KorAPUrl, "/")
18 }
Marc Kupietzf568f3f2019-09-16 17:03:46 +020019 if (missing(apiUrl)) {
Marc Kupietz632cbd42019-09-06 16:04:51 +020020 apiUrl = paste0(KorAPUrl, 'api/', apiVersion, '/')
21 }
Marc Kupietz5bbc9db2019-08-30 16:30:45 +020022 con <- data.frame(apiUrl, KorAPUrl, apiVersion)
23 return(con)
24}