Skip to content

Commit

Permalink
Add notes endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
gdower committed Mar 12, 2024
1 parent 6e9d17e commit 38ac451
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export(tw_ba)
export(tw_biological_associations)
export(tw_co)
export(tw_collection_objects)
export(tw_note)
export(tw_notes)
export(tw_otu)
export(tw_otus)
export(tw_people)
Expand Down
36 changes: 36 additions & 0 deletions R/tw_notes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#' Notes
#'
#' @export
#' @template args
#' @param note_id (integer, vector) filter by note id
#' @param note_object_id (integer, vector) filter by note object id
#' @param note_object_type (string, vector) filter by note object type
#' @param text (string) filter by note text
#' @return list
#' @examples
#' \dontrun{
#' tw_people(last_name="Smith")
#' }
tw_notes <- function(note_id = NULL, note_object_id = NULL,
note_object_type = NULL, text = NULL,
csv = FALSE, token = NULL, project_token = NULL,
page = 0, per = 50, ...) {

assert(page, c("numeric", "integer"))
assert(per, c("numeric", "integer"))

args <- cc(list(note_id = note_id, note_object_id = note_object_id,
note_object_type = note_object_type, text = text,
token = token, project_token = project_token,
page = page, per = per))

res <- tw_GET(api_base_url(), "/notes", query = args, csv = csv, ...)
return(res)
}


#' Notes
#'
#' @rdname tw_notes
#' @export
tw_note <- tw_notes
65 changes: 65 additions & 0 deletions man/tw_notes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/testthat/test-tw_notes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
skip_on_cran()

test_that("tw_notes", {
vcr::use_cassette("tw_notes", {
assign("TW_API_URL", "https://sandbox.taxonworks.org/api/v1", envir = .GlobalEnv)
assign("TW_PROJECT_TOKEN", Sys.getenv("TW_PROJECT_TOKEN"), envir = .GlobalEnv)
assign("TW_USER_TOKEN", Sys.getenv("TW_USER_TOKEN"), envir = .GlobalEnv)
x <- tw_notes(page = 0, per = 1)$data
})

expect_true("note_object_id" %in% colnames(x))
expect_equal(nrow(x), 1)
})

0 comments on commit 38ac451

Please # to comment.