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 | 25aebc3 | 2019-09-16 18:40:50 +0200 | [diff] [blame^] | 8 | #' |
Marc Kupietz | 632cbd4 | 2019-09-06 16:04:51 +0200 | [diff] [blame] | 9 | #' @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 | 25aebc3 | 2019-09-16 18:40:50 +0200 | [diff] [blame^] | 10 | #' @param apiVersion which version of KorAP's API you want to connect to |
| 11 | #' @param apiUrl url of the KorAP web service |
Marc Kupietz | 7915dc4 | 2019-09-12 17:44:58 +0200 | [diff] [blame] | 12 | #' @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 Kupietz | 632cbd4 | 2019-09-06 16:04:51 +0200 | [diff] [blame] | 16 | #' @export |
Marc Kupietz | f568f3f | 2019-09-16 17:03:46 +0200 | [diff] [blame] | 17 | KorAPConnection <- function(KorAPUrl=defaultKorAPUrl, apiVersion='v1.0', apiUrl) { |
Marc Kupietz | 632cbd4 | 2019-09-06 16:04:51 +0200 | [diff] [blame] | 18 | m <-regexpr("https?://[^?]+", KorAPUrl, perl = TRUE) |
| 19 | KorAPUrl <- regmatches(KorAPUrl, m) |
| 20 | if (!endsWith(KorAPUrl, '/')) { |
| 21 | KorAPUrl <- paste0(KorAPUrl, "/") |
| 22 | } |
Marc Kupietz | f568f3f | 2019-09-16 17:03:46 +0200 | [diff] [blame] | 23 | if (missing(apiUrl)) { |
Marc Kupietz | 632cbd4 | 2019-09-06 16:04:51 +0200 | [diff] [blame] | 24 | apiUrl = paste0(KorAPUrl, 'api/', apiVersion, '/') |
| 25 | } |
Marc Kupietz | 5bbc9db | 2019-08-30 16:30:45 +0200 | [diff] [blame] | 26 | con <- data.frame(apiUrl, KorAPUrl, apiVersion) |
| 27 | return(con) |
| 28 | } |