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 | b956b81 | 2019-11-25 17:53:13 +0100 | [diff] [blame] | 8 | \alias{persistAccessToken,KorAPConnection-method} |
| 9 | \alias{persistAccessToken} |
| 10 | \alias{clearAccessToken,KorAPConnection-method} |
| 11 | \alias{clearAccessToken} |
Marc Kupietz | d0d3e9b | 2019-09-24 17:36:03 +0200 | [diff] [blame] | 12 | \alias{apiCall,KorAPConnection-method} |
| 13 | \alias{apiCall} |
Marc Kupietz | 0a96b28 | 2019-10-01 11:05:31 +0200 | [diff] [blame] | 14 | \alias{clearCache,KorAPConnection-method} |
| 15 | \alias{clearCache} |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 16 | \alias{show,KorAPConnection-method} |
| 17 | \title{Class KorAPConnection} |
| 18 | \usage{ |
Marc Kupietz | 76685f5 | 2019-11-25 17:46:06 +0100 | [diff] [blame] | 19 | \S4method{initialize}{KorAPConnection}( |
| 20 | .Object, |
| 21 | KorAPUrl = "https://korap.ids-mannheim.de/", |
| 22 | apiVersion = "v1.0", |
| 23 | apiUrl, |
Marc Kupietz | b956b81 | 2019-11-25 17:53:13 +0100 | [diff] [blame] | 24 | accessToken = getAccessToken(KorAPUrl), |
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 | b956b81 | 2019-11-25 17:53:13 +0100 | [diff] [blame] | 31 | \S4method{persistAccessToken}{KorAPConnection}(kco, accessToken = kco@accessToken) |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 32 | |
Marc Kupietz | b956b81 | 2019-11-25 17:53:13 +0100 | [diff] [blame] | 33 | \S4method{clearAccessToken}{KorAPConnection}(kco) |
Marc Kupietz | d0d3e9b | 2019-09-24 17:36:03 +0200 | [diff] [blame] | 34 | |
Marc Kupietz | a467572 | 2022-02-23 23:55:15 +0100 | [diff] [blame] | 35 | \S4method{apiCall}{KorAPConnection}( |
| 36 | kco, |
| 37 | url, |
| 38 | json = TRUE, |
| 39 | getHeaders = FALSE, |
| 40 | cache = kco@cache, |
| 41 | timeout = kco@timeout |
| 42 | ) |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 43 | |
Marc Kupietz | 0a96b28 | 2019-10-01 11:05:31 +0200 | [diff] [blame] | 44 | \S4method{clearCache}{KorAPConnection}(kco) |
| 45 | |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 46 | \S4method{show}{KorAPConnection}(object) |
| 47 | } |
| 48 | \arguments{ |
| 49 | \item{.Object}{KorAPConnection object} |
| 50 | |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 51 | \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] | 52 | |
| 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 Kupietz | 132f005 | 2023-04-16 14:23:05 +0200 | [diff] [blame] | 57 | \item{accessToken}{OAuth2 access token. For queries on corpus parts with restricted |
| 58 | access (e.g. textual queries on IPR protected data), you need to authorize |
| 59 | your application with an access token. |
| 60 | How to obtain an access token for the DeReKo KorAP instance is explained in the |
| 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 | |
| 67 | \if{html}{\out{<div class="sourceCode">}}\preformatted{kco <- new("KorAPConnection", accessToken="<access token>") |
| 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 | 67edcb5 | 2021-09-20 21:54:24 +0200 | [diff] [blame] | 78 | \code{\link[=keyring]{keyring()}} package. Subsequent new("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 | 67edcb5 | 2021-09-20 21:54:24 +0200 | [diff] [blame] | 84 | you 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 Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 86 | |
Marc Kupietz | d0d3e9b | 2019-09-24 17:36:03 +0200 | [diff] [blame] | 87 | \item{userAgent}{user agent string.} |
| 88 | |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 89 | \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] | 90 | |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 91 | \item{verbose}{logical that decides whether following operations will default to |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 92 | be verbose.} |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame] | 93 | |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 94 | \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] | 95 | the cache with \code{\link[=clearCache]{clearCache()}}.} |
Marc Kupietz | 0a96b28 | 2019-10-01 11:05:31 +0200 | [diff] [blame] | 96 | |
Marc Kupietz | d0d3e9b | 2019-09-24 17:36:03 +0200 | [diff] [blame] | 97 | \item{kco}{KorAPConnection object} |
| 98 | |
| 99 | \item{url}{request url} |
| 100 | |
Marc Kupietz | b2b32a3 | 2020-03-24 13:56:50 +0100 | [diff] [blame] | 101 | \item{json}{logical that determines if json result is expected} |
| 102 | |
Marc Kupietz | b49afa0 | 2020-06-04 15:50:29 +0200 | [diff] [blame] | 103 | \item{getHeaders}{logical that determines if headers and content should be returned (as a list)} |
| 104 | |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 105 | \item{object}{KorAPConnection object} |
| 106 | } |
| 107 | \value{ |
Marc Kupietz | 67edcb5 | 2021-09-20 21:54:24 +0200 | [diff] [blame] | 108 | \code{\link[=KorAPConnection]{KorAPConnection()}} object that can be used e.g. with |
| 109 | \code{\link[=corpusQuery]{corpusQuery()}} |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 110 | } |
| 111 | \description{ |
Marc Kupietz | 7776dec | 2019-09-27 16:59:02 +0200 | [diff] [blame] | 112 | \code{KorAPConnection} objects represent the connection to a KorAP server. |
Marc Kupietz | 7715e9d | 2019-11-08 15:59:58 +0100 | [diff] [blame] | 113 | New \code{KorAPConnection} objects can be created by \code{new("KorAPConnection")}. |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 114 | } |
Marc Kupietz | a81343d | 2022-09-06 12:32:10 +0200 | [diff] [blame] | 115 | \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 Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 139 | \examples{ |
Marc Kupietz | 6ae7605 | 2021-09-21 10:34:00 +0200 | [diff] [blame] | 140 | \dontrun{ |
| 141 | |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame] | 142 | kcon <- new("KorAPConnection", verbose = TRUE) |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 143 | kq <- corpusQuery(kcon, "Ameisenplage") |
Marc Kupietz | 5a51982 | 2019-09-20 21:43:52 +0200 | [diff] [blame] | 144 | kq <- fetchAll(kq) |
Marc Kupietz | 05b2277 | 2020-02-18 21:58:42 +0100 | [diff] [blame] | 145 | } |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 146 | |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 147 | \dontrun{ |
Marc Kupietz | 6ae7605 | 2021-09-21 10:34:00 +0200 | [diff] [blame] | 148 | |
Marc Kupietz | b956b81 | 2019-11-25 17:53:13 +0100 | [diff] [blame] | 149 | kcon <- new("KorAPConnection", verbose = TRUE, accessToken="e739u6eOzkwADQPdVChxFg") |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 150 | kq <- corpusQuery(kcon, "Ameisenplage", metadataOnly=FALSE) |
| 151 | kq <- fetchAll(kq) |
| 152 | kq@collectedMatches$snippet |
| 153 | } |
| 154 | |
| 155 | \dontrun{ |
Marc Kupietz | 6ae7605 | 2021-09-21 10:34:00 +0200 | [diff] [blame] | 156 | |
Marc Kupietz | b956b81 | 2019-11-25 17:53:13 +0100 | [diff] [blame] | 157 | kco <- new("KorAPConnection", accessToken="e739u6eOzkwADQPdVChxFg") |
| 158 | persistAccessToken(kco) |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | \dontrun{ |
Marc Kupietz | 6ae7605 | 2021-09-21 10:34:00 +0200 | [diff] [blame] | 162 | |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 163 | kco <- new("KorAPConnection") |
Marc Kupietz | b956b81 | 2019-11-25 17:53:13 +0100 | [diff] [blame] | 164 | clearAccessToken(kco) |
Marc Kupietz | 4862b86 | 2019-11-07 10:13:53 +0100 | [diff] [blame] | 165 | } |
| 166 | |
Marc Kupietz | e95108e | 2019-09-18 13:23:58 +0200 | [diff] [blame] | 167 | } |