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