Marc Kupietz | c616098 | 2025-06-24 15:57:51 +0200 | [diff] [blame] | 1 | % 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. |
| 31 | Defaults to the environment variable \code{KORAP_URL} if set and to the IDS Mannheim KorAP main instance |
| 32 | to 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 |
| 39 | access (e.g. textual queries on IPR protected data), you need to authorize |
| 40 | your application with an access token. |
| 41 | You can obtain an access token in the OAuth settings of your KorAP web interface. |
| 42 | |
| 43 | More details are explained in the |
| 44 | \href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section} |
| 45 | of the RKorAPClient Readme on GitHub. |
| 46 | |
| 47 | To use authorization based on an access token |
| 48 | in 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 | |
| 53 | In order to make the API |
| 54 | token persistent for the currently used \code{KorAPUrl} (you can have one |
| 55 | token per KorAPUrl / KorAP server instance), use: |
| 56 | |
| 57 | \if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco) |
| 58 | }\if{html}{\out{</div>}} |
| 59 | |
| 60 | This will store it in your keyring using the |
| 61 | \link[keyring:keyring-package]{keyring::keyring-package}. Subsequent KorAPConnection() calls will |
| 62 | then automatically retrieve the token from your keying. To stop using a |
| 63 | persisted token, call \code{clearAccessToken(kco)}. Please note that for |
| 64 | DeReKo, authorized queries will behave differently inside and outside the |
| 65 | IDS, because of the special license situation. This concerns also cached |
| 66 | results which do not take into account from where a request was issued. If |
| 67 | you 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 | |
| 70 | An alternative to using an access token is to use a browser-based oauth2 workflow |
| 71 | to 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 |
| 84 | be verbose.} |
| 85 | |
| 86 | \item{cache}{logical that decides if API calls are cached locally. You can clear |
| 87 | the 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{ |
| 94 | Initialize KorAPConnection object |
| 95 | } |
| 96 | \examples{ |
| 97 | \dontrun{ |
| 98 | |
| 99 | kcon <- KorAPConnection(verbose = TRUE) |
| 100 | kq <- corpusQuery(kcon, "Ameisenplage") |
| 101 | kq <- fetchAll(kq) |
| 102 | } |
| 103 | |
| 104 | \dontrun{ |
| 105 | |
| 106 | kcon <- KorAPConnection(verbose = TRUE, accessToken = "e739u6eOzkwADQPdVChxFg") |
| 107 | kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly = FALSE) |
| 108 | kq <- fetchAll(kq) |
| 109 | kq@collectedMatches$snippet |
| 110 | } |
| 111 | |
| 112 | } |
| 113 | \keyword{internal} |