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 |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame^] | 13 | KorAPConnection <- setClass("KorAPConnection", slots=c(KorAPUrl="character", apiVersion="character", apiUrl="character", verbose="logical")) |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 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. |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame^] | 19 | #' @param verbose logical decides wether following operations will default to be verbose |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 20 | #' @return \code{\link{KorAPConnection}} object that can be used e.g. with \code{\link{corpusQuery}} |
| 21 | #' |
| 22 | #' @examples |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame^] | 23 | #' kcon <- new("KorAPConnection", verbose = TRUE) |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 24 | #' kq <- corpusQuery(kcon, "Ameisenplage") |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame^] | 25 | #' kq <- fetchAll(kq) |
Marc Kupietz | 7915dc4 | 2019-09-12 17:44:58 +0200 | [diff] [blame] | 26 | #' |
| 27 | #' @note Currently it is not possible to authenticate the client |
| 28 | #' |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 29 | #' @rdname KorAPConnection-class |
Marc Kupietz | 632cbd4 | 2019-09-06 16:04:51 +0200 | [diff] [blame] | 30 | #' @export |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 31 | setMethod("initialize", "KorAPConnection", |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame^] | 32 | function(.Object, KorAPUrl = "https://korap.ids-mannheim.de/", apiVersion = 'v1.0', apiUrl, verbose = FALSE) { |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 33 | .Object <- callNextMethod() |
| 34 | m <- regexpr("https?://[^?]+", KorAPUrl, perl = TRUE) |
| 35 | .Object@KorAPUrl <- regmatches(KorAPUrl, m) |
| 36 | if (!endsWith(.Object@KorAPUrl, '/')) { |
| 37 | .Object@KorAPUrl <- paste0(.Object@KorAPUrl, "/") |
| 38 | } |
| 39 | if (missing(apiUrl)) { |
| 40 | .Object@apiUrl = paste0(.Object@KorAPUrl, 'api/', apiVersion, '/') |
| 41 | } else { |
| 42 | .Object@apiUrl = apiUrl |
| 43 | } |
| 44 | .Object@apiVersion = apiVersion |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame^] | 45 | .Object@verbose = verbose |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 46 | .Object |
| 47 | }) |
| 48 | |
| 49 | #' @rdname KorAPConnection-class |
| 50 | #' @param object KorAPConnection object |
| 51 | #' @export |
| 52 | setMethod("show", "KorAPConnection", function(object) { |
| 53 | cat("<KorAPConnection>", "\n") |
| 54 | cat("apiUrl: ", object@apiUrl, "\n") |
| 55 | }) |
| 56 | |
| 57 | #' Funtion KorAPConnection() |
| 58 | #' |
| 59 | #' Wrappper function for new("KorAPConnection") |
| 60 | #' |
| 61 | #' @rdname KorAPConnection-constructor |
| 62 | #' @name KorAPConnection-constructor |
| 63 | #' @export |
| 64 | # KorAPConnection <- function(...) new("KorAPConnection", ...) |
| 65 | |