Marc Kupietz | 5bbc9db | 2019-08-30 16:30:45 +0200 | [diff] [blame] | 1 | #' @import jsonlite |
| 2 | #' @import curl |
| 3 | |
Marc Kupietz | 5bbc9db | 2019-08-30 16:30:45 +0200 | [diff] [blame] | 4 | defaultKorAPUrl <- "https://korap.ids-mannheim.de/" |
| 5 | |
Marc Kupietz | 7915dc4 | 2019-09-12 17:44:58 +0200 | [diff] [blame] | 6 | #' Connect to a KorAP server. |
Marc Kupietz | 632cbd4 | 2019-09-06 16:04:51 +0200 | [diff] [blame] | 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. |
Marc Kupietz | 7915dc4 | 2019-09-12 17:44:58 +0200 | [diff] [blame] | 8 | #' @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 Kupietz | 632cbd4 | 2019-09-06 16:04:51 +0200 | [diff] [blame] | 12 | #' @export |
Marc Kupietz | f568f3f | 2019-09-16 17:03:46 +0200 | [diff] [blame^] | 13 | KorAPConnection <- function(KorAPUrl=defaultKorAPUrl, apiVersion='v1.0', apiUrl) { |
Marc Kupietz | 632cbd4 | 2019-09-06 16:04:51 +0200 | [diff] [blame] | 14 | m <-regexpr("https?://[^?]+", KorAPUrl, perl = TRUE) |
| 15 | KorAPUrl <- regmatches(KorAPUrl, m) |
| 16 | if (!endsWith(KorAPUrl, '/')) { |
| 17 | KorAPUrl <- paste0(KorAPUrl, "/") |
| 18 | } |
Marc Kupietz | f568f3f | 2019-09-16 17:03:46 +0200 | [diff] [blame^] | 19 | if (missing(apiUrl)) { |
Marc Kupietz | 632cbd4 | 2019-09-06 16:04:51 +0200 | [diff] [blame] | 20 | apiUrl = paste0(KorAPUrl, 'api/', apiVersion, '/') |
| 21 | } |
Marc Kupietz | 5bbc9db | 2019-08-30 16:30:45 +0200 | [diff] [blame] | 22 | con <- data.frame(apiUrl, KorAPUrl, apiVersion) |
| 23 | return(con) |
| 24 | } |