blob: 84aec06abb53373241351974ffe0935f6799a672 [file] [log] [blame]
Marc Kupietze95108e2019-09-18 13:23:58 +02001#' Class KorAPConnection
Marc Kupietz25aebc32019-09-16 18:40:50 +02002#'
Marc Kupietze95108e2019-09-18 13:23:58 +02003#' \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
13KorAPConnection <- 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 Kupietz7915dc42019-09-12 17:44:58 +020025#'
26#' @note Currently it is not possible to authenticate the client
27#'
Marc Kupietze95108e2019-09-18 13:23:58 +020028#' @rdname KorAPConnection-class
Marc Kupietz632cbd42019-09-06 16:04:51 +020029#' @export
Marc Kupietze95108e2019-09-18 13:23:58 +020030setMethod("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
50setMethod("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