From 38ac451dc37816db4b3ece060670071dedb1f372 Mon Sep 17 00:00:00 2001 From: Geoff Ower Date: Tue, 12 Mar 2024 11:58:14 -0500 Subject: [PATCH] Add notes endpoint --- NAMESPACE | 2 ++ R/tw_notes.R | 36 +++++++++++++++++++ man/tw_notes.Rd | 65 ++++++++++++++++++++++++++++++++++ tests/testthat/test-tw_notes.R | 13 +++++++ 4 files changed, 116 insertions(+) create mode 100644 R/tw_notes.R create mode 100644 man/tw_notes.Rd create mode 100644 tests/testthat/test-tw_notes.R diff --git a/NAMESPACE b/NAMESPACE index 8b8b64b..3e6af20 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/tw_notes.R b/R/tw_notes.R new file mode 100644 index 0000000..3dd03b1 --- /dev/null +++ b/R/tw_notes.R @@ -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 diff --git a/man/tw_notes.Rd b/man/tw_notes.Rd new file mode 100644 index 0000000..a78bb67 --- /dev/null +++ b/man/tw_notes.Rd @@ -0,0 +1,65 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tw_notes.R +\name{tw_notes} +\alias{tw_notes} +\alias{tw_note} +\title{Notes} +\usage{ +tw_notes( + note_id = NULL, + note_object_id = NULL, + note_object_type = NULL, + text = NULL, + csv = FALSE, + token = NULL, + project_token = NULL, + page = 0, + per = 50, + ... +) + +tw_note( + note_id = NULL, + note_object_id = NULL, + note_object_type = NULL, + text = NULL, + csv = FALSE, + token = NULL, + project_token = NULL, + page = 0, + per = 50, + ... +) +} +\arguments{ +\item{note_id}{(integer, vector) filter by note id} + +\item{note_object_id}{(integer, vector) filter by note object id} + +\item{note_object_type}{(string, vector) filter by note object type} + +\item{text}{(string) filter by note text} + +\item{token}{(string) a user token (set with the TW_USER_TOKEN environment variable)} + +\item{project_token}{(string) a project token (set with the TW_PROJECT_TOKEN environment variable)} + +\item{page}{(integer) requested number of offset records (Default: 0)} + +\item{per}{(integer) requested number of maximum records to be returned (Default: 50, Maximum: 10000)} + +\item{...}{curl options passed on to \code{\link[httr2]{verb-GET}}} +} +\value{ +list +} +\description{ +Notes + +Notes +} +\examples{ +\dontrun{ +tw_people(last_name="Smith") +} +} diff --git a/tests/testthat/test-tw_notes.R b/tests/testthat/test-tw_notes.R new file mode 100644 index 0000000..b6c6b44 --- /dev/null +++ b/tests/testthat/test-tw_notes.R @@ -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) +})