blob: a7da86fe33724b5f587032b6f1e7d9093afafcb7 [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 Kupietzf83d59a2025-02-01 14:48:30 +010021 oauthClient = NULL,
22 oauthScope = "search match_info",
Marc Kupietz62b17892025-02-01 18:26:45 +010023 authorizationSupported = TRUE,
Marc Kupietz76685f52019-11-25 17:46:06 +010024 userAgent = "R-KorAP-Client",
Marc Kupietz6a3185b2021-12-07 10:23:16 +010025 timeout = 240,
Marc Kupietz76685f52019-11-25 17:46:06 +010026 verbose = FALSE,
27 cache = TRUE
28)
Marc Kupietz4862b862019-11-07 10:13:53 +010029
Marc Kupietza4675722022-02-23 23:55:15 +010030\S4method{apiCall}{KorAPConnection}(
31 kco,
32 url,
33 json = TRUE,
34 getHeaders = FALSE,
35 cache = kco@cache,
36 timeout = kco@timeout
37)
Marc Kupietze95108e2019-09-18 13:23:58 +020038
Marc Kupietz0a96b282019-10-01 11:05:31 +020039\S4method{clearCache}{KorAPConnection}(kco)
40
Marc Kupietze95108e2019-09-18 13:23:58 +020041\S4method{show}{KorAPConnection}(object)
42}
43\arguments{
44\item{.Object}{KorAPConnection object}
45
Marc Kupietza81343d2022-09-06 12:32:10 +020046\item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access.}
Marc Kupietze95108e2019-09-18 13:23:58 +020047
48\item{apiVersion}{which version of KorAP's API you want to connect to.}
49
50\item{apiUrl}{URL of the KorAP web service.}
51
Marc Kupietz132f0052023-04-16 14:23:05 +020052\item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted
53access (e.g. textual queries on IPR protected data), you need to authorize
54your application with an access token.
Marc Kupietz62b17892025-02-01 18:26:45 +010055You can obtain an access token in the OAuth settings of your KorAP web interface.
Marc Kupietza4f51d72025-01-25 16:23:18 +010056
57More details are explained in the
Marc Kupietz132f0052023-04-16 14:23:05 +020058\href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section}
59of the RKorAPClient Readme on GitHub.
60
61To use authorization based on an access token
62in subsequent queries, initialize your KorAP connection with:
63
64\if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- new("KorAPConnection", accessToken="<access token>")
65}\if{html}{\out{</div>}}
66
Marc Kupietz4862b862019-11-07 10:13:53 +010067In order to make the API
68token persistent for the currently used \code{KorAPUrl} (you can have one
Marc Kupietz132f0052023-04-16 14:23:05 +020069token per KorAPUrl / KorAP server instance), use:
70
71\if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco)
72}\if{html}{\out{</div>}}
73
74This will store it in your keyring using the
Marc Kupietz6a02e4c2025-01-09 21:22:30 +010075\link[keyring:keyring-package]{keyring::keyring-package}. Subsequent new("KorAPConnection") calls will
Marc Kupietz4862b862019-11-07 10:13:53 +010076then automatically retrieve the token from your keying. To stop using a
Marc Kupietzb956b812019-11-25 17:53:13 +010077persisted token, call \code{clearAccessToken(kco)}. Please note that for
Marc Kupietz4862b862019-11-07 10:13:53 +010078DeReKo, authorized queries will behave differently inside and outside the
79IDS, because of the special license situation. This concerns also cached
80results which do not take into account from where a request was issued. If
Marc Kupietz67edcb52021-09-20 21:54:24 +020081you experience problems or unexpected results, please try \code{kco <- new("KorAPConnection", cache=FALSE)} or use
Marc Kupietzf83d59a2025-02-01 14:48:30 +010082\code{\link[=clearCache]{clearCache()}} to clear the cache completely.
83
84An alternative to using an access token is to use a browser-based oauth2 workflow
85to obtain an access token. This can be done with the \code{\link[=auth]{auth()}} method.}
86
87\item{oauthClient}{OAuth2 client object.}
88
89\item{oauthScope}{OAuth2 scope.}
90
Marc Kupietz62b17892025-02-01 18:26:45 +010091\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 +010092
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020093\item{userAgent}{user agent string.}
94
Marc Kupietza81343d2022-09-06 12:32:10 +020095\item{timeout}{tineout in seconds for API requests (this does not influence server internal timeouts).}
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020096
Marc Kupietza81343d2022-09-06 12:32:10 +020097\item{verbose}{logical that decides whether following operations will default to
Marc Kupietz4862b862019-11-07 10:13:53 +010098be verbose.}
Marc Kupietz5a519822019-09-20 21:43:52 +020099
Marc Kupietza81343d2022-09-06 12:32:10 +0200100\item{cache}{logical that decides if API calls are cached locally. You can clear
Marc Kupietz67edcb52021-09-20 21:54:24 +0200101the cache with \code{\link[=clearCache]{clearCache()}}.}
Marc Kupietz0a96b282019-10-01 11:05:31 +0200102
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +0200103\item{kco}{KorAPConnection object}
104
105\item{url}{request url}
106
Marc Kupietzf9129592025-01-26 19:17:54 +0100107\item{json}{logical that determines if JSON result is expected}
Marc Kupietzb2b32a32020-03-24 13:56:50 +0100108
Marc Kupietzb49afa02020-06-04 15:50:29 +0200109\item{getHeaders}{logical that determines if headers and content should be returned (as a list)}
110
Marc Kupietze95108e2019-09-18 13:23:58 +0200111\item{object}{KorAPConnection object}
112}
113\value{
Marc Kupietz67edcb52021-09-20 21:54:24 +0200114\code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with
115\code{\link[=corpusQuery]{corpusQuery()}}
Marc Kupietze95108e2019-09-18 13:23:58 +0200116}
117\description{
Marc Kupietz7776dec2019-09-27 16:59:02 +0200118\code{KorAPConnection} objects represent the connection to a KorAP server.
Marc Kupietz7715e9d2019-11-08 15:59:58 +0100119New \code{KorAPConnection} objects can be created by \code{new("KorAPConnection")}.
Marc Kupietze95108e2019-09-18 13:23:58 +0200120}
Marc Kupietza81343d2022-09-06 12:32:10 +0200121\section{Slots}{
122
123\describe{
124\item{\code{KorAPUrl}}{URL of the web user interface of the KorAP server used in the connection.}
125
126\item{\code{apiVersion}}{requested KorAP API version.}
127
128\item{\code{indexRevision}}{indexRevision code as reported from API via \code{X-Index-Revision} HTTP header.}
129
130\item{\code{apiUrl}}{full URL of API including version.}
131
132\item{\code{accessToken}}{OAuth2 access token.}
133
Marc Kupietzf83d59a2025-02-01 14:48:30 +0100134\item{\code{oauthClient}}{OAuth2 client object.}
135
136\item{\code{oauthScope}}{OAuth2 scope.}
137
Marc Kupietz62b17892025-02-01 18:26:45 +0100138\item{\code{authorizationSupported}}{logical that indicates if authorization is supported/necessary for the current KorAP instance. Automatically set during initialization.}
139
Marc Kupietza81343d2022-09-06 12:32:10 +0200140\item{\code{userAgent}}{user agent string used for connection the API.}
141
Marc Kupietz471d90a2025-02-01 18:26:12 +0100142\item{\code{timeout}}{timeout in seconds for API requests (this does not influence server internal timeouts)}
Marc Kupietza81343d2022-09-06 12:32:10 +0200143
144\item{\code{verbose}}{logical that decides whether operations will default to be verbose.}
145
146\item{\code{cache}}{logical that decides if API calls are cached locally.}
147
148\item{\code{welcome}}{list containing HTTP response received from KorAP server welcome function.}
149}}
150
Marc Kupietze95108e2019-09-18 13:23:58 +0200151\examples{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200152\dontrun{
153
Marc Kupietz5a519822019-09-20 21:43:52 +0200154kcon <- new("KorAPConnection", verbose = TRUE)
Marc Kupietze95108e2019-09-18 13:23:58 +0200155kq <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietz5a519822019-09-20 21:43:52 +0200156kq <- fetchAll(kq)
Marc Kupietz05b22772020-02-18 21:58:42 +0100157}
Marc Kupietze95108e2019-09-18 13:23:58 +0200158
Marc Kupietz4862b862019-11-07 10:13:53 +0100159\dontrun{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200160
Marc Kupietzb956b812019-11-25 17:53:13 +0100161kcon <- new("KorAPConnection", verbose = TRUE, accessToken="e739u6eOzkwADQPdVChxFg")
Marc Kupietz4862b862019-11-07 10:13:53 +0100162kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly=FALSE)
163kq <- fetchAll(kq)
164kq@collectedMatches$snippet
165}
166
Marc Kupietze95108e2019-09-18 13:23:58 +0200167}