blob: a890d3fade0d54d6e02fc32aa5c5cc3188920ef8 [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
Marc Kupietz5a519822019-09-20 21:43:52 +020013KorAPConnection <- setClass("KorAPConnection", slots=c(KorAPUrl="character", apiVersion="character", apiUrl="character", verbose="logical"))
Marc Kupietze95108e2019-09-18 13:23:58 +020014
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 Kupietz5a519822019-09-20 21:43:52 +020019#' @param verbose logical decides wether following operations will default to be verbose
Marc Kupietze95108e2019-09-18 13:23:58 +020020#' @return \code{\link{KorAPConnection}} object that can be used e.g. with \code{\link{corpusQuery}}
21#'
22#' @examples
Marc Kupietz5a519822019-09-20 21:43:52 +020023#' kcon <- new("KorAPConnection", verbose = TRUE)
Marc Kupietze95108e2019-09-18 13:23:58 +020024#' kq <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietz5a519822019-09-20 21:43:52 +020025#' kq <- fetchAll(kq)
Marc Kupietz7915dc42019-09-12 17:44:58 +020026#'
27#' @note Currently it is not possible to authenticate the client
28#'
Marc Kupietze95108e2019-09-18 13:23:58 +020029#' @rdname KorAPConnection-class
Marc Kupietz632cbd42019-09-06 16:04:51 +020030#' @export
Marc Kupietze95108e2019-09-18 13:23:58 +020031setMethod("initialize", "KorAPConnection",
Marc Kupietz5a519822019-09-20 21:43:52 +020032 function(.Object, KorAPUrl = "https://korap.ids-mannheim.de/", apiVersion = 'v1.0', apiUrl, verbose = FALSE) {
Marc Kupietze95108e2019-09-18 13:23:58 +020033 .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 Kupietz5a519822019-09-20 21:43:52 +020045 .Object@verbose = verbose
Marc Kupietze95108e2019-09-18 13:23:58 +020046 .Object
47 })
48
49#' @rdname KorAPConnection-class
50#' @param object KorAPConnection object
51#' @export
52setMethod("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