diff --git a/DESCRIPTION b/DESCRIPTION index f73e700..778a186 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: sbtools Title: USGS ScienceBase Tools Maintainer: David Blodgett -Version: 1.3.2 +Version: 1.4.0 Authors@R: c(person("David", "Blodgett", role=c("cre"), email = "dblodgett@usgs.gov"), person("Luke", "Winslow", role = c("aut"), @@ -35,7 +35,7 @@ Suggests: License: CC0 URL: https://github.com/DOI-USGS/sbtools, https://doi-usgs.github.io/sbtools/ BugReports: https://github.com/DOI-USGS/sbtools/issues -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 VignetteBuilder: knitr Config/testthat/parallel: true Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index 999fafa..9eac835 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -34,9 +34,6 @@ export(item_update_identifier) export(item_upload_cloud) export(item_upload_create) export(item_upsert) -export(items_create) -export(items_update) -export(items_upsert) export(query_item_identifier) export(query_item_in_folder) export(query_items) diff --git a/NEWS.md b/NEWS.md index 8985f3a..829d636 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# version 1.4.0 + +- removed `items_create()`, `items_upsert()`, and `items_update()` as they are no longer supported by sciencebase. +- Fixed bugs related to sciencebase updates. + # version 1.3.2 - `item_rm_files()` now uses cloud end point. #315 diff --git a/R/item_create.R b/R/item_create.R index c81ad4e..5810940 100644 --- a/R/item_create.R +++ b/R/item_create.R @@ -33,81 +33,6 @@ item_create = function(parent_id = user_id(), title, ..., info){ return(as.sbitem(content(r))) } -#' @title Create many new SB items -#' -#' @export -#' @param parent_id An \code{\link{sbitem}} object or character ScienceBase ID -#' corresponding to the parent item (folder). This must be of length 1 or more. -#' If length 1, then we recycle it for every item. -#' @param title Two or more titles for the new SB items -#' @param info (optional) list of metadata info for the new items. for each -#' item include a named list of variables -#' @param ... Additional parameters are passed on to \code{\link[httr]{GET}}, \code{\link[httr]{POST}}, -#' \code{\link[httr]{HEAD}}, \code{\link[httr]{PUT}}. -#' @return One or more objects of class \code{sbitem} in a list -#' @details The length of the \code{title} and \code{info} values must be the same -#' length - however, the \code{parent_id} can be of length 1 or equal to the length -#' of each of \code{title} and \code{info} parameters -#' -#' @description -#' A method to create multiple ScienceBase items with a single call and a single HTTP service -#' request. Can be useful for improving performance of creating a large number of items at once. -#' -#' @examples \dontrun{ -#' # helper function to make a random name -#' aname <- function() paste0(sample(letters, size = 5, replace = TRUE), collapse = "") -#' -#' # Create some items - by default we use your user ID -#' items_create(title = c(aname(), aname())) -#' -#' # add additional items in the info parameter - by default we use your user ID -#' items_create(title = c(aname(), aname()), -#' info = list( -#' list(contacts = list(list(name = "Suzy"))), -#' list(contacts = list(list(name = "Brandy"))) -#' ) -#' ) -#' -#' # another example with more information - by default we use your user ID -#' items_create(title = c(aname(), aname()), -#' info = list( -#' list(contacts = list(list(name = "Suzy"))), -#' list(contacts = list(list(name = "Brandy"))) -#' ) -#' ) -#' -#' # Pass an object of class sbitem -#' (x <- folder_create(user_id(), aname())) -#' items_create(x, title = c(aname(), aname())) -#' } -items_create <- function(parent_id = user_id(), title, ..., info = NULL) { - - if (!length(parent_id) > 0) stop("parent_id must be of length > 0", call. = FALSE) - if (length(parent_id) > 1) { - if (length(parent_id) != length(title)) { - stop("If parent_id length > 1, it must be of same length as title and info", call. = FALSE) - } - } - - item <- lapply(parent_id, as.sbitem) - item <- if (length(item) == 1) rep(item[[1]]$id, length(title)) else item[[1]]$id - body <- unname( - Map(function(x, y) { - list('parentId' = x, 'title' = y) - }, item, title - ) - ) - - if (!is.null(info)) { - body <- Map(function(a, b) c(a, b), body, info) - } - - res <- sbtools_POST(url = pkg.env$url_items, ..., - body = toJSON(body, auto_unbox = TRUE)) - - lapply(content(res), as.sbitem) -} - #' @title Create a folder #' @template item_with_parent #' @param name (character) the folder name diff --git a/R/item_update.R b/R/item_update.R index a1ed050..ef6eb76 100644 --- a/R/item_update.R +++ b/R/item_update.R @@ -34,53 +34,6 @@ item_update = function(sb_id, info, ...){ return(as.sbitem(content(r))) } -#' @title Update many SB items with new metadata -#' -#' @export -#' @param sb_id An \code{\link{sbitem}} object or a character ScienceBase ID -#' corresponding to the item -#' @param info list of metadata info (key-value pairs) to change on the item -#' @param ... Additional parameters are passed on to \code{\link[httr]{PUT}} -#' -#' @description -#' A method to update multiple ScienceBase items with a single call and a single HTTP service -#' request. Can be useful for improving performance of updating a large number of items at once. -#' -#' @return One or more objects of class \code{sbitem} in a list -#' @details If length of \code{sb_id} > 1, then length of \code{info} input must be the same -#' @examples \dontrun{ -#' # helper function to make a random name -#' aname <- function() paste0(sample(letters, size = 5, replace = TRUE), collapse = "") -#' -#' res <- items_create(user_id(), title = c(aname(), aname())) -#' out <- items_update(res, info = list( list(title = aname()), list(title = aname()) ) ) -#' vapply(out, "[[", "", "title") -#' } -items_update <- function(sb_id, info, ...){ - - if (length(sb_id) == 1) sb_id <- list(sb_id) - item <- vapply(sb_id, function(z) as.sbitem(z)$id, "") - invisible(lapply(info, is_info_list)) - - body <- unname( - Map(function(x, y) { - c(list('id' = x, null = "null"), y) - }, item, info - ) - ) - - res <- sbtools_PUT(url = pkg.env$url_items, - body = toJSON(body, auto_unbox = TRUE), - ..., accept_json()) - - # catch 405, which is, I think, expired login - if ('errors' %in% names(content(res))) { - stop(content(res)$errors$message, call. = FALSE) - } - - lapply(content(res), as.sbitem) -} - is_info_list <- function(x) { if (!is.list(x)) { stop('Info must be a list of name-value pairs that can be serialized into JSON', call. = FALSE) diff --git a/R/item_upsert.R b/R/item_upsert.R index 25b30ad..f194e77 100644 --- a/R/item_upsert.R +++ b/R/item_upsert.R @@ -41,64 +41,3 @@ item_upsert <- function(parent_id = user_id(), title = NULL, ..., as.sbitem(content(res)) } - -#' @title Upsert many SB items -#' -#' @description Either creates or updates (if items already exist) -#' -#' @export -#' @template item_with_parent -#' @param title The title of the new SB item -#' @param info (optional) list of metadata info for the new item -#' @return An object of class \code{sbitem} -#' @examples \dontrun{ -#' # helper function to make a random name -#' aname <- function() paste0(sample(letters, size = 5, replace = TRUE), collapse = "") -#' -#' # Create some item - by default we use your user ID -#' z1 <- item_create(title = aname()) -#' z2 <- item_create(title = aname()) -#' -#' # Upsert items -#' (x <- items_upsert(list(z1, z2), title = c(aname(), aname()))) -#' -#' # Call item_upsert again, updates this time -#' items_upsert(x, info = list( -#' contacts = list(list(name = "Suzy")) -#' ) -#' ) -#' } -items_upsert <- function(parent_id = user_id(), title = NULL, ..., - info = NULL){ - - if (!length(parent_id) > 0) stop("parent_id must be of length > 0", call. = FALSE) - if (length(parent_id) > 1) { - if (length(parent_id) != length(title)) { - stop("If parent_id length > 1, it must be of same length as title and info", call. = FALSE) - } - } - - item <- lapply(parent_id, as.sbitem) - ids <- if (length(item) < 2) rep(item$id, 2) else vapply(item, "[[", "", "id") - if (is.null(title)) { - message("title is NULL - re-using titles from input SB items") - title <- vapply(item, "[[", "", "title") - } - - body <- unname( - Map(function(x, y) { - list('parentId' = x, 'title' = y) - }, ids, title - ) - ) - - if (!is.null(info)) { - body <- Map(function(a, b) c(a, b), body, info) - } - - res <- sbtools_POST(url = paste0(pkg.env$url_items, "upsert"), - ..., body = toJSON(body, auto_unbox = TRUE)) - - lapply(content(res), as.sbitem) -} - diff --git a/R/sbtools-package.R b/R/sbtools-package.R index 9229532..7d46662 100644 --- a/R/sbtools-package.R +++ b/R/sbtools-package.R @@ -33,6 +33,5 @@ #' #' @name sbtools-package #' @aliases sbtools -#' @docType package #' @keywords package NULL diff --git a/_pkgdown.yml b/_pkgdown.yml index 0084815..8c8660e 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -21,9 +21,6 @@ reference: - '`sbitem`' - '`folder_create`' - '`identifier_exists`' - - '`items_create`' - - '`items_update`' - - '`items_upsert`' - '`item_append_files`' - '`item_create`' - '`item_exists`' diff --git a/docs/404.html b/docs/404.html index 4453005..981ddce 100644 --- a/docs/404.html +++ b/docs/404.html @@ -8,62 +8,47 @@ Page not found (404) • sbtools - - - - + + + Skip to contents - -