Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 1 | #' Class KorAPConnection |
Marc Kupietz | 25aebc3 | 2019-09-16 18:40:50 +0200 | [diff] [blame] | 2 | #' |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 3 | #' \code{KorAPConnection} objetcs represent the connection to a KorAP server. |
| 4 | #' New \code{KorAPConnection} objects can be created by \code{KorAPConnection()} |
| 5 | #' |
| 6 | #' @import jsonlite |
| 7 | #' @import utils |
| 8 | #' @import methods |
| 9 | #' |
| 10 | #' |
| 11 | |
| 12 | #' @export |
| 13 | KorAPConnection <- setClass("KorAPConnection", slots=c(KorAPUrl="character", apiVersion="character", apiUrl="character")) |
| 14 | |
| 15 | #' @param .Object KorAPConnection object |
| 16 | #' @param KorAPUrl the URL of the KorAP server instance you want to access. |
| 17 | #' @param apiVersion which version of KorAP's API you want to connect to. |
| 18 | #' @param apiUrl URL of the KorAP web service. |
| 19 | #' @return \code{\link{KorAPConnection}} object that can be used e.g. with \code{\link{corpusQuery}} |
| 20 | #' |
| 21 | #' @examples |
| 22 | #' kcon <- new("KorAPConnection") |
| 23 | #' kq <- corpusQuery(kcon, "Ameisenplage") |
| 24 | #' kq <- fetchAll(kq, verbose=TRUE) |
Marc Kupietz | 7915dc4 | 2019-09-12 17:44:58 +0200 | [diff] [blame] | 25 | #' |
| 26 | #' @note Currently it is not possible to authenticate the client |
| 27 | #' |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 28 | #' @rdname KorAPConnection-class |
Marc Kupietz | 632cbd4 | 2019-09-06 16:04:51 +0200 | [diff] [blame] | 29 | #' @export |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 30 | setMethod("initialize", "KorAPConnection", |
| 31 | function(.Object, KorAPUrl = "https://korap.ids-mannheim.de/", apiVersion = 'v1.0', apiUrl) { |
| 32 | .Object <- callNextMethod() |
| 33 | m <- regexpr("https?://[^?]+", KorAPUrl, perl = TRUE) |
| 34 | .Object@KorAPUrl <- regmatches(KorAPUrl, m) |
| 35 | if (!endsWith(.Object@KorAPUrl, '/')) { |
| 36 | .Object@KorAPUrl <- paste0(.Object@KorAPUrl, "/") |
| 37 | } |
| 38 | if (missing(apiUrl)) { |
| 39 | .Object@apiUrl = paste0(.Object@KorAPUrl, 'api/', apiVersion, '/') |
| 40 | } else { |
| 41 | .Object@apiUrl = apiUrl |
| 42 | } |
| 43 | .Object@apiVersion = apiVersion |
| 44 | .Object |
| 45 | }) |
| 46 | |
| 47 | #' @rdname KorAPConnection-class |
| 48 | #' @param object KorAPConnection object |
| 49 | #' @export |
| 50 | setMethod("show", "KorAPConnection", function(object) { |
| 51 | cat("<KorAPConnection>", "\n") |
| 52 | cat("apiUrl: ", object@apiUrl, "\n") |
| 53 | }) |
| 54 | |
| 55 | #' Funtion KorAPConnection() |
| 56 | #' |
| 57 | #' Wrappper function for new("KorAPConnection") |
| 58 | #' |
| 59 | #' @rdname KorAPConnection-constructor |
| 60 | #' @name KorAPConnection-constructor |
| 61 | #' @export |
| 62 | # KorAPConnection <- function(...) new("KorAPConnection", ...) |
| 63 | |