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