-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrt_ticket_history.R
59 lines (53 loc) · 1.49 KB
/
rt_ticket_history.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
#' Get ticket history
#'
#' Retrieves information about the ticket history
#'
#' @inheritParams rt_ticket_attachment
#' @param format (character) Either \code{s} (ticket ID and subject)
#' or \code{l} (full ticket metadata).
#' Defaults to \code{l}.
#'
#' @export
#'
#' @import stringr
#' @importFrom tidyr separate
#' @import dplyr
#' @importFrom tibble tibble
#'
#' @examples
#' \dontrun{
#' # Log in to RT
#' Sys.getenv("RT_BASE_URL" ="https://demo.bestpractical.com")
#' rt_login(user = "guest", pass = "guest")
#'
#' # Get the full ticket history
#' rt_ticket_history(992)
#' #'
#' # Get just the ticket ID and subject
#' rt_ticket_history(992, format = "s")
#' }
rt_ticket_history <- function(ticket_id, format = "l", rt_base_url = Sys.getenv("RT_BASE_URL")) {
if (missing(ticket_id)) {
stop("'ticket_id' must be specified.", call. = FALSE)
}
url <- rt_url(rt_base_url, "ticket", ticket_id, "history")
if(format == "l"){
url <- paste0(url, "?format=l")
}
out <- rt_GET(url)
if(format == "s"){
out$content <- out$content %>%
tidyr::gather(history_id, history_name)
}
return(out)
# if(format == "l"){
# history <- stringr::str_split(content(req), "\\n\\n--\\n\\n")[[1]]
# print(cat(history))
# } else {
# history <- tibble::tibble(content = stringr::str_split(httr::content(req), "\\n")[[1]]) %>%
# dplyr::filter(str_detect(content, ":")) %>%
# tidyr::separate(content, c("ticket", "subject"), sep = ": ", extra = "merge")
# }
#
# return(history)
}