blob: 4c75799d247d5f0bd25fbcf555e5cd8a5cfa535a [file] [log] [blame]
Marc Kupietze95108e2019-09-18 13:23:58 +02001% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/KorAPConnection.R
3\docType{class}
4\name{KorAPConnection-class}
5\alias{KorAPConnection-class}
6\alias{KorAPConnection}
7\alias{initialize,KorAPConnection-method}
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +02008\alias{apiCall,KorAPConnection-method}
9\alias{apiCall}
Marc Kupietz0a96b282019-10-01 11:05:31 +020010\alias{clearCache,KorAPConnection-method}
11\alias{clearCache}
Marc Kupietze95108e2019-09-18 13:23:58 +020012\alias{show,KorAPConnection-method}
13\title{Class KorAPConnection}
14\usage{
Marc Kupietz76685f52019-11-25 17:46:06 +010015\S4method{initialize}{KorAPConnection}(
16 .Object,
17 KorAPUrl = "https://korap.ids-mannheim.de/",
18 apiVersion = "v1.0",
19 apiUrl,
Marc Kupietzb956b812019-11-25 17:53:13 +010020 accessToken = getAccessToken(KorAPUrl),
Marc Kupietz76685f52019-11-25 17:46:06 +010021 userAgent = "R-KorAP-Client",
Marc Kupietz6a3185b2021-12-07 10:23:16 +010022 timeout = 240,
Marc Kupietz76685f52019-11-25 17:46:06 +010023 verbose = FALSE,
24 cache = TRUE
25)
Marc Kupietz4862b862019-11-07 10:13:53 +010026
Marc Kupietza4675722022-02-23 23:55:15 +010027\S4method{apiCall}{KorAPConnection}(
28 kco,
29 url,
30 json = TRUE,
31 getHeaders = FALSE,
32 cache = kco@cache,
33 timeout = kco@timeout
34)
Marc Kupietze95108e2019-09-18 13:23:58 +020035
Marc Kupietz0a96b282019-10-01 11:05:31 +020036\S4method{clearCache}{KorAPConnection}(kco)
37
Marc Kupietze95108e2019-09-18 13:23:58 +020038\S4method{show}{KorAPConnection}(object)
39}
40\arguments{
41\item{.Object}{KorAPConnection object}
42
Marc Kupietza81343d2022-09-06 12:32:10 +020043\item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access.}
Marc Kupietze95108e2019-09-18 13:23:58 +020044
45\item{apiVersion}{which version of KorAP's API you want to connect to.}
46
47\item{apiUrl}{URL of the KorAP web service.}
48
Marc Kupietz132f0052023-04-16 14:23:05 +020049\item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted
50access (e.g. textual queries on IPR protected data), you need to authorize
51your application with an access token.
Marc Kupietza4f51d72025-01-25 16:23:18 +010052You can obtain an access token using the \code{\link[=auth]{auth()}} method.
53
54More details are explained in the
Marc Kupietz132f0052023-04-16 14:23:05 +020055\href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section}
56of the RKorAPClient Readme on GitHub.
57
58To use authorization based on an access token
59in subsequent queries, initialize your KorAP connection with:
60
61\if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- new("KorAPConnection", accessToken="<access token>")
62}\if{html}{\out{</div>}}
63
Marc Kupietz4862b862019-11-07 10:13:53 +010064In order to make the API
65token persistent for the currently used \code{KorAPUrl} (you can have one
Marc Kupietz132f0052023-04-16 14:23:05 +020066token per KorAPUrl / KorAP server instance), use:
67
68\if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco)
69}\if{html}{\out{</div>}}
70
71This will store it in your keyring using the
Marc Kupietz6a02e4c2025-01-09 21:22:30 +010072\link[keyring:keyring-package]{keyring::keyring-package}. Subsequent new("KorAPConnection") calls will
Marc Kupietz4862b862019-11-07 10:13:53 +010073then automatically retrieve the token from your keying. To stop using a
Marc Kupietzb956b812019-11-25 17:53:13 +010074persisted token, call \code{clearAccessToken(kco)}. Please note that for
Marc Kupietz4862b862019-11-07 10:13:53 +010075DeReKo, authorized queries will behave differently inside and outside the
76IDS, because of the special license situation. This concerns also cached
77results which do not take into account from where a request was issued. If
Marc Kupietz67edcb52021-09-20 21:54:24 +020078you experience problems or unexpected results, please try \code{kco <- new("KorAPConnection", cache=FALSE)} or use
79\code{\link[=clearCache]{clearCache()}} to clear the cache completely.}
Marc Kupietz4862b862019-11-07 10:13:53 +010080
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020081\item{userAgent}{user agent string.}
82
Marc Kupietza81343d2022-09-06 12:32:10 +020083\item{timeout}{tineout in seconds for API requests (this does not influence server internal timeouts).}
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020084
Marc Kupietza81343d2022-09-06 12:32:10 +020085\item{verbose}{logical that decides whether following operations will default to
Marc Kupietz4862b862019-11-07 10:13:53 +010086be verbose.}
Marc Kupietz5a519822019-09-20 21:43:52 +020087
Marc Kupietza81343d2022-09-06 12:32:10 +020088\item{cache}{logical that decides if API calls are cached locally. You can clear
Marc Kupietz67edcb52021-09-20 21:54:24 +020089the cache with \code{\link[=clearCache]{clearCache()}}.}
Marc Kupietz0a96b282019-10-01 11:05:31 +020090
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020091\item{kco}{KorAPConnection object}
92
93\item{url}{request url}
94
Marc Kupietzf9129592025-01-26 19:17:54 +010095\item{json}{logical that determines if JSON result is expected}
Marc Kupietzb2b32a32020-03-24 13:56:50 +010096
Marc Kupietzb49afa02020-06-04 15:50:29 +020097\item{getHeaders}{logical that determines if headers and content should be returned (as a list)}
98
Marc Kupietze95108e2019-09-18 13:23:58 +020099\item{object}{KorAPConnection object}
100}
101\value{
Marc Kupietz67edcb52021-09-20 21:54:24 +0200102\code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with
103\code{\link[=corpusQuery]{corpusQuery()}}
Marc Kupietze95108e2019-09-18 13:23:58 +0200104}
105\description{
Marc Kupietz7776dec2019-09-27 16:59:02 +0200106\code{KorAPConnection} objects represent the connection to a KorAP server.
Marc Kupietz7715e9d2019-11-08 15:59:58 +0100107New \code{KorAPConnection} objects can be created by \code{new("KorAPConnection")}.
Marc Kupietze95108e2019-09-18 13:23:58 +0200108}
Marc Kupietza81343d2022-09-06 12:32:10 +0200109\section{Slots}{
110
111\describe{
112\item{\code{KorAPUrl}}{URL of the web user interface of the KorAP server used in the connection.}
113
114\item{\code{apiVersion}}{requested KorAP API version.}
115
116\item{\code{indexRevision}}{indexRevision code as reported from API via \code{X-Index-Revision} HTTP header.}
117
118\item{\code{apiUrl}}{full URL of API including version.}
119
120\item{\code{accessToken}}{OAuth2 access token.}
121
122\item{\code{userAgent}}{user agent string used for connection the API.}
123
124\item{\code{timeout}}{tineout in seconds for API requests (this does not influence server internal timeouts)}
125
126\item{\code{verbose}}{logical that decides whether operations will default to be verbose.}
127
128\item{\code{cache}}{logical that decides if API calls are cached locally.}
129
130\item{\code{welcome}}{list containing HTTP response received from KorAP server welcome function.}
131}}
132
Marc Kupietze95108e2019-09-18 13:23:58 +0200133\examples{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200134\dontrun{
135
Marc Kupietz5a519822019-09-20 21:43:52 +0200136kcon <- new("KorAPConnection", verbose = TRUE)
Marc Kupietze95108e2019-09-18 13:23:58 +0200137kq <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietz5a519822019-09-20 21:43:52 +0200138kq <- fetchAll(kq)
Marc Kupietz05b22772020-02-18 21:58:42 +0100139}
Marc Kupietze95108e2019-09-18 13:23:58 +0200140
Marc Kupietz4862b862019-11-07 10:13:53 +0100141\dontrun{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200142
Marc Kupietzb956b812019-11-25 17:53:13 +0100143kcon <- new("KorAPConnection", verbose = TRUE, accessToken="e739u6eOzkwADQPdVChxFg")
Marc Kupietz4862b862019-11-07 10:13:53 +0100144kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly=FALSE)
145kq <- fetchAll(kq)
146kq@collectedMatches$snippet
147}
148
Marc Kupietze95108e2019-09-18 13:23:58 +0200149}