blob: 85b12e4df0dc1bbab6b347b99a12f9e9d61d44ab [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 Kupietz25aebc32019-09-16 18:40:50 +02008#'
Marc Kupietz632cbd42019-09-06 16:04:51 +02009#' @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 Kupietz25aebc32019-09-16 18:40:50 +020010#' @param apiVersion which version of KorAP's API you want to connect to
11#' @param apiUrl url of the KorAP web service
Marc Kupietz7915dc42019-09-12 17:44:58 +020012#' @return object that contains all connection information and can be used with \code{\link{KorAPQuery}}
13#'
14#' @note Currently it is not possible to authenticate the client
15#'
Marc Kupietz632cbd42019-09-06 16:04:51 +020016#' @export
Marc Kupietzf568f3f2019-09-16 17:03:46 +020017KorAPConnection <- function(KorAPUrl=defaultKorAPUrl, apiVersion='v1.0', apiUrl) {
Marc Kupietz632cbd42019-09-06 16:04:51 +020018 m <-regexpr("https?://[^?]+", KorAPUrl, perl = TRUE)
19 KorAPUrl <- regmatches(KorAPUrl, m)
20 if (!endsWith(KorAPUrl, '/')) {
21 KorAPUrl <- paste0(KorAPUrl, "/")
22 }
Marc Kupietzf568f3f2019-09-16 17:03:46 +020023 if (missing(apiUrl)) {
Marc Kupietz632cbd42019-09-06 16:04:51 +020024 apiUrl = paste0(KorAPUrl, 'api/', apiVersion, '/')
25 }
Marc Kupietz5bbc9db2019-08-30 16:30:45 +020026 con <- data.frame(apiUrl, KorAPUrl, apiVersion)
27 return(con)
28}