-
Notifications
You must be signed in to change notification settings - Fork 0
/
statement.R
67 lines (62 loc) · 1.69 KB
/
statement.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
#' statement
#'
#' xAPI Statement object creation functions
#' @importFrom uuid UUIDgenerate
#' @name statement
NULL
#' Creates an xAPI Statement
#'
#' @param stmt Statement values
#' @param warn Show warnings
#'
#' @examples
#' createStatement(
#' stmt = list(
#' agent = list(
#' name = "John Doe",
#' mbox = "mailto:john@example.com"
#' ),
#' verb = list(
#' display = "answered",
#' id = "http://adlnet.gov/expapi/verbs/answered"
#' ),
#' object = list(
#' name = "Question 1",
#' description = "Example question description."
#' ),
#' result = list(
#' success = TRUE,
#' response = "correctAnswer",
#' extensions = list(
#' ref = "https://w3id.org/xapi/cmi5/result/extensions/progress",
#' value = 100
#' )
#' )
#' )
#' )
#'
#' @seealso \code{\link{createAgent}}
#' @seealso \code{\link{createVerb}}
#' @seealso \code{\link{createObject}}
#' @seealso \code{\link{createResult}}
#'
#' @return xAPI Statement (json)
#'
#' @export
createStatement <- function(stmt = NULL, warn = FALSE, ...) {
if (is.null(stmt)) {
warning("No arguments specified; using default xapi:statement.", call. = FALSE)
warn <- FALSE
}
# Required
statement <- list(
actor = do.call(createActor, list(agent = stmt$agent, group = stmt$group, warn = warn)),
verb = do.call(createVerb, list(verb = stmt$verb, warn = warn)),
object = do.call(createObject, list(object = stmt$object, warn = warn))
)
# Optional
if (!is.null(stmt$result)) {
statement$result <- do.call(createResult, list(result = stmt$result, warn = warn))
}
return(formatJSON(statement, pretty = TRUE, auto_unbox = TRUE))
}