blob: 83b05ff13fc155f110832965eb32ee2117e4ed08 [file] [log] [blame]
Marc Kupietzc6160982025-06-24 15:57:51 +02001% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/KorAPConnection.R
3\name{initialize,KorAPConnection-method}
4\alias{initialize,KorAPConnection-method}
5\title{Initialize KorAPConnection object}
6\usage{
7\S4method{initialize}{KorAPConnection}(
8 .Object,
9 KorAPUrl = if (is.null(Sys.getenv("KORAP_URL")) | Sys.getenv("KORAP_URL") == "") {
10
11 "https://korap.ids-mannheim.de/"
12 } else {
13 Sys.getenv("KORAP_URL")
14 },
15 apiVersion = "v1.0",
16 apiUrl,
17 accessToken = getAccessToken(KorAPUrl),
18 oauthClient = NULL,
19 oauthScope = "search match_info",
20 authorizationSupported = TRUE,
21 userAgent = "R-KorAP-Client",
22 timeout = 240,
23 verbose = FALSE,
24 cache = TRUE
25)
26}
27\arguments{
28\item{.Object}{KorAPConnection object}
29
30\item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access.
31Defaults to the environment variable \code{KORAP_URL} if set and to the IDS Mannheim KorAP main instance
32to query DeReKo, otherwise.}
33
34\item{apiVersion}{which version of KorAP's API you want to connect to.}
35
36\item{apiUrl}{URL of the KorAP web service.}
37
38\item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted
39access (e.g. textual queries on IPR protected data), you need to authorize
40your application with an access token.
41You can obtain an access token in the OAuth settings of your KorAP web interface.
42
43More details are explained in the
44\href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section}
45of the RKorAPClient Readme on GitHub.
46
47To use authorization based on an access token
48in subsequent queries, initialize your KorAP connection with:
49
50\if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- KorAPConnection(accessToken="<access token>")
51}\if{html}{\out{</div>}}
52
53In order to make the API
54token persistent for the currently used \code{KorAPUrl} (you can have one
55token per KorAPUrl / KorAP server instance), use:
56
57\if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco)
58}\if{html}{\out{</div>}}
59
60This will store it in your keyring using the
61\link[keyring:keyring-package]{keyring::keyring-package}. Subsequent KorAPConnection() calls will
62then automatically retrieve the token from your keying. To stop using a
63persisted token, call \code{clearAccessToken(kco)}. Please note that for
64DeReKo, authorized queries will behave differently inside and outside the
65IDS, because of the special license situation. This concerns also cached
66results which do not take into account from where a request was issued. If
67you experience problems or unexpected results, please try \code{kco <- KorAPConnection(cache=FALSE)} or use
68\code{\link[=clearCache]{clearCache()}} to clear the cache completely.
69
70An alternative to using an access token is to use a browser-based oauth2 workflow
71to obtain an access token. This can be done with the \code{\link[=auth]{auth()}} method.}
72
73\item{oauthClient}{OAuth2 client object.}
74
75\item{oauthScope}{OAuth2 scope.}
76
77\item{authorizationSupported}{logical that indicates if authorization is supported/necessary for the current KorAP instance. Automatically set during initialization.}
78
79\item{userAgent}{user agent string.}
80
81\item{timeout}{tineout in seconds for API requests (this does not influence server internal timeouts).}
82
83\item{verbose}{logical that decides whether following operations will default to
84be verbose.}
85
86\item{cache}{logical that decides if API calls are cached locally. You can clear
87the cache with \code{\link[=clearCache]{clearCache()}}.}
88}
89\value{
90\code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with
91\code{\link[=corpusQuery]{corpusQuery()}}
92}
93\description{
94Initialize KorAPConnection object
95}
96\examples{
97\dontrun{
98
99kcon <- KorAPConnection(verbose = TRUE)
100kq <- corpusQuery(kcon, "Ameisenplage")
101kq <- fetchAll(kq)
102}
103
104\dontrun{
105
106kcon <- KorAPConnection(verbose = TRUE, accessToken = "e739u6eOzkwADQPdVChxFg")
107kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly = FALSE)
108kq <- fetchAll(kq)
109kq@collectedMatches$snippet
110}
111
112}
113\keyword{internal}