blob: 1e0737dc769d95d1e5ffafe8040dcec7545da7a3 [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 Kupietzb956b812019-11-25 17:53:13 +01008\alias{persistAccessToken,KorAPConnection-method}
9\alias{persistAccessToken}
10\alias{clearAccessToken,KorAPConnection-method}
11\alias{clearAccessToken}
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020012\alias{apiCall,KorAPConnection-method}
13\alias{apiCall}
Marc Kupietz0a96b282019-10-01 11:05:31 +020014\alias{clearCache,KorAPConnection-method}
15\alias{clearCache}
Marc Kupietze95108e2019-09-18 13:23:58 +020016\alias{show,KorAPConnection-method}
17\title{Class KorAPConnection}
18\usage{
Marc Kupietz76685f52019-11-25 17:46:06 +010019\S4method{initialize}{KorAPConnection}(
20 .Object,
21 KorAPUrl = "https://korap.ids-mannheim.de/",
22 apiVersion = "v1.0",
23 apiUrl,
Marc Kupietzb956b812019-11-25 17:53:13 +010024 accessToken = getAccessToken(KorAPUrl),
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 Kupietzb956b812019-11-25 17:53:13 +010031\S4method{persistAccessToken}{KorAPConnection}(kco, accessToken = kco@accessToken)
Marc Kupietz4862b862019-11-07 10:13:53 +010032
Marc Kupietzb956b812019-11-25 17:53:13 +010033\S4method{clearAccessToken}{KorAPConnection}(kco)
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020034
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 Kupietza81343d2022-09-06 12:32:10 +020051\item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access.}
Marc Kupietze95108e2019-09-18 13:23:58 +020052
53\item{apiVersion}{which version of KorAP's API you want to connect to.}
54
55\item{apiUrl}{URL of the KorAP web service.}
56
Marc Kupietz132f0052023-04-16 14:23:05 +020057\item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted
58access (e.g. textual queries on IPR protected data), you need to authorize
59your application with an access token.
60How to obtain an access token for the DeReKo KorAP instance is explained in the
61\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
67\if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- new("KorAPConnection", accessToken="<access token>")
68}\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 Kupietz1faa7212024-12-07 18:29:42 +010078\link{keyring} package. Subsequent new("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 Kupietz67edcb52021-09-20 21:54:24 +020084you experience problems or unexpected results, please try \code{kco <- new("KorAPConnection", cache=FALSE)} or use
85\code{\link[=clearCache]{clearCache()}} to clear the cache completely.}
Marc Kupietz4862b862019-11-07 10:13:53 +010086
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020087\item{userAgent}{user agent string.}
88
Marc Kupietza81343d2022-09-06 12:32:10 +020089\item{timeout}{tineout in seconds for API requests (this does not influence server internal timeouts).}
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020090
Marc Kupietza81343d2022-09-06 12:32:10 +020091\item{verbose}{logical that decides whether following operations will default to
Marc Kupietz4862b862019-11-07 10:13:53 +010092be verbose.}
Marc Kupietz5a519822019-09-20 21:43:52 +020093
Marc Kupietza81343d2022-09-06 12:32:10 +020094\item{cache}{logical that decides if API calls are cached locally. You can clear
Marc Kupietz67edcb52021-09-20 21:54:24 +020095the cache with \code{\link[=clearCache]{clearCache()}}.}
Marc Kupietz0a96b282019-10-01 11:05:31 +020096
Marc Kupietzd0d3e9b2019-09-24 17:36:03 +020097\item{kco}{KorAPConnection object}
98
99\item{url}{request url}
100
Marc Kupietzb2b32a32020-03-24 13:56:50 +0100101\item{json}{logical that determines if json result is expected}
102
Marc Kupietzb49afa02020-06-04 15:50:29 +0200103\item{getHeaders}{logical that determines if headers and content should be returned (as a list)}
104
Marc Kupietze95108e2019-09-18 13:23:58 +0200105\item{object}{KorAPConnection object}
106}
107\value{
Marc Kupietz67edcb52021-09-20 21:54:24 +0200108\code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with
109\code{\link[=corpusQuery]{corpusQuery()}}
Marc Kupietze95108e2019-09-18 13:23:58 +0200110}
111\description{
Marc Kupietz7776dec2019-09-27 16:59:02 +0200112\code{KorAPConnection} objects represent the connection to a KorAP server.
Marc Kupietz7715e9d2019-11-08 15:59:58 +0100113New \code{KorAPConnection} objects can be created by \code{new("KorAPConnection")}.
Marc Kupietze95108e2019-09-18 13:23:58 +0200114}
Marc Kupietza81343d2022-09-06 12:32:10 +0200115\section{Slots}{
116
117\describe{
118\item{\code{KorAPUrl}}{URL of the web user interface of the KorAP server used in the connection.}
119
120\item{\code{apiVersion}}{requested KorAP API version.}
121
122\item{\code{indexRevision}}{indexRevision code as reported from API via \code{X-Index-Revision} HTTP header.}
123
124\item{\code{apiUrl}}{full URL of API including version.}
125
126\item{\code{accessToken}}{OAuth2 access token.}
127
128\item{\code{userAgent}}{user agent string used for connection the API.}
129
130\item{\code{timeout}}{tineout in seconds for API requests (this does not influence server internal timeouts)}
131
132\item{\code{verbose}}{logical that decides whether operations will default to be verbose.}
133
134\item{\code{cache}}{logical that decides if API calls are cached locally.}
135
136\item{\code{welcome}}{list containing HTTP response received from KorAP server welcome function.}
137}}
138
Marc Kupietze95108e2019-09-18 13:23:58 +0200139\examples{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200140\dontrun{
141
Marc Kupietz5a519822019-09-20 21:43:52 +0200142kcon <- new("KorAPConnection", verbose = TRUE)
Marc Kupietze95108e2019-09-18 13:23:58 +0200143kq <- corpusQuery(kcon, "Ameisenplage")
Marc Kupietz5a519822019-09-20 21:43:52 +0200144kq <- fetchAll(kq)
Marc Kupietz05b22772020-02-18 21:58:42 +0100145}
Marc Kupietze95108e2019-09-18 13:23:58 +0200146
Marc Kupietz4862b862019-11-07 10:13:53 +0100147\dontrun{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200148
Marc Kupietzb956b812019-11-25 17:53:13 +0100149kcon <- new("KorAPConnection", verbose = TRUE, accessToken="e739u6eOzkwADQPdVChxFg")
Marc Kupietz4862b862019-11-07 10:13:53 +0100150kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly=FALSE)
151kq <- fetchAll(kq)
152kq@collectedMatches$snippet
153}
154
155\dontrun{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200156
Marc Kupietzb956b812019-11-25 17:53:13 +0100157kco <- new("KorAPConnection", accessToken="e739u6eOzkwADQPdVChxFg")
158persistAccessToken(kco)
Marc Kupietz4862b862019-11-07 10:13:53 +0100159}
160
161\dontrun{
Marc Kupietz6ae76052021-09-21 10:34:00 +0200162
Marc Kupietz4862b862019-11-07 10:13:53 +0100163kco <- new("KorAPConnection")
Marc Kupietzb956b812019-11-25 17:53:13 +0100164clearAccessToken(kco)
Marc Kupietz4862b862019-11-07 10:13:53 +0100165}
166
Marc Kupietze95108e2019-09-18 13:23:58 +0200167}