Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
55 changes: 53 additions & 2 deletions R/collection.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#'
Expand All @@ -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){

Expand Down Expand Up @@ -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)
#'
Expand All @@ -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){

Expand Down Expand Up @@ -198,3 +200,52 @@ 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
#'
#' @examples
#'
#' collection_list_by_project(
#' id = "unique-id-for-project"
#' )
#'
#' @export
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)
}



3 changes: 3 additions & 0 deletions man/collection_add_projects.Rd

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

24 changes: 24 additions & 0 deletions man/collection_list_by_project.Rd

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

9 changes: 6 additions & 3 deletions man/collection_remove_projects.Rd

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