blob: 4652927a09ee64f430edcdd5d68ced5fe77a6861 [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
13KorAPConnection <- function(KorAPUrl=defaultKorAPUrl, apiVersion='v1.0', apiUrl = NA) {
14 m <-regexpr("https?://[^?]+", KorAPUrl, perl = TRUE)
15 KorAPUrl <- regmatches(KorAPUrl, m)
16 if (!endsWith(KorAPUrl, '/')) {
17 KorAPUrl <- paste0(KorAPUrl, "/")
18 }
19 if (is.na(apiUrl)) {
20 apiUrl = paste0(KorAPUrl, 'api/', apiVersion, '/')
21 }
Marc Kupietz5bbc9db2019-08-30 16:30:45 +020022 con <- data.frame(apiUrl, KorAPUrl, apiVersion)
23 return(con)
24}