blob: d8573f847fe29f9638f4581cc11c9bde18581a25 [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 Kupietz76685f52019-11-25 17:46:06 +010023 userAgent = "R-KorAP-Client",
Marc Kupietz6a3185b2021-12-07 10:23:16 +010024 timeout = 240,
Marc Kupietz76685f52019-11-25 17:46:06 +010025 verbose = FALSE,
26 cache = TRUE
27)
Marc Kupietz4862b862019-11-07 10:13:53 +010028
Marc Kupietza4675722022-02-23 23:55:15 +010029\S4method{apiCall}{KorAPConnection}(
30 kco,
31 url,
32 json = TRUE,
33 getHeaders = FALSE,
34 cache = kco@cache,
35 timeout = kco@timeout
36)
Marc Kupietze95108e2019-09-18 13:23:58 +020037
Marc Kupietz0a96b282019-10-01 11:05:31 +020038\S4method{clearCache}{KorAPConnection}(kco)
39
Marc Kupietze95108e2019-09-18 13:23:58 +020040\S4method{show}{KorAPConnection}(object)
41}
42\arguments{
43\item{.Object}{KorAPConnection object}
44
Marc Kupietza81343d2022-09-06 12:32:10 +020045\item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access.}
Marc Kupietze95108e2019-09-18 13:23:58 +020046
47\item{apiVersion}{which version of KorAP's API you want to connect to.}
48
49\item{apiUrl}{URL of the KorAP web service.}
50
Marc Kupietz132f0052023-04-16 14:23:05 +020051\item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted
52access (e.g. textual queries on IPR protected data), you need to authorize
53your application with an access token.
Marc Kupietza4f51d72025-01-25 16:23:18 +010054You can obtain an access token using the \code{\link[=auth]{auth()}} method.
55
56More details are explained in the
Marc Kupietz132f0052023-04-16 14:23:05 +020057\href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section}
58of the RKorAPClient Readme on GitHub.
59
60To use authorization based on an access token
61in subsequent queries, initialize your KorAP connection with:
62
63\if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- new("KorAPConnection", accessToken="<access token>")
64}\if{html}{\out{</div>}}
65
Marc Kupietz4862b862019-11-07 10:13:53 +010066In order to make the API
67token persistent for the currently used \code{KorAPUrl} (you can have one
Marc Kupietz132f0052023-04-16 14:23:05 +020068token per KorAPUrl / KorAP server instance), use:
69
70\if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco)
71}\if{html}{\out{</div>}}
72
73This will store it in your keyring using the
Marc Kupietz6a02e4c2025-01-09 21:22:30 +010074\link[keyring:keyring-package]{keyring::keyring-package}. Subsequent new("KorAPConnection") calls will
Marc Kupietz4862b862019-11-07 10:13:53 +010075then automatically retrieve the token from your keying. To stop using a
Marc Kupietzb956b812019-11-25 17:53:13 +010076persisted token, call \code{clearAccessToken(kco)}. Please note that for
Marc Kupietz4862b862019-11-07 10:13:53 +010077DeReKo, authorized queries will behave differently inside and outside the
78IDS, because of the special license situation. This concerns also cached
79results which do not take into account from where a request was issued. If
Marc Kupietz67edcb52021-09-20 21:54:24 +020080you experience problems or unexpected results, please try \code{kco <- new("KorAPConnection", cache=FALSE)} or use
Marc Kupietzf83d59a2025-02-01 14:48:30 +010081\code{\link[=clearCache]{clearCache()}} to clear the cache completely.
82
83An alternative to using an access token is to use a browser-based oauth2 workflow
84to obtain an access token. This can be done with the \code{\link[=auth]{auth()}} method.}
85
86\item{oauthClient}{OAuth2 client object.}
87
88\item{oauthScope}{OAuth2 scope.}
89
90\item{authorizationPossible}{logical that indicates if authorization is possible/necessary for the current KorAP instance. Automatically set during initialization.}
Marc Kupietz4862b862019-11-07 10:13:53 +010091
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020092\item{userAgent}{user agent string.}
93
Marc Kupietza81343d2022-09-06 12:32:10 +020094\item{timeout}{tineout in seconds for API requests (this does not influence server internal timeouts).}
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020095
Marc Kupietza81343d2022-09-06 12:32:10 +020096\item{verbose}{logical that decides whether following operations will default to
Marc Kupietz4862b862019-11-07 10:13:53 +010097be verbose.}
Marc Kupietz5a519822019-09-20 21:43:52 +020098
Marc Kupietza81343d2022-09-06 12:32:10 +020099\item{cache}{logical that decides if API calls are cached locally. You can clear
Marc Kupietz67edcb52021-09-20 21:54:24 +0200100the cache with \code{\link[=clearCache]{clearCache()}}.}
Marc Kupietz0a96b282019-10-01 11:05:31 +0200101
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +0200102\item{kco}{KorAPConnection object}
103
104\item{url}{request url}
105
Marc Kupietzf9129592025-01-26 19:17:54 +0100106\item{json}{logical that determines if JSON result is expected}
Marc Kupietzb2b32a32020-03-24 13:56:50 +0100107
Marc Kupietzb49afa02020-06-04 15:50:29 +0200108\item{getHeaders}{logical that determines if headers and content should be returned (as a list)}
109
Marc Kupietze95108e2019-09-18 13:23:58 +0200110\item{object}{KorAPConnection object}
111}
112\value{
Marc Kupietz67edcb52021-09-20 21:54:24 +0200113\code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with
114\code{\link[=corpusQuery]{corpusQuery()}}
Marc Kupietze95108e2019-09-18 13:23:58 +0200115}
116\description{
Marc Kupietz7776dec2019-09-27 16:59:02 +0200117\code{KorAPConnection} objects represent the connection to a KorAP server.
Marc Kupietz7715e9d2019-11-08 15:59:58 +0100118New \code{KorAPConnection} objects can be created by \code{new("KorAPConnection")}.
Marc Kupietze95108e2019-09-18 13:23:58 +0200119}
Marc Kupietza81343d2022-09-06 12:32:10 +0200120\section{Slots}{
121
122\describe{
123\item{\code{KorAPUrl}}{URL of the web user interface of the KorAP server used in the connection.}
124
125\item{\code{apiVersion}}{requested KorAP API version.}
126
127\item{\code{indexRevision}}{indexRevision code as reported from API via \code{X-Index-Revision} HTTP header.}
128
129\item{\code{apiUrl}}{full URL of API including version.}
130
131\item{\code{accessToken}}{OAuth2 access token.}
132
Marc Kupietzf83d59a2025-02-01 14:48:30 +0100133\item{\code{oauthClient}}{OAuth2 client object.}
134
135\item{\code{oauthScope}}{OAuth2 scope.}
136
Marc Kupietza81343d2022-09-06 12:32:10 +0200137\item{\code{userAgent}}{user agent string used for connection the API.}
138
Marc Kupietz471d90a2025-02-01 18:26:12 +0100139\item{\code{timeout}}{timeout in seconds for API requests (this does not influence server internal timeouts)}
Marc Kupietza81343d2022-09-06 12:32:10 +0200140
141\item{\code{verbose}}{logical that decides whether operations will default to be verbose.}
142
143\item{\code{cache}}{logical that decides if API calls are cached locally.}
144
145\item{\code{welcome}}{list containing HTTP response received from KorAP server welcome function.}
146}}
147
Marc Kupietze95108e2019-09-18 13:23:58 +0200148\examples{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200149\dontrun{
150
Marc Kupietz5a519822019-09-20 21:43:52 +0200151kcon <- new("KorAPConnection", verbose = TRUE)
Marc Kupietze95108e2019-09-18 13:23:58 +0200152kq <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietz5a519822019-09-20 21:43:52 +0200153kq <- fetchAll(kq)
Marc Kupietz05b22772020-02-18 21:58:42 +0100154}
Marc Kupietze95108e2019-09-18 13:23:58 +0200155
Marc Kupietz4862b862019-11-07 10:13:53 +0100156\dontrun{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200157
Marc Kupietzb956b812019-11-25 17:53:13 +0100158kcon <- new("KorAPConnection", verbose = TRUE, accessToken="e739u6eOzkwADQPdVChxFg")
Marc Kupietz4862b862019-11-07 10:13:53 +0100159kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly=FALSE)
160kq <- fetchAll(kq)
161kq@collectedMatches$snippet
162}
163
Marc Kupietze95108e2019-09-18 13:23:58 +0200164}