Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 1 | % 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 Kupietz | d0d3e9b | 2019-09-24 17:36:03 +0200 | [diff] [blame] | 8 | \alias{apiCall,KorAPConnection-method} |
| 9 | \alias{apiCall} |
Marc Kupietz | 0a96b28 | 2019-10-01 11:05:31 +0200 | [diff] [blame] | 10 | \alias{clearCache,KorAPConnection-method} |
| 11 | \alias{clearCache} |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 12 | \alias{show,KorAPConnection-method} |
| 13 | \title{Class KorAPConnection} |
| 14 | \usage{ |
Marc Kupietz | 76685f5 | 2019-11-25 17:46:06 +0100 | [diff] [blame] | 15 | \S4method{initialize}{KorAPConnection}( |
| 16 | .Object, |
Marc Kupietz | b79fd44 | 2025-03-26 10:25:03 +0100 | [diff] [blame] | 17 | KorAPUrl = if (is.null(Sys.getenv("KORAP_URL") | Sys.getenv("KORAP_URL") == "")) |
| 18 | "https://korap.ids-mannheim.de/" else Sys.getenv("KORAP_URL"), |
Marc Kupietz | 76685f5 | 2019-11-25 17:46:06 +0100 | [diff] [blame] | 19 | apiVersion = "v1.0", |
| 20 | apiUrl, |
Marc Kupietz | b956b81 | 2019-11-25 17:53:13 +0100 | [diff] [blame] | 21 | accessToken = getAccessToken(KorAPUrl), |
Marc Kupietz | f83d59a | 2025-02-01 14:48:30 +0100 | [diff] [blame] | 22 | oauthClient = NULL, |
| 23 | oauthScope = "search match_info", |
Marc Kupietz | 62b1789 | 2025-02-01 18:26:45 +0100 | [diff] [blame] | 24 | authorizationSupported = TRUE, |
Marc Kupietz | 76685f5 | 2019-11-25 17:46:06 +0100 | [diff] [blame] | 25 | userAgent = "R-KorAP-Client", |
Marc Kupietz | 6a3185b | 2021-12-07 10:23:16 +0100 | [diff] [blame] | 26 | timeout = 240, |
Marc Kupietz | 76685f5 | 2019-11-25 17:46:06 +0100 | [diff] [blame] | 27 | verbose = FALSE, |
| 28 | cache = TRUE |
| 29 | ) |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 30 | |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 31 | \S4method{apiCall}{KorAPConnection}( |
| 32 | kco, |
| 33 | url, |
| 34 | json = TRUE, |
| 35 | getHeaders = FALSE, |
| 36 | cache = kco@cache, |
| 37 | timeout = kco@timeout |
| 38 | ) |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 39 | |
Marc Kupietz | 0a96b28 | 2019-10-01 11:05:31 +0200 | [diff] [blame] | 40 | \S4method{clearCache}{KorAPConnection}(kco) |
| 41 | |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 42 | \S4method{show}{KorAPConnection}(object) |
| 43 | } |
| 44 | \arguments{ |
| 45 | \item{.Object}{KorAPConnection object} |
| 46 | |
Marc Kupietz | b79fd44 | 2025-03-26 10:25:03 +0100 | [diff] [blame] | 47 | \item{KorAPUrl}{URL of the web user interface of the KorAP server instance you want to access. |
| 48 | Defaults to the environment variable \code{KORAP_URL} if set and to the IDS Mannheim KorAP main instance, |
| 49 | otherwise.} |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 50 | |
| 51 | \item{apiVersion}{which version of KorAP's API you want to connect to.} |
| 52 | |
| 53 | \item{apiUrl}{URL of the KorAP web service.} |
| 54 | |
Marc Kupietz | 132f005 | 2023-04-16 14:23:05 +0200 | [diff] [blame] | 55 | \item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted |
| 56 | access (e.g. textual queries on IPR protected data), you need to authorize |
| 57 | your application with an access token. |
Marc Kupietz | 62b1789 | 2025-02-01 18:26:45 +0100 | [diff] [blame] | 58 | You can obtain an access token in the OAuth settings of your KorAP web interface. |
Marc Kupietz | a4f51d7 | 2025-01-25 16:23:18 +0100 | [diff] [blame] | 59 | |
| 60 | More details are explained in the |
Marc Kupietz | 132f005 | 2023-04-16 14:23:05 +0200 | [diff] [blame] | 61 | \href{https://github.com/KorAP/RKorAPClient#authorization}{authorization section} |
| 62 | of the RKorAPClient Readme on GitHub. |
| 63 | |
| 64 | To use authorization based on an access token |
| 65 | in subsequent queries, initialize your KorAP connection with: |
| 66 | |
Marc Kupietz | 617266d | 2025-02-27 10:43:07 +0100 | [diff] [blame] | 67 | \if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- KorAPConnection(accessToken="<access token>") |
Marc Kupietz | 132f005 | 2023-04-16 14:23:05 +0200 | [diff] [blame] | 68 | }\if{html}{\out{</div>}} |
| 69 | |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 70 | In order to make the API |
| 71 | token persistent for the currently used \code{KorAPUrl} (you can have one |
Marc Kupietz | 132f005 | 2023-04-16 14:23:05 +0200 | [diff] [blame] | 72 | token per KorAPUrl / KorAP server instance), use: |
| 73 | |
| 74 | \if{html}{\out{<div class="sourceCode">}}\preformatted{persistAccessToken(kco) |
| 75 | }\if{html}{\out{</div>}} |
| 76 | |
| 77 | This will store it in your keyring using the |
Marc Kupietz | 617266d | 2025-02-27 10:43:07 +0100 | [diff] [blame] | 78 | \link[keyring:keyring-package]{keyring::keyring-package}. Subsequent KorAPConnection() calls will |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 79 | then automatically retrieve the token from your keying. To stop using a |
Marc Kupietz | b956b81 | 2019-11-25 17:53:13 +0100 | [diff] [blame] | 80 | persisted token, call \code{clearAccessToken(kco)}. Please note that for |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 81 | DeReKo, authorized queries will behave differently inside and outside the |
| 82 | IDS, because of the special license situation. This concerns also cached |
| 83 | results which do not take into account from where a request was issued. If |
Marc Kupietz | 617266d | 2025-02-27 10:43:07 +0100 | [diff] [blame] | 84 | you experience problems or unexpected results, please try \code{kco <- KorAPConnection(cache=FALSE)} or use |
Marc Kupietz | f83d59a | 2025-02-01 14:48:30 +0100 | [diff] [blame] | 85 | \code{\link[=clearCache]{clearCache()}} to clear the cache completely. |
| 86 | |
| 87 | An alternative to using an access token is to use a browser-based oauth2 workflow |
| 88 | to obtain an access token. This can be done with the \code{\link[=auth]{auth()}} method.} |
| 89 | |
| 90 | \item{oauthClient}{OAuth2 client object.} |
| 91 | |
| 92 | \item{oauthScope}{OAuth2 scope.} |
| 93 | |
Marc Kupietz | 62b1789 | 2025-02-01 18:26:45 +0100 | [diff] [blame] | 94 | \item{authorizationSupported}{logical that indicates if authorization is supported/necessary for the current KorAP instance. Automatically set during initialization.} |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 95 | |
Marc Kupietz | d0d3e9b | 2019-09-24 17:36:03 +0200 | [diff] [blame] | 96 | \item{userAgent}{user agent string.} |
| 97 | |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 98 | \item{timeout}{tineout in seconds for API requests (this does not influence server internal timeouts).} |
Marc Kupietz | d0d3e9b | 2019-09-24 17:36:03 +0200 | [diff] [blame] | 99 | |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 100 | \item{verbose}{logical that decides whether following operations will default to |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 101 | be verbose.} |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame] | 102 | |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 103 | \item{cache}{logical that decides if API calls are cached locally. You can clear |
Marc Kupietz | 67edcb5 | 2021-09-20 21:54:24 +0200 | [diff] [blame] | 104 | the cache with \code{\link[=clearCache]{clearCache()}}.} |
Marc Kupietz | 0a96b28 | 2019-10-01 11:05:31 +0200 | [diff] [blame] | 105 | |
Marc Kupietz | d0d3e9b | 2019-09-24 17:36:03 +0200 | [diff] [blame] | 106 | \item{kco}{KorAPConnection object} |
| 107 | |
| 108 | \item{url}{request url} |
| 109 | |
Marc Kupietz | f912959 | 2025-01-26 19:17:54 +0100 | [diff] [blame] | 110 | \item{json}{logical that determines if JSON result is expected} |
Marc Kupietz | b2b32a3 | 2020-03-24 13:56:50 +0100 | [diff] [blame] | 111 | |
Marc Kupietz | b49afa0 | 2020-06-04 15:50:29 +0200 | [diff] [blame] | 112 | \item{getHeaders}{logical that determines if headers and content should be returned (as a list)} |
| 113 | |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 114 | \item{object}{KorAPConnection object} |
| 115 | } |
| 116 | \value{ |
Marc Kupietz | 67edcb5 | 2021-09-20 21:54:24 +0200 | [diff] [blame] | 117 | \code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with |
| 118 | \code{\link[=corpusQuery]{corpusQuery()}} |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 119 | } |
| 120 | \description{ |
Marc Kupietz | 7776dec | 2019-09-27 16:59:02 +0200 | [diff] [blame] | 121 | \code{KorAPConnection} objects represent the connection to a KorAP server. |
Marc Kupietz | 617266d | 2025-02-27 10:43:07 +0100 | [diff] [blame] | 122 | New \code{KorAPConnection} objects can be created by \code{KorAPConnection()}. |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 123 | } |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 124 | \section{Slots}{ |
| 125 | |
| 126 | \describe{ |
| 127 | \item{\code{KorAPUrl}}{URL of the web user interface of the KorAP server used in the connection.} |
| 128 | |
| 129 | \item{\code{apiVersion}}{requested KorAP API version.} |
| 130 | |
| 131 | \item{\code{indexRevision}}{indexRevision code as reported from API via \code{X-Index-Revision} HTTP header.} |
| 132 | |
| 133 | \item{\code{apiUrl}}{full URL of API including version.} |
| 134 | |
| 135 | \item{\code{accessToken}}{OAuth2 access token.} |
| 136 | |
Marc Kupietz | f83d59a | 2025-02-01 14:48:30 +0100 | [diff] [blame] | 137 | \item{\code{oauthClient}}{OAuth2 client object.} |
| 138 | |
| 139 | \item{\code{oauthScope}}{OAuth2 scope.} |
| 140 | |
Marc Kupietz | 62b1789 | 2025-02-01 18:26:45 +0100 | [diff] [blame] | 141 | \item{\code{authorizationSupported}}{logical that indicates if authorization is supported/necessary for the current KorAP instance. Automatically set during initialization.} |
| 142 | |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 143 | \item{\code{userAgent}}{user agent string used for connection the API.} |
| 144 | |
Marc Kupietz | 471d90a | 2025-02-01 18:26:12 +0100 | [diff] [blame] | 145 | \item{\code{timeout}}{timeout in seconds for API requests (this does not influence server internal timeouts)} |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 146 | |
| 147 | \item{\code{verbose}}{logical that decides whether operations will default to be verbose.} |
| 148 | |
| 149 | \item{\code{cache}}{logical that decides if API calls are cached locally.} |
| 150 | |
| 151 | \item{\code{welcome}}{list containing HTTP response received from KorAP server welcome function.} |
| 152 | }} |
| 153 | |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 154 | \examples{ |
Marc Kupietz | 6ae7605 | 2021-09-21 10:34:00 +0200 | [diff] [blame] | 155 | \dontrun{ |
| 156 | |
Marc Kupietz | 617266d | 2025-02-27 10:43:07 +0100 | [diff] [blame] | 157 | kcon <- KorAPConnection(verbose = TRUE) |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 158 | kq <- corpusQuery(kcon, "Ameisenplage") |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame] | 159 | kq <- fetchAll(kq) |
Marc Kupietz | 05b2277 | 2020-02-18 21:58:42 +0100 | [diff] [blame] | 160 | } |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 161 | |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 162 | \dontrun{ |
Marc Kupietz | 6ae7605 | 2021-09-21 10:34:00 +0200 | [diff] [blame] | 163 | |
Marc Kupietz | 617266d | 2025-02-27 10:43:07 +0100 | [diff] [blame] | 164 | kcon <- KorAPConnection(verbose = TRUE, accessToken="e739u6eOzkwADQPdVChxFg") |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 165 | kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly=FALSE) |
| 166 | kq <- fetchAll(kq) |
| 167 | kq@collectedMatches$snippet |
| 168 | } |
| 169 | |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 170 | } |