blob: 469f22811aa6fd5658537626ae0eaa3ae872abe1 [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 Kupietz632cbd42019-09-06 16:04:51 +02006#' \code{KorAPQuery} initiates a connect to some KorAP server.
7#' @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.
8#' @return object that contains all necessary connection information and can be used on \code{\link{KorAPQuery}}
9#' @export
10KorAPConnection <- function(KorAPUrl=defaultKorAPUrl, apiVersion='v1.0', apiUrl = NA) {
11 m <-regexpr("https?://[^?]+", KorAPUrl, perl = TRUE)
12 KorAPUrl <- regmatches(KorAPUrl, m)
13 if (!endsWith(KorAPUrl, '/')) {
14 KorAPUrl <- paste0(KorAPUrl, "/")
15 }
16 if (is.na(apiUrl)) {
17 apiUrl = paste0(KorAPUrl, 'api/', apiVersion, '/')
18 }
Marc Kupietz5bbc9db2019-08-30 16:30:45 +020019 con <- data.frame(apiUrl, KorAPUrl, apiVersion)
20 return(con)
21}