From a2dfae64586530b9c9cc610ffb810fb1f5ff7aa0 Mon Sep 17 00:00:00 2001 From: Thijs Benschop Date: Thu, 8 May 2025 10:38:00 -0400 Subject: [PATCH 1/3] Add idformat for collection_remove_projects and collect_add_projects set default to idno as in example - add function collection_list_by_project --- R/collection.R | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/R/collection.R b/R/collection.R index 5db7822..eeb4276 100644 --- a/R/collection.R +++ b/R/collection.R @@ -65,6 +65,7 @@ list_collections <- function( #' @return NULL #' @param collections \strong{(required)} List of Collection IDs #' @param projects \strong{(required)} List of projects +#' @param id_format \strong{(optional)} ID format (default: "idno") - alternative "id" #' @param api_key API key (optional if API key is set using set_api_key) #' @param api_base_url API base endpoint (optional if API base endpoint is set using set_api_url) #' @@ -83,7 +84,7 @@ list_collections <- function( collection_add_projects <- function( collections=c(), projects=c(), - id_format="id", + id_format="idno", api_key=NULL, api_base_url=NULL){ @@ -135,6 +136,7 @@ collection_add_projects <- function( #' @return NULL #' @param collection_id (required) Collection ID #' @param projects \strong{(required)} List of projects +#' @param id_format \strong{(optional)} ID format (default: "idno") - alternative "id" #' @param api_key API key (optional if API key is set using set_api_key) #' @param api_base_url API base endpoint (optional if API base endpoint is set using set_api_url) #' @@ -153,7 +155,7 @@ collection_add_projects <- function( collection_remove_projects <- function( collections=c(), projects=c(), - id_format="id", + id_format="idno", api_key=NULL, api_base_url=NULL){ @@ -198,3 +200,45 @@ collection_remove_projects <- function( return (output) } +#' List all collections for a project +#' +#' List all collections in which a project is included +#' +#' @return list +#' +#' @param id \strong{(required)} Numeric project id +#' +collection_list_by_project <- function( + id, + api_key=NULL, + api_base_url=NULL){ + + # Get api_key if not provided + if(is.null(api_key)){ + api_key=get_api_key(); + } + + # API endpoint + endpoint <- paste0('editor/collections/', id) + + url=get_api_url(endpoint) + + httpResponse <- GET(url, add_headers("X-API-KEY" = api_key), + accept_json(), + verbose(get_verbose())) + output=NULL + + if(httpResponse$status_code!=200){ + warning(content(httpResponse, "text")) + } + + output=list( + "status_code"=httpResponse$status_code, + "response"=fromJSON(content(httpResponse,"text")) + ) + + return (output) +} + + + From ded2c086165ed8e3c5fac216c04b5cc1c4c44225 Mon Sep 17 00:00:00 2001 From: Thijs Benschop Date: Thu, 8 May 2025 10:42:23 -0400 Subject: [PATCH 2/3] Regenerate documentation using roxygenize --- DESCRIPTION | 2 +- man/collection_add_projects.Rd | 3 +++ man/collection_list_by_project.Rd | 17 +++++++++++++++++ man/collection_remove_projects.Rd | 9 ++++++--- 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 man/collection_list_by_project.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 2c7e81a..559f9bf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +8,7 @@ Description: R client for Metadata Editor API License: MIT Encoding: UTF-8 LazyData: true -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Suggests: testthat Depends: diff --git a/man/collection_add_projects.Rd b/man/collection_add_projects.Rd index 623573a..1dbc3d0 100644 --- a/man/collection_add_projects.Rd +++ b/man/collection_add_projects.Rd @@ -7,6 +7,7 @@ collection_add_projects( collections = c(), projects = c(), + id_format = "idno", api_key = NULL, api_base_url = NULL ) @@ -16,6 +17,8 @@ collection_add_projects( \item{projects}{\strong{(required)} List of projects} +\item{id_format}{\strong{(optional)} ID format (default: "idno") - alternative "id"} + \item{api_key}{API key (optional if API key is set using set_api_key)} \item{api_base_url}{API base endpoint (optional if API base endpoint is set using set_api_url)} diff --git a/man/collection_list_by_project.Rd b/man/collection_list_by_project.Rd new file mode 100644 index 0000000..cc0f776 --- /dev/null +++ b/man/collection_list_by_project.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/collection.R +\name{collection_list_by_project} +\alias{collection_list_by_project} +\title{List all collections for a project} +\usage{ +collection_list_by_project(id, api_key = NULL, api_base_url = NULL) +} +\arguments{ +\item{id}{\strong{(required)} Numeric project id} +} +\value{ +list +} +\description{ +List all collections in which a project is included +} diff --git a/man/collection_remove_projects.Rd b/man/collection_remove_projects.Rd index 1393cff..8d2e883 100644 --- a/man/collection_remove_projects.Rd +++ b/man/collection_remove_projects.Rd @@ -5,20 +5,23 @@ \title{Remove projects from a collection} \usage{ collection_remove_projects( - collection_id, + collections = c(), projects = c(), + id_format = "idno", api_key = NULL, api_base_url = NULL ) } \arguments{ -\item{collection_id}{(required) Collection ID} - \item{projects}{\strong{(required)} List of projects} +\item{id_format}{\strong{(optional)} ID format (default: "idno") - alternative "id"} + \item{api_key}{API key (optional if API key is set using set_api_key)} \item{api_base_url}{API base endpoint (optional if API base endpoint is set using set_api_url)} + +\item{collection_id}{(required) Collection ID} } \description{ Remove projects from a collection From 703ad318339324a580b18c775ae0fae3aa3f507a Mon Sep 17 00:00:00 2001 From: Thijs Benschop Date: Thu, 8 May 2025 10:55:23 -0400 Subject: [PATCH 3/3] Add example and export to collectio_list_by_project --- NAMESPACE | 1 + R/collection.R | 7 +++++++ man/collection_list_by_project.Rd | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 10dab8e..c375479 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ export(ProjectTypes) export(capture_pdf_cover) export(collection_add_projects) +export(collection_list_by_project) export(collection_remove_projects) export(create_project) export(get_api_key) diff --git a/R/collection.R b/R/collection.R index eeb4276..abee746 100644 --- a/R/collection.R +++ b/R/collection.R @@ -208,6 +208,13 @@ collection_remove_projects <- function( #' #' @param id \strong{(required)} Numeric project id #' +#' @examples +#' +#' collection_list_by_project( +#' id = "unique-id-for-project" +#' ) +#' +#' @export collection_list_by_project <- function( id, api_key=NULL, diff --git a/man/collection_list_by_project.Rd b/man/collection_list_by_project.Rd index cc0f776..9edbbb7 100644 --- a/man/collection_list_by_project.Rd +++ b/man/collection_list_by_project.Rd @@ -15,3 +15,10 @@ list \description{ List all collections in which a project is included } +\examples{ + +collection_list_by_project( + id = "unique-id-for-project" +) + +}