Skip to content
Merged
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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: sbtools
Title: USGS ScienceBase Tools
Maintainer: David Blodgett <dblodgett@usgs.gov>
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"),
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
75 changes: 0 additions & 75 deletions R/item_create.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 0 additions & 47 deletions R/item_update.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
61 changes: 0 additions & 61 deletions R/item_upsert.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

1 change: 0 additions & 1 deletion R/sbtools-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@
#'
#' @name sbtools-package
#' @aliases sbtools
#' @docType package
#' @keywords package
NULL
3 changes: 0 additions & 3 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ reference:
- '`sbitem`'
- '`folder_create`'
- '`identifier_exists`'
- '`items_create`'
- '`items_update`'
- '`items_upsert`'
- '`item_append_files`'
- '`item_create`'
- '`item_exists`'
Expand Down
65 changes: 24 additions & 41 deletions docs/404.html

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

Loading