blob: 0637e397501b116df73396bd191ebb561d049ecc [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 Kupietza824d502025-05-02 15:40:23 +020017 KorAPUrl = if (is.null(Sys.getenv("KORAP_URL")) | Sys.getenv("KORAP_URL") == "") {
18
19 "https://korap.ids-mannheim.de/"
20 } else {
21 Sys.getenv("KORAP_URL")
22 },
Marc Kupietz76685f52019-11-25 17:46:06 +010023 apiVersion = "v1.0",
24 apiUrl,
Marc Kupietzb956b812019-11-25 17:53:13 +010025 accessToken = getAccessToken(KorAPUrl),
Marc Kupietzf83d59a2025-02-01 14:48:30 +010026 oauthClient = NULL,
27 oauthScope = "search match_info",
Marc Kupietz62b17892025-02-01 18:26:45 +010028 authorizationSupported = TRUE,
Marc Kupietz76685f52019-11-25 17:46:06 +010029 userAgent = "R-KorAP-Client",
Marc Kupietz6a3185b2021-12-07 10:23:16 +010030 timeout = 240,
Marc Kupietz76685f52019-11-25 17:46:06 +010031 verbose = FALSE,
32 cache = TRUE
33)
Marc Kupietz4862b862019-11-07 10:13:53 +010034
Marc Kupietza4675722022-02-23 23:55:15 +010035\S4method{apiCall}{KorAPConnection}(
36 kco,
37 url,
38 json = TRUE,
39 getHeaders = FALSE,
40 cache = kco@cache,
41 timeout = kco@timeout
42)
Marc Kupietze95108e2019-09-18 13:23:58 +020043
Marc Kupietz0a96b282019-10-01 11:05:31 +020044\S4method{clearCache}{KorAPConnection}(kco)
45
Marc Kupietze95108e2019-09-18 13:23:58 +020046\S4method{show}{KorAPConnection}(object)
47}
48\arguments{
49\item{.Object}{KorAPConnection object}
50
Marc Kupietzb79fd442025-03-26 10:25:03 +010051\item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access.
Marc Kupietzc6acf592025-04-06 18:23:01 +020052Defaults to the environment variable \code{KORAP_URL} if set and to the IDS Mannheim KorAP main instance
53to query DeReKo, otherwise.}
Marc Kupietze95108e2019-09-18 13:23:58 +020054
55\item{apiVersion}{which version of KorAP's API you want to connect to.}
56
57\item{apiUrl}{URL of the KorAP web service.}
58
Marc Kupietz132f0052023-04-16 14:23:05 +020059\item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted
60access (e.g. textual queries on IPR protected data), you need to authorize
61your application with an access token.
Marc Kupietz62b17892025-02-01 18:26:45 +010062You can obtain an access token in the OAuth settings of your KorAP web interface.
Marc Kupietza4f51d72025-01-25 16:23:18 +010063
64More details are explained in the
Marc Kupietz132f0052023-04-16 14:23:05 +020065\href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section}
66of the RKorAPClient Readme on GitHub.
67
68To use authorization based on an access token
69in subsequent queries, initialize your KorAP connection with:
70
Marc Kupietz617266d2025-02-27 10:43:07 +010071\if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- KorAPConnection(accessToken="<access token>")
Marc Kupietz132f0052023-04-16 14:23:05 +020072}\if{html}{\out{</div>}}
73
Marc Kupietz4862b862019-11-07 10:13:53 +010074In order to make the API
75token persistent for the currently used \code{KorAPUrl} (you can have one
Marc Kupietz132f0052023-04-16 14:23:05 +020076token per KorAPUrl / KorAP server instance), use:
77
78\if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco)
79}\if{html}{\out{</div>}}
80
81This will store it in your keyring using the
Marc Kupietz617266d2025-02-27 10:43:07 +010082\link[keyring:keyring-package]{keyring::keyring-package}. Subsequent KorAPConnection() calls will
Marc Kupietz4862b862019-11-07 10:13:53 +010083then automatically retrieve the token from your keying. To stop using a
Marc Kupietzb956b812019-11-25 17:53:13 +010084persisted token, call \code{clearAccessToken(kco)}. Please note that for
Marc Kupietz4862b862019-11-07 10:13:53 +010085DeReKo, authorized queries will behave differently inside and outside the
86IDS, because of the special license situation. This concerns also cached
87results which do not take into account from where a request was issued. If
Marc Kupietz617266d2025-02-27 10:43:07 +010088you experience problems or unexpected results, please try \code{kco <- KorAPConnection(cache=FALSE)} or use
Marc Kupietzf83d59a2025-02-01 14:48:30 +010089\code{\link[=clearCache]{clearCache()}} to clear the cache completely.
90
91An alternative to using an access token is to use a browser-based oauth2 workflow
92to obtain an access token. This can be done with the \code{\link[=auth]{auth()}} method.}
93
94\item{oauthClient}{OAuth2 client object.}
95
96\item{oauthScope}{OAuth2 scope.}
97
Marc Kupietz62b17892025-02-01 18:26:45 +010098\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 +010099
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +0200100\item{userAgent}{user agent string.}
101
Marc Kupietza81343d2022-09-06 12:32:10 +0200102\item{timeout}{tineout in seconds for API requests (this does not influence server internal timeouts).}
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +0200103
Marc Kupietza81343d2022-09-06 12:32:10 +0200104\item{verbose}{logical that decides whether following operations will default to
Marc Kupietz4862b862019-11-07 10:13:53 +0100105be verbose.}
Marc Kupietz5a519822019-09-20 21:43:52 +0200106
Marc Kupietza81343d2022-09-06 12:32:10 +0200107\item{cache}{logical that decides if API calls are cached locally. You can clear
Marc Kupietz67edcb52021-09-20 21:54:24 +0200108the cache with \code{\link[=clearCache]{clearCache()}}.}
Marc Kupietz0a96b282019-10-01 11:05:31 +0200109
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +0200110\item{kco}{KorAPConnection object}
111
112\item{url}{request url}
113
Marc Kupietzf9129592025-01-26 19:17:54 +0100114\item{json}{logical that determines if JSON result is expected}
Marc Kupietzb2b32a32020-03-24 13:56:50 +0100115
Marc Kupietzb49afa02020-06-04 15:50:29 +0200116\item{getHeaders}{logical that determines if headers and content should be returned (as a list)}
117
Marc Kupietze95108e2019-09-18 13:23:58 +0200118\item{object}{KorAPConnection object}
119}
120\value{
Marc Kupietz67edcb52021-09-20 21:54:24 +0200121\code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with
122\code{\link[=corpusQuery]{corpusQuery()}}
Marc Kupietze95108e2019-09-18 13:23:58 +0200123}
124\description{
Marc Kupietz7776dec2019-09-27 16:59:02 +0200125\code{KorAPConnection} objects represent the connection to a KorAP server.
Marc Kupietz617266d2025-02-27 10:43:07 +0100126New \code{KorAPConnection} objects can be created by \code{KorAPConnection()}.
Marc Kupietze95108e2019-09-18 13:23:58 +0200127}
Marc Kupietza81343d2022-09-06 12:32:10 +0200128\section{Slots}{
129
130\describe{
131\item{\code{KorAPUrl}}{URL of the web user interface of the KorAP server used in the connection.}
132
133\item{\code{apiVersion}}{requested KorAP API version.}
134
135\item{\code{indexRevision}}{indexRevision code as reported from API via \code{X-Index-Revision} HTTP header.}
136
137\item{\code{apiUrl}}{full URL of API including version.}
138
139\item{\code{accessToken}}{OAuth2 access token.}
140
Marc Kupietzf83d59a2025-02-01 14:48:30 +0100141\item{\code{oauthClient}}{OAuth2 client object.}
142
143\item{\code{oauthScope}}{OAuth2 scope.}
144
Marc Kupietz62b17892025-02-01 18:26:45 +0100145\item{\code{authorizationSupported}}{logical that indicates if authorization is supported/necessary for the current KorAP instance. Automatically set during initialization.}
146
Marc Kupietza81343d2022-09-06 12:32:10 +0200147\item{\code{userAgent}}{user agent string used for connection the API.}
148
Marc Kupietz471d90a2025-02-01 18:26:12 +0100149\item{\code{timeout}}{timeout in seconds for API requests (this does not influence server internal timeouts)}
Marc Kupietza81343d2022-09-06 12:32:10 +0200150
151\item{\code{verbose}}{logical that decides whether operations will default to be verbose.}
152
153\item{\code{cache}}{logical that decides if API calls are cached locally.}
154
155\item{\code{welcome}}{list containing HTTP response received from KorAP server welcome function.}
156}}
157
Marc Kupietze95108e2019-09-18 13:23:58 +0200158\examples{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200159\dontrun{
160
Marc Kupietz617266d2025-02-27 10:43:07 +0100161kcon <- KorAPConnection(verbose = TRUE)
Marc Kupietze95108e2019-09-18 13:23:58 +0200162kq <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietz5a519822019-09-20 21:43:52 +0200163kq <- fetchAll(kq)
Marc Kupietz05b22772020-02-18 21:58:42 +0100164}
Marc Kupietze95108e2019-09-18 13:23:58 +0200165
Marc Kupietz4862b862019-11-07 10:13:53 +0100166\dontrun{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200167
Marc Kupietza824d502025-05-02 15:40:23 +0200168kcon <- KorAPConnection(verbose = TRUE, accessToken = "e739u6eOzkwADQPdVChxFg")
169kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly = FALSE)
Marc Kupietz4862b862019-11-07 10:13:53 +0100170kq <- fetchAll(kq)
171kq@collectedMatches$snippet
172}
173
Marc Kupietze95108e2019-09-18 13:23:58 +0200174}