blob: 4959e45a5d2738a7ab12e152c6f096d4686452a0 [file] [log] [blame]
Marc Kupietz5bbc9db2019-08-30 16:30:45 +02001#' @import jsonlite
2#' @import curl
Marc Kupietzd235a712019-09-16 18:31:33 +02003#' @import utils
Marc Kupietz5bbc9db2019-08-30 16:30:45 +02004
Marc Kupietz5bbc9db2019-08-30 16:30:45 +02005defaultKorAPUrl <- "https://korap.ids-mannheim.de/"
6
Marc Kupietz7915dc42019-09-12 17:44:58 +02007#' Connect to a KorAP server.
Marc Kupietz632cbd42019-09-06 16:04:51 +02008#' @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 +02009#' @return object that contains all connection information and can be used with \code{\link{KorAPQuery}}
10#'
11#' @note Currently it is not possible to authenticate the client
12#'
Marc Kupietz632cbd42019-09-06 16:04:51 +020013#' @export
Marc Kupietzf568f3f2019-09-16 17:03:46 +020014KorAPConnection <- function(KorAPUrl=defaultKorAPUrl, apiVersion='v1.0', apiUrl) {
Marc Kupietz632cbd42019-09-06 16:04:51 +020015 m <-regexpr("https?://[^?]+", KorAPUrl, perl = TRUE)
16 KorAPUrl <- regmatches(KorAPUrl, m)
17 if (!endsWith(KorAPUrl, '/')) {
18 KorAPUrl <- paste0(KorAPUrl, "/")
19 }
Marc Kupietzf568f3f2019-09-16 17:03:46 +020020 if (missing(apiUrl)) {
Marc Kupietz632cbd42019-09-06 16:04:51 +020021 apiUrl = paste0(KorAPUrl, 'api/', apiVersion, '/')
22 }
Marc Kupietz5bbc9db2019-08-30 16:30:45 +020023 con <- data.frame(apiUrl, KorAPUrl, apiVersion)
24 return(con)
25}