R/rt_ticket_attachments.R

Defines functions rt_ticket_attachments

Documented in rt_ticket_attachments

#' Get ticket attachments
#'
#' Retrieves attachment metadata for a ticket
#'
#' @inheritParams rt_ticket_attachment
#' @param ... Other arguments passed to \code{\link{rt_POST}}
#'
#' @export
#'
#' @examples
#' \dontrun{
#' rt_ticket_attachments(2)
#' }
rt_ticket_attachments <- function(ticket_id, ...) {
  url <- rt_url("ticket", ticket_id, "attachments")
  out <- rt_GET(url, ...)

  location <- stringr::str_locate(out$body, "Attachments: ")

  if (all(dim(location) != c(1,2))) {
    stop("Error while processing response from RT.")
  }

  rest <- stringr::str_sub(out$body, location[1,2] + 1, nchar(out$body))
  attachments <- parse_rt_properties(rest)

  lapply(attachments, function(attachment) {
    props <- as.list(stringr::str_match(attachment, "\\(?(.+)\\) \\((.+) \\/ (.+)\\)")[1,(2:4)])
    names(props) <- c("Name", "Type", "Size")
    props
  })
}
amoeba/rt documentation built on March 7, 2020, 10:01 a.m.