blob: 46032b93d7b25b315ccd16e0fe338c03a280b731 [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,
Marc Kupietzb79fd442025-03-26 10:25:03 +010017 KorAPUrl = if (is.null(Sys.getenv("KORAP_URL") | Sys.getenv("KORAP_URL") == ""))
18 "https://korap.ids-mannheim.de/" else Sys.getenv("KORAP_URL"),
Marc Kupietz76685f52019-11-25 17:46:06 +010019 apiVersion = "v1.0",
20 apiUrl,
Marc Kupietzb956b812019-11-25 17:53:13 +010021 accessToken = getAccessToken(KorAPUrl),
Marc Kupietzf83d59a2025-02-01 14:48:30 +010022 oauthClient = NULL,
23 oauthScope = "search match_info",
Marc Kupietz62b17892025-02-01 18:26:45 +010024 authorizationSupported = TRUE,
Marc Kupietz76685f52019-11-25 17:46:06 +010025 userAgent = "R-KorAP-Client",
Marc Kupietz6a3185b2021-12-07 10:23:16 +010026 timeout = 240,
Marc Kupietz76685f52019-11-25 17:46:06 +010027 verbose = FALSE,
28 cache = TRUE
29)
Marc Kupietz4862b862019-11-07 10:13:53 +010030
Marc Kupietza4675722022-02-23 23:55:15 +010031\S4method{apiCall}{KorAPConnection}(
32 kco,
33 url,
34 json = TRUE,
35 getHeaders = FALSE,
36 cache = kco@cache,
37 timeout = kco@timeout
38)
Marc Kupietze95108e2019-09-18 13:23:58 +020039
Marc Kupietz0a96b282019-10-01 11:05:31 +020040\S4method{clearCache}{KorAPConnection}(kco)
41
Marc Kupietze95108e2019-09-18 13:23:58 +020042\S4method{show}{KorAPConnection}(object)
43}
44\arguments{
45\item{.Object}{KorAPConnection object}
46
Marc Kupietzb79fd442025-03-26 10:25:03 +010047\item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access.
48Defaults to the environment variable \code{KORAP_URL} if set and to the IDS Mannheim KorAP main instance,
49otherwise.}
Marc Kupietze95108e2019-09-18 13:23:58 +020050
51\item{apiVersion}{which version of KorAP's API you want to connect to.}
52
53\item{apiUrl}{URL of the KorAP web service.}
54
Marc Kupietz132f0052023-04-16 14:23:05 +020055\item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted
56access (e.g. textual queries on IPR protected data), you need to authorize
57your application with an access token.
Marc Kupietz62b17892025-02-01 18:26:45 +010058You can obtain an access token in the OAuth settings of your KorAP web interface.
Marc Kupietza4f51d72025-01-25 16:23:18 +010059
60More details are explained in the
Marc Kupietz132f0052023-04-16 14:23:05 +020061\href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section}
62of the RKorAPClient Readme on GitHub.
63
64To use authorization based on an access token
65in subsequent queries, initialize your KorAP connection with:
66
Marc Kupietz617266d2025-02-27 10:43:07 +010067\if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- KorAPConnection(accessToken="<access token>")
Marc Kupietz132f0052023-04-16 14:23:05 +020068}\if{html}{\out{</div>}}
69
Marc Kupietz4862b862019-11-07 10:13:53 +010070In order to make the API
71token persistent for the currently used \code{KorAPUrl} (you can have one
Marc Kupietz132f0052023-04-16 14:23:05 +020072token per KorAPUrl / KorAP server instance), use:
73
74\if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco)
75}\if{html}{\out{</div>}}
76
77This will store it in your keyring using the
Marc Kupietz617266d2025-02-27 10:43:07 +010078\link[keyring:keyring-package]{keyring::keyring-package}. Subsequent KorAPConnection() calls will
Marc Kupietz4862b862019-11-07 10:13:53 +010079then automatically retrieve the token from your keying. To stop using a
Marc Kupietzb956b812019-11-25 17:53:13 +010080persisted token, call \code{clearAccessToken(kco)}. Please note that for
Marc Kupietz4862b862019-11-07 10:13:53 +010081DeReKo, authorized queries will behave differently inside and outside the
82IDS, because of the special license situation. This concerns also cached
83results which do not take into account from where a request was issued. If
Marc Kupietz617266d2025-02-27 10:43:07 +010084you experience problems or unexpected results, please try \code{kco <- KorAPConnection(cache=FALSE)} or use
Marc Kupietzf83d59a2025-02-01 14:48:30 +010085\code{\link[=clearCache]{clearCache()}} to clear the cache completely.
86
87An alternative to using an access token is to use a browser-based oauth2 workflow
88to obtain an access token. This can be done with the \code{\link[=auth]{auth()}} method.}
89
90\item{oauthClient}{OAuth2 client object.}
91
92\item{oauthScope}{OAuth2 scope.}
93
Marc Kupietz62b17892025-02-01 18:26:45 +010094\item{authorizationSupported}{logical that indicates if authorization is supported/necessary for the current KorAP instance. Automatically set during initialization.}
Marc Kupietz4862b862019-11-07 10:13:53 +010095
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020096\item{userAgent}{user agent string.}
97
Marc Kupietza81343d2022-09-06 12:32:10 +020098\item{timeout}{tineout in seconds for API requests (this does not influence server internal timeouts).}
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020099
Marc Kupietza81343d2022-09-06 12:32:10 +0200100\item{verbose}{logical that decides whether following operations will default to
Marc Kupietz4862b862019-11-07 10:13:53 +0100101be verbose.}
Marc Kupietz5a519822019-09-20 21:43:52 +0200102
Marc Kupietza81343d2022-09-06 12:32:10 +0200103\item{cache}{logical that decides if API calls are cached locally. You can clear
Marc Kupietz67edcb52021-09-20 21:54:24 +0200104the cache with \code{\link[=clearCache]{clearCache()}}.}
Marc Kupietz0a96b282019-10-01 11:05:31 +0200105
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +0200106\item{kco}{KorAPConnection object}
107
108\item{url}{request url}
109
Marc Kupietzf9129592025-01-26 19:17:54 +0100110\item{json}{logical that determines if JSON result is expected}
Marc Kupietzb2b32a32020-03-24 13:56:50 +0100111
Marc Kupietzb49afa02020-06-04 15:50:29 +0200112\item{getHeaders}{logical that determines if headers and content should be returned (as a list)}
113
Marc Kupietze95108e2019-09-18 13:23:58 +0200114\item{object}{KorAPConnection object}
115}
116\value{
Marc Kupietz67edcb52021-09-20 21:54:24 +0200117\code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with
118\code{\link[=corpusQuery]{corpusQuery()}}
Marc Kupietze95108e2019-09-18 13:23:58 +0200119}
120\description{
Marc Kupietz7776dec2019-09-27 16:59:02 +0200121\code{KorAPConnection} objects represent the connection to a KorAP server.
Marc Kupietz617266d2025-02-27 10:43:07 +0100122New \code{KorAPConnection} objects can be created by \code{KorAPConnection()}.
Marc Kupietze95108e2019-09-18 13:23:58 +0200123}
Marc Kupietza81343d2022-09-06 12:32:10 +0200124\section{Slots}{
125
126\describe{
127\item{\code{KorAPUrl}}{URL of the web user interface of the KorAP server used in the connection.}
128
129\item{\code{apiVersion}}{requested KorAP API version.}
130
131\item{\code{indexRevision}}{indexRevision code as reported from API via \code{X-Index-Revision} HTTP header.}
132
133\item{\code{apiUrl}}{full URL of API including version.}
134
135\item{\code{accessToken}}{OAuth2 access token.}
136
Marc Kupietzf83d59a2025-02-01 14:48:30 +0100137\item{\code{oauthClient}}{OAuth2 client object.}
138
139\item{\code{oauthScope}}{OAuth2 scope.}
140
Marc Kupietz62b17892025-02-01 18:26:45 +0100141\item{\code{authorizationSupported}}{logical that indicates if authorization is supported/necessary for the current KorAP instance. Automatically set during initialization.}
142
Marc Kupietza81343d2022-09-06 12:32:10 +0200143\item{\code{userAgent}}{user agent string used for connection the API.}
144
Marc Kupietz471d90a2025-02-01 18:26:12 +0100145\item{\code{timeout}}{timeout in seconds for API requests (this does not influence server internal timeouts)}
Marc Kupietza81343d2022-09-06 12:32:10 +0200146
147\item{\code{verbose}}{logical that decides whether operations will default to be verbose.}
148
149\item{\code{cache}}{logical that decides if API calls are cached locally.}
150
151\item{\code{welcome}}{list containing HTTP response received from KorAP server welcome function.}
152}}
153
Marc Kupietze95108e2019-09-18 13:23:58 +0200154\examples{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200155\dontrun{
156
Marc Kupietz617266d2025-02-27 10:43:07 +0100157kcon <- KorAPConnection(verbose = TRUE)
Marc Kupietze95108e2019-09-18 13:23:58 +0200158kq <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietz5a519822019-09-20 21:43:52 +0200159kq <- fetchAll(kq)
Marc Kupietz05b22772020-02-18 21:58:42 +0100160}
Marc Kupietze95108e2019-09-18 13:23:58 +0200161
Marc Kupietz4862b862019-11-07 10:13:53 +0100162\dontrun{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200163
Marc Kupietz617266d2025-02-27 10:43:07 +0100164kcon <- KorAPConnection(verbose = TRUE, accessToken="e739u6eOzkwADQPdVChxFg")
Marc Kupietz4862b862019-11-07 10:13:53 +0100165kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly=FALSE)
166kq <- fetchAll(kq)
167kq@collectedMatches$snippet
168}
169
Marc Kupietze95108e2019-09-18 13:23:58 +0200170}