This repository has been archived by the owner on Nov 7, 2023. It is now read-only.
/
Agent.r
62 lines (56 loc) · 1.94 KB
/
Agent.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
# Netherlands Biodiversity Api
#
# Access to the digitised Natural History collection at the Naturalis Biodiversity Center
#
# OpenAPI spec version: v2
# Contact: support@naturalis.nl
# Generated by: https://github.com/swagger-api/swagger-codegen.git
#' Agent Class
#'
#' @field agentText
#'
#' @importFrom R6 R6Class
#' @importFrom jsonlite fromJSON toJSON
#' @export
Agent <- R6::R6Class(
"Agent",
public = list(
`agentText` = NULL,
initialize = function(`agentText`) {
if (!missing(`agentText`)) {
stopifnot(is.character(`agentText`), length(`agentText`) == 1)
self[["agentText"]] <- `agentText`
}
},
toList = function() {
AgentList <- list()
if (!is.null(self[["agentText"]])) {
AgentList[["agentText"]] <- self[["agentText"]]
}
## omit empty nested lists in returned list
AgentList[vapply(AgentList, length, FUN.VALUE = integer(1)) > 0]
},
fromList = function(AgentList, typeMapping = NULL) {
if (is.null(typeMapping[["agentText"]])) {
self[["agentText"]] <- AgentList[["agentText"]]
} else {
obj <- eval(parse(text = paste0(typeMapping[["agentText"]], "$new()")))
self[["agentText"]] <- obj$fromList(AgentList[["agentText"]], typeMapping = typeMapping)
}
invisible(self)
},
toJSONString = function(pretty = T) {
jsonlite::toJSON(self$toList(), simplifyVector = T, auto_unbox = T, pretty = pretty)
},
fromJSONString = function(AgentJson, typeMapping = NULL) {
AgentList <- jsonlite::fromJSON(AgentJson, simplifyVector = F)
if (is.null(typeMapping[["agentText"]])) {
self[["agentText"]] <- AgentList[["agentText"]]
} else {
obj <- eval(parse(text = paste0(typeMapping[["agentText"]], "$new()")))
self[["agentText"]] <- obj$fromJSONString(jsonlite::toJSON(AgentList[["agentText"]], auto_unbox = TRUE), typeMapping = typeMapping)
}
invisible(self)
}
)
)