-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcu-options.R
53 lines (51 loc) · 1.47 KB
/
cu-options.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
#' Global options for the clickrup package
#'
#' Options store and allow to set global values for the ClickUp API
#' and for clickrup functions.
#' @details
#'
#' Options are mostly for internal use and to allow API version changes
#' in the future.
#'
#' The `tz` (time zone) option can be set globally for [cu_date_from()].
#' The default value `""` means current time zone, see [strptime()].
#'
#' @param ... Options to set.
#'
#' @examples
#' str(cu_options())
#'
#' op <- cu_options(tz = "GMT") # save old values and set tz
#' cu_options()$tz # new tz value
#' cu_options(op) # reset
#' cu_options()$tz # default tz value
#'
#' @return
#'
#' When parameters are set by `cu_options`, their former values are
#' returned in an invisible named list. Such a list can be passed as an
#' argument to `cu_options` to restore the parameter values.
#' Tags are the following:
#'
#' * `baseurl`: ClickUp API base URL.
#' * `version`: ClickUp API version.
#' * `tz`: time zone.
#' * `useragent`: user agent.
#'
#' @export
#' @name cu-options
## this allows manipulating cu options conveniently
cu_options <- function(...) {
opar <- getOption("cu_options")
args <- list(...)
if (length(args)) {
if (length(args) == 1L && is.list(args[[1L]])) {
npar <- args[[1L]]
} else {
npar <- opar
npar[match(names(args), names(npar))] <- args
}
options("cu_options" = npar)
}
invisible(opar)
}