-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccounts_api.R
245 lines (238 loc) · 9.9 KB
/
accounts_api.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# Engines API
#
# Allow clients to fetch Analytics through APIs.
#
# The version of the OpenAPI document: v2:[pa,spar,vault,pub],v1:[fiab,fi,axp,afi,npo,bpm,fpo]
# Contact: analytics.api.support@factset.com
# Generated by: https://openapi-generator.tech
#' @docType class
#' @title Accounts operations
#' @description factset.analyticsapi.engines.Accounts
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ GetAccounts } \emph{ Get accounts and sub-directories in a directory }
#' This endpoint looks up all ACCT and ACTM files and sub-directories in a given directory.
#'
#' \itemize{
#' \item \emph{ @param } path character
#' \item \emph{ @returnType } \link{AccountDirectories} \cr
#'
#' \item On encountering errors, an error of subclass ApiException will be thrown.
#'
#' \item status code : 200 | Expected response, returns a list of accounts and directories
#'
#' \item return type : AccountDirectories
#' \item response headers :
#'
#' \tabular{ll}{
#' X-DataDirect-Request-Key \tab FactSet's request key header. \cr
#' X-FactSet-Api-Request-Key \tab Key to uniquely identify an Analytics API request. Only available after successful authentication. \cr
#' X-RateLimit-Limit \tab Number of allowed requests for the time window. \cr
#' X-RateLimit-Remaining \tab Number of requests left for the time window. \cr
#' X-RateLimit-Reset \tab Number of seconds remaining till rate limit resets. \cr
#' }
#' \item status code : 400 | Invalid query parameter or value provided
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' X-DataDirect-Request-Key \tab FactSet's request key header. \cr
#' X-FactSet-Api-Request-Key \tab Key to uniquely identify an Analytics API request. Only available after successful authentication. \cr
#' X-RateLimit-Limit \tab Number of allowed requests for the time window. \cr
#' X-RateLimit-Remaining \tab Number of requests left for the time window. \cr
#' X-RateLimit-Reset \tab Number of seconds remaining till rate limit resets. \cr
#' }
#' \item status code : 401 | Missing or invalid authentication
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' X-DataDirect-Request-Key \tab FactSet's request key header. \cr
#' X-FactSet-Api-Request-Key \tab Key to uniquely identify an Analytics API request. Only available after successful authentication. \cr
#' }
#' \item status code : 403 | User is forbidden with current credentials
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' X-DataDirect-Request-Key \tab FactSet's request key header. \cr
#' X-FactSet-Api-Request-Key \tab Key to uniquely identify an Analytics API request. Only available after successful authentication. \cr
#' X-RateLimit-Limit \tab Number of allowed requests for the time window. \cr
#' X-RateLimit-Remaining \tab Number of requests left for the time window. \cr
#' X-RateLimit-Reset \tab Number of seconds remaining till rate limit resets. \cr
#' }
#' \item status code : 404 | Path not found
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' X-DataDirect-Request-Key \tab FactSet's request key header. \cr
#' X-FactSet-Api-Request-Key \tab Key to uniquely identify an Analytics API request. Only available after successful authentication. \cr
#' X-RateLimit-Limit \tab Number of allowed requests for the time window. \cr
#' X-RateLimit-Remaining \tab Number of requests left for the time window. \cr
#' X-RateLimit-Reset \tab Number of seconds remaining till rate limit resets. \cr
#' }
#' \item status code : 406 | Unsupported Accept header. Header needs to be set to application/json
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' X-DataDirect-Request-Key \tab FactSet's request key header. \cr
#' X-FactSet-Api-Request-Key \tab Key to uniquely identify an Analytics API request. Only available after successful authentication. \cr
#' X-RateLimit-Limit \tab Number of allowed requests for the time window. \cr
#' X-RateLimit-Remaining \tab Number of requests left for the time window. \cr
#' X-RateLimit-Reset \tab Number of seconds remaining till rate limit resets. \cr
#' }
#' \item status code : 429 | Rate limit reached. Wait till the time specified in Retry-After header value to make further requests.
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' X-DataDirect-Request-Key \tab FactSet's request key header. \cr
#' X-FactSet-Api-Request-Key \tab Key to uniquely identify an Analytics API request. Only available after successful authentication. \cr
#' Retry-After \tab Time to wait in seconds before making a new request as the rate limit has reached. \cr
#' }
#' \item status code : 500 | Server error. Log the X-DataDirect-Request-Key header to assist in troubleshooting
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' X-DataDirect-Request-Key \tab FactSet's request key header. \cr
#' X-FactSet-Api-Request-Key \tab Key to uniquely identify an Analytics API request. Only available after successful authentication. \cr
#' }
#' \item status code : 503 | Request timed out. Retry the request in some time
#'
#'
#' \item response headers :
#'
#' \tabular{ll}{
#' X-DataDirect-Request-Key \tab FactSet's request key header. \cr
#' X-FactSet-Api-Request-Key \tab Key to uniquely identify an Analytics API request. Only available after successful authentication. \cr
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' #################### GetAccounts ####################
#'
#' library(factset.analyticsapi.engines)
#' var.path <- '' # character | The directory to get the accounts and sub-directories in
#'
#' #Get accounts and sub-directories in a directory
#' api.instance <- AccountsApi$new()
#'
#' #Configure HTTP basic authorization: Basic
#' # provide your username in the user-serial format
#' api.instance$apiClient$username <- '<user-serial>';
#' # provide your api key generated using the developer portal
#' api.instance$apiClient$password <- '<api_key>';
#'
#'result <- tryCatch(
#' api.instance$GetAccounts(var.path),
#' ApiException = function(ex) ex
#' )
#' # In case of error, print the error object
#' if(!is.null(result$ApiException)) {
#' cat(result$ApiException$toString())
#' } else {
#' # deserialized response object
#' response.object <- result$content
#' # response headers
#' response.headers <- result$response$headers
#' # response status code
#' response.status.code <- result$response$status_code
#' }
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @importFrom rlang abort
#' @export
AccountsApi <- R6::R6Class(
'AccountsApi',
public = list(
apiClient = NULL,
initialize = function(apiClient){
if (!missing(apiClient)) {
self$apiClient <- apiClient
}
else {
self$apiClient <- ApiClient$new()
}
},
GetAccounts = function(path, ...){
apiResponse <- self$GetAccountsWithHttpInfo(path, ...)
resp <- apiResponse$response
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
apiResponse$content
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
apiResponse
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
apiResponse
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
apiResponse
}
},
GetAccountsWithHttpInfo = function(path, ...){
args <- list(...)
queryParams <- list()
headerParams <- c()
if (missing(`path`)) {
rlang::abort(message = "Missing required parameter `path`.", .subclass = "ApiException", ApiException = ApiException$new(status = 0, reason = "Missing required parameter `path`."))
}
urlPath <- "/analytics/lookups/v2/accounts/{path}"
if (!missing(`path`)) {
urlPath <- gsub(paste0("\\{", "path", "\\}"), URLencode(as.character(`path`), reserved = TRUE), urlPath)
}
# HTTP basic auth
headerParams['Authorization'] <- paste("Basic", base64enc::base64encode(charToRaw(paste(self$apiClient$username, self$apiClient$password, sep=":"))))
resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
method = "GET",
queryParams = queryParams,
headerParams = headerParams,
body = body,
...)
if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
deserializedRespObj <- tryCatch(
self$apiClient$deserialize(resp, "AccountDirectories", loadNamespace("factset.analyticsapi.engines")),
error = function(e){
rlang::abort(message = "Failed to deserialize response", .subclass = "ApiException", ApiException = ApiException$new(http_response = resp))
}
)
ApiResponse$new(deserializedRespObj, resp)
} else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
errorMsg <- toString(content(resp))
if(errorMsg == ""){
errorMsg <- paste("Server returned " , httr::status_code(resp) , " response status code.")
}
rlang::abort(message = errorMsg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp))
} else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
errorMsg <- toString(content(resp))
if(errorMsg == ""){
errorMsg <- "Api client exception encountered."
}
rlang::abort(message = errorMsg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp))
} else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
errorMsg <- toString(content(resp))
if(errorMsg == ""){
errorMsg <- "Api server exception encountered."
}
rlang::abort(message = errorMsg, .subclass = "ApiException", ApiException = ApiException$new(http_response = resp))
}
}
)
)