Skip to content

Commit

Permalink
Clean up a bunch of messy in-progress changes that are part of the re…
Browse files Browse the repository at this point in the history
…factor
  • Loading branch information
amoeba committed Oct 4, 2018
1 parent 85eddb2 commit cf4a2a0
Show file tree
Hide file tree
Showing 49 changed files with 291 additions and 139 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
^.*\.Rproj$
^\.Rproj\.user$
.travis.yml
.travis.yml
Dockerfile
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM netsandbox/request-tracker
6 changes: 3 additions & 3 deletions R/rt_logout.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Use this to log out of RT at the end of your session. Note: restarting your R session will also log you out.
#'
#' @param rt_base (character) The base URL that hosts RT for your organization. Set the base URL in your R session using \code{options(rt_base = "https://server.name/rt/")}
#' @param rt_base (character) The base URL that hosts RT for your organization. Set the base URL in your R session using \code{Sys.getenv("RT_BASE_URL" ="https://server.name/rt/")}
#'
#' @export
#'
Expand All @@ -11,8 +11,8 @@
#' rt_logout()
#' }

rt_logout <- function(rt_base = getOption("rt_base")) {
url <- rt_url(rt_base, "logout")
rt_logout <- function(rt_base_url = Sys.getenv("RT_BASE_URL")) {
url <- rt_url(rt_base_url, "logout")
httr::POST(url, body = NULL)
#clean output?
}
8 changes: 4 additions & 4 deletions R/rt_queue_properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' Get the data for a single queue.
#'
#' @param queue_id (character) The queue identifier
#' @param queue (character) The queue
#' @inheritParams rt_login
#'
#' @export
Expand All @@ -12,8 +12,8 @@
#' rt_queue_properties("General")
#' }

rt_queue_properties <- function(queue_id, rt_base = getOption("rt_base")) {
stopifnot(is.character(queue_id))
url <- rt_url(rt_base, "queue", queue_id)
rt_queue_properties <- function(queue, rt_base_url = Sys.getenv("RT_BASE_URL")) {
stopifnot(is.character(queue))
url <- rt_url(rt_base_url, "queue", queue)
rt_GET(url)
}
4 changes: 2 additions & 2 deletions R/rt_ticket_attachment.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

rt_ticket_attachment <- function(ticket_id,
attachment_id,
rt_base = getOption("rt_base")) {
rt_base_url = Sys.getenv("RT_BASE_URL")) {

url <- rt_url(rt_base, "ticket", ticket_id, "attachments", attachment_id)
url <- rt_url(rt_base_url, "ticket", ticket_id, "attachments", attachment_id)
rt_GET(url)

#TODO: parse more? currently Content & Headers catches stuff that could be split out further
Expand Down
4 changes: 2 additions & 2 deletions R/rt_ticket_attachment_content.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

rt_ticket_attachment_content <- function(ticket_id,
attachment_id,
rt_base = getOption("rt_base")) {
rt_base_url = Sys.getenv("RT_BASE_URL")) {

url <- rt_url(rt_base, "ticket", ticket_id, "attachments", attachment_id, "content")
url <- rt_url(rt_base_url, "ticket", ticket_id, "attachments", attachment_id, "content")
httr::GET(url)
#parse more? may be best to leave as is
}
4 changes: 2 additions & 2 deletions R/rt_ticket_attachments.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#' }

rt_ticket_attachments <- function(ticket_id,
rt_base = getOption("rt_base")) {
url <- rt_url(rt_base, "ticket", ticket_id, "attachments")
rt_base_url = Sys.getenv("RT_BASE_URL")) {
url <- rt_url(rt_base_url, "ticket", ticket_id, "attachments")
out <- rt_GET(url)

#TODO: test how robust this is:
Expand Down
62 changes: 41 additions & 21 deletions R/rt_ticket_create.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
#' Parse an RT ticket create response body and return the ticket ID
#'
#' This function essential parses the text:
#' "# Ticket 1 created."
#' @param body (character) The ticket create response
#'
#' @return (numeric) The ticket ID
parse_ticket_create_body <- function(body) {
match_result <- stringr::str_match(body, "# Ticket (\\d+) created\\.")

if (is.na(match_result[1,1])) {
stop(body, call. = FALSE)
}

as.numeric(match_result[1,2])
}

#' Create an RT ticket
#'
#' Create a new ticket in RT.
Expand Down Expand Up @@ -26,25 +43,25 @@
#' rt_ticket_create(priority = 2, custom_field = c(Description = "A description"))
#' }

rt_ticket_create <- function(queue_id = NULL,
requestor = NULL,
subject = NULL,
cc = NULL,
admin_cc = NULL,
owner = NULL,
status = NULL,
priority = NULL,
initial_priority = NULL,
final_priority = NULL,
time_estimated = NULL,
starts = NULL,
due = NULL,
text = NULL,
custom_field = NULL,
rt_base = getOption("rt_base")) {
rt_ticket_create <- function(queue = NULL,
requestor = NULL,
subject = NULL,
cc = NULL,
admin_cc = NULL,
owner = NULL,
status = NULL,
priority = NULL,
initial_priority = NULL,
final_priority = NULL,
time_estimated = NULL,
starts = NULL,
due = NULL,
text = NULL,
custom_field = NULL,
rt_base_url = Sys.getenv("RT_BASE_URL")) {

params <- compact(list(id = "ticket/new",
Queue = queue_id,
Queue = queue,
Requestor = requestor,
Subject = subject,
Cc = cc,
Expand All @@ -61,13 +78,16 @@ rt_ticket_create <- function(queue_id = NULL,

ticket_content <- paste(names(params), params, sep = ": ", collapse = "\n")

if(exists("custom_field") && length(custom_field) > 0){
if (exists("custom_field") && length(custom_field) > 0) {
cf <- sprintf("\nCF-%s: %s", names(custom_field), custom_field)
ticket_content <- paste(ticket_content, cf)
}

url <- rt_url(rt_base, "ticket", "new")
httr::POST(url, body = list(content = ticket_content))
url <- rt_url(rt_base_url, "ticket", "new")
response <- httr::POST(url, body = list(content = ticket_content))
parsed <- parse_rt_response(httr::content(response))

#need to check
stop_for_status(parsed$status)
parse_ticket_create_body(parsed$body)
}

8 changes: 4 additions & 4 deletions R/rt_ticket_edit.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' }

rt_ticket_edit <- function(ticket_id,
queue_id = NULL,
queue = NULL,
requestor = NULL,
subject = NULL,
cc = NULL,
Expand All @@ -28,11 +28,11 @@ rt_ticket_edit <- function(ticket_id,
due = NULL,
text = NULL,
custom_field = NULL,
rt_base = getOption("rt_base")) {
rt_base_url = Sys.getenv("RT_BASE_URL")) {
stopifnot(is.character(ticket_id) | is.numeric(ticket_id))

params <- compact(list(id = ticket_id,
Queue = queue_id,
Queue = queue,
Requestor = requestor,
Subject = subject,
Cc = cc,
Expand All @@ -54,7 +54,7 @@ rt_ticket_edit <- function(ticket_id,
ticket_content <- paste(ticket_content, cf)
}

url <- rt_url(rt_base, "ticket", ticket_id, "edit")
url <- rt_url(rt_base_url, "ticket", ticket_id, "edit")
httr::POST(url, body = list(content = ticket_content))

#need to check
Expand Down
6 changes: 3 additions & 3 deletions R/rt_ticket_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @examples
#' \dontrun{
#' # Log in to RT
#' options(rt_base = "https://demo.bestpractical.com")
#' Sys.getenv("RT_BASE_URL" ="https://demo.bestpractical.com")
#' rt_login(user = "guest", pass = "guest")
#'
#' # Get the full ticket history
Expand All @@ -27,12 +27,12 @@
#' rt_ticket_history(992, format = "s")
#' }

rt_ticket_history <- function(ticket_id, format = "l", rt_base = getOption("rt_base")) {
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, "ticket", ticket_id, "history")
url <- rt_url(rt_base_url, "ticket", ticket_id, "history")
if(format == "l"){
url <- paste0(url, "?format=l")
}
Expand Down
6 changes: 3 additions & 3 deletions R/rt_ticket_history_comment.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#' rt_ticket_history_comment()
#' }

rt_ticket_history_comment <- function(ticket_id, comment_text, rt_base = getOption("rt_base")) {
rt_ticket_history_comment <- function(ticket_id, comment_text, rt_base_url = Sys.getenv("RT_BASE_URL")) {

url <- rt_url(rt_base, "ticket", ticket_id, "comment")
url <- rt_url(rt_base_url, "ticket", ticket_id, "comment")

comment <- sprintf("id: %s\nAction: comment\nText: %s",
ticket_id, comment_text)
Expand All @@ -23,4 +23,4 @@ rt_ticket_history_comment <- function(ticket_id, comment_text, rt_base = getOpti

#implement attachment
#https://rt-wiki.bestpractical.com/wiki/REST#Ticket_History_Comment
}
}
6 changes: 3 additions & 3 deletions R/rt_ticket_history_reply.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ rt_ticket_history_reply <- function(ticket_id,
bcc = NULL,
time_worked = NULL, #unsure what the inputs are...
attachment_path = NULL,
rt_base = getOption("rt_base")) {
rt_base_url = Sys.getenv("RT_BASE_URL")) {

url <- rt_url(rt_base, "ticket", ticket_id, "comment")
url <- rt_url(rt_base_url, "ticket", ticket_id, "comment")

#account for NULLs
params <- compact(list(id = ticket_id,
Expand All @@ -43,4 +43,4 @@ rt_ticket_history_reply <- function(ticket_id,
httr::POST(url, body = list(content = reply))

#not tested
}
}
4 changes: 2 additions & 2 deletions R/rt_ticket_links.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#' rt_ticket_links(1007)
#' }

rt_ticket_links <- function(ticket_id, rt_base = getOption("rt_base")) {
rt_ticket_links <- function(ticket_id, rt_base_url = Sys.getenv("RT_BASE_URL")) {
stopifnot(is.character(ticket_id) | is.numeric(ticket_id))

url <- rt_url(rt_base, "ticket", ticket_id, "links", "show")
url <- rt_url(rt_base_url, "ticket", ticket_id, "links", "show")

rt_GET(url)
}
4 changes: 2 additions & 2 deletions R/rt_ticket_links_edit.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
rt_ticket_links_edit <- function(ticket_id,
referred_to_by = NULL, depended_on_by = NULL,
member_of = NULL, refers_to = NULL, depends_on = NULL,
rt_base = getOption("rt_base")) {
rt_base_url = Sys.getenv("RT_BASE_URL")) {
stopifnot(is.character(ticket_id) | is.numeric(ticket_id))

params <- compact(list(ReferredToBy = referred_to_by,
Expand All @@ -32,6 +32,6 @@ rt_ticket_links_edit <- function(ticket_id,

links_edit <- paste(names(params), params, sep = ": ", collapse = "\n")

url <- rt_url(rt_base, "ticket", ticket_id, "links")
url <- rt_url(rt_base_url, "ticket", ticket_id, "links")
httr::POST(url, body = list(content = links_edit))
}
4 changes: 2 additions & 2 deletions R/rt_ticket_properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' rt_ticket_properties(15)
#' }

rt_ticket_properties <- function(ticket_id, rt_base = getOption("rt_base")) {
url <- rt_url(rt_base, "ticket", ticket_id, "show")
rt_ticket_properties <- function(ticket_id, rt_base_url = Sys.getenv("RT_BASE_URL")) {
url <- rt_url(rt_base_url, "ticket", ticket_id, "show")
rt_GET(url)
}
4 changes: 2 additions & 2 deletions R/rt_ticket_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#' rt_ticket_search(query = "Queue='General' AND (Status='new')")
#' }

rt_ticket_search <- function(query, orderBy = NULL, format="l", rt_base = getOption("rt_base")) {
base_api <- rt_url(rt_base, "search", "ticket?")
rt_ticket_search <- function(query, orderBy = NULL, format="l", rt_base_url = Sys.getenv("RT_BASE_URL")) {
base_api <- rt_url(rt_base_url, "search", "ticket?")

#based on httr::modify_url()
#possible TODO - turn this into its own function that can be used internally in the package
Expand Down
4 changes: 2 additions & 2 deletions R/rt_user_create.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rt_user_create <- function(user_id,
organization = NULL,
privileged = NULL,
disabled = NULL,
rt_base = getOption("rt_base")) {
rt_base_url = Sys.getenv("RT_BASE_URL")) {

params <- compact(list(Name = name,
Password = password,
Expand All @@ -39,7 +39,7 @@ rt_user_create <- function(user_id,

user_info <- paste(names(params), params, sep = ": ", collapse = "\n")

url <- rt_url(rt_base, "user", "new")
url <- rt_url(rt_base_url, "user", "new")
httr::POST(url, body = list(content = user_info))
#TODO: make this work!
#might need specific permissions?
Expand Down
6 changes: 3 additions & 3 deletions R/rt_user_edit.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ rt_user_edit <- function(user_id,
organization = NULL,
privileged = NULL,
disabled = NULL,
rt_base = getOption("rt_base")) {
rt_base_url = Sys.getenv("RT_BASE_URL")) {

params <- compact(list(Name = name,
Password = password,
Expand All @@ -32,9 +32,9 @@ rt_user_edit <- function(user_id,

user_info <- paste(names(params), params, sep = ": ", collapse = "\n")

url <- rt_url(rt_base, "user", "27", "edit")
url <- rt_url(rt_base_url, "user", "27", "edit")
httr::POST(url, body = list(content = user_info), httr::user_agent("https://github.com/nceas/rt"))
#TODO: make this work!
#might need specific permissions?
#got Permission denied error
}
}
4 changes: 2 additions & 2 deletions R/rt_user_properties.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#' rt_user_properties(1)
#' }

rt_user_properties <- function(user_id, rt_base = getOption("rt_base")) {
rt_user_properties <- function(user_id, rt_base_url = Sys.getenv("RT_BASE_URL")) {
stopifnot(is.character(user_id) | is.numeric(user_id))

url <- rt_url(rt_base, "user", user_id)
url <- rt_url(rt_base_url, "user", user_id)

rt_GET(url)
}
5 changes: 5 additions & 0 deletions R/stop_for_status.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
stop_for_status <- function(status) {
if (status < 200 || status >= 300) {
stop(status)
}
}
Loading

0 comments on commit cf4a2a0

Please sign in to comment.