-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a4364aa
Showing
12 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
^.*\.Rproj$ | ||
^\.Rproj\.user$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Package: rt | ||
Type: Package | ||
Title: An R Package for the RT REST API | ||
Version: 0.1.0 | ||
Author: Bryce Mecum <[email protected]> | ||
Maintainer: Bryce Mecum <[email protected]> | ||
Description: This package implements a number of the functions provided by the | ||
RT REST API. | ||
License: MIT | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Depends: httr, | ||
stringr | ||
Suggests: testthat | ||
RoxygenNote: 6.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exportPattern("^[[:alpha:]]+") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
rt_login <- function(base, user, pass) { | ||
req <- httr::POST(base, body = list('user' = user, 'pass' = pass)) | ||
if (req$status_code == 200) { | ||
message("Successfully logged in.") | ||
} else { | ||
stop(req) | ||
} | ||
|
||
invisible(TRUE) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
rt_search <- function(base, query, orderBy=NULL, format="l") { | ||
url <- paste0(base, "/search/ticket?query=", query) | ||
|
||
if (!is.null(orderBy)) { | ||
url <- paste0(url, "&orderBy=", orderBy) | ||
} | ||
|
||
if (!is.null(format)) { | ||
url <- paste0(url, "&format=", format) | ||
} | ||
|
||
req <- httr::GET(url) | ||
|
||
if (req$status_code != 200) { | ||
stop(req, call. = FALSE) | ||
} | ||
|
||
|
||
if (format != "l") { | ||
return(req) | ||
} | ||
|
||
result_split <- lapply(stringr::str_split(httr::content(req), "\\n--\\n"), stringr::str_split, "\\n")[[1]] | ||
|
||
parse_rt_result <- function(x) { | ||
lines_f <- Filter(function(x) { stringr::str_detect(x, ": ")}, x) | ||
parts <- stringr::str_split(lines_f, ": ") | ||
x <- do.call(list, lapply(parts, function(p) paste0(p[-1], collapse = ": "))) | ||
names(x) <- lapply(parts, function(p) p[[1]]) | ||
|
||
x | ||
} | ||
|
||
y <- lapply(result_split, parse_rt_result) | ||
|
||
result <- data.frame() | ||
|
||
for (z in y) { | ||
zdf <- as.data.frame(z, stringsAsFactors = FALSE) | ||
|
||
if (nrow(result) > 0 ) { | ||
for (name in setdiff(names(result), names(zdf))) { | ||
zdf[,name] <- NA | ||
} | ||
|
||
for (name in setdiff(names(zdf), names(result))) { | ||
result[,name] <- NA | ||
} | ||
} | ||
|
||
result <- rbind(result, zdf) | ||
} | ||
|
||
result | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
rt_ticket_history <- function(base, ticket) { | ||
if (missing(ticket)) { | ||
stop("'ticket' must be specified.", call. = FALSE) | ||
} | ||
|
||
url <- paste0(base, "/ticket/", as.character(ticket), "/history") | ||
|
||
req <- httr::GET(url) | ||
history <- stringr::str_split(httr::content(req), "\\n")[[1]] | ||
history <- Filter(function(x) { stringr::str_detect(x, ":")}, history) | ||
transactions <- stringr::str_split(history, ": ") | ||
ids <- lapply(transactions, function(x) x[1]) | ||
bodies <- lapply(transactions, function(x) x[2]) | ||
|
||
transactions_df <- data.frame(id = unlist(ids), body = unlist(bodies), stringsAsFactors = FALSE) | ||
transactions_df <- transactions_df[order(transactions_df$id),] | ||
|
||
transactions_df | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
rt_ticket_show <- function(base, ticket) { | ||
if (missing(ticket)) { | ||
stop("The argument 'ticket' must be specified.", call. = FALSE) | ||
} | ||
|
||
url <- paste0(base, "/ticket/", as.character(ticket), "/show") | ||
|
||
httr::GET(url) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# rt | ||
|
||
An R package for the [RT REST API](https://rt-wiki.bestpractical.com/wiki/REST). | ||
|
||
## Installation | ||
|
||
TBD | ||
|
||
## Development | ||
|
||
TBD | ||
|
||
## Support / Issues / Feedback | ||
|
||
TBD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
\name{hello} | ||
\alias{hello} | ||
\title{Hello, World!} | ||
\usage{ | ||
hello() | ||
} | ||
\description{ | ||
Prints 'Hello, world!'. | ||
} | ||
\examples{ | ||
hello() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: knitr | ||
LaTeX: pdfLaTeX | ||
|
||
StripTrailingWhitespace: Yes | ||
|
||
BuildType: Package | ||
PackageUseDevtools: Yes | ||
PackageInstallArgs: --no-multiarch --with-keep.source | ||
PackageRoxygenize: rd,collate,namespace,vignette |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
library(testthat) | ||
library(rt) | ||
|
||
test_check("rt") |