Skip to content

Commit

Permalink
Low hanging fruit and the jump to R v4 (#159)
Browse files Browse the repository at this point in the history
* fix #142 with box_current_version()

* testing travis1

* doc fixins

* coherce to character for vctrs warning in dplyr::bind_rows()

* dplyr bind_rows test

* delink some funcs in docs

* remove print

* update README travis badge

* delink more and add readRDS

* item paren

* readRDS link

* alt mode unclass strat

* return something

* retry newer behavior for bind_rows()

* remove internal docs

* reknit README for travis badge

* box_save/read_rds ready to go

* add skip_funcs to rds tests

* add commentability, close #107

* open browser wrappers, fix #98

* redoc for Rcheck

* version bump and NEWS

* update box_browse to work like box_collab_create

* respond to edits

* ref utils for browseURL to make Rcm chck happy

* box_version clean-up

* refactor documentation

* edit responses rd2

* Refactor versions to "supersede" box_previous_version()

* pull upstream, bump version

* comment tweaks

* add box_comment_get_classes

* box_comment_create classed

* version bump, news

* polish comment classes

* touch up box_browse() documentation - put directory/folder first to match argument order

* add on.exit() to save/load functions, tweak documentation

* tweak documentation on box_comment, S3 classes. add jsonlite to imports.

* box_comment_get() and box_collab_get() return only the entries part of the API response:

- the rest deals with only pagination
- by returning only entries, we can support pagination
- this is what box_ls() does

* export box_versions_api(), add s3 class `box_versions_list`, methods, amend tests

- uses `version_id` rather than `file_version_id`

* clean-up:

 - tweak box_read_rds() docs
 - deprecation call for box_previous_versions()
 - amend NEWS

Co-authored-by: Ian Lyttle <[email protected]>
  • Loading branch information
nathancday and ijlyttle authored Sep 23, 2020
1 parent 14d2ae6 commit 90df3f8
Show file tree
Hide file tree
Showing 45 changed files with 815 additions and 132 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Sample .travis.yml for R projects

language: r
warnings_are_errors: true
sudo: required
cache: packages

matrix:
Expand All @@ -16,7 +14,7 @@ matrix:
deploy:
provider: script
script: Rscript -e 'pkgdown::deploy_site_github()'
skip_cleanup: true
cleanup: true
- r: release
env: BOXR_PASSWORD=''
- r: oldrel
Expand Down
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: boxr
Type: Package
Title: Interface for the 'Box.com API'
Version: 0.3.5.9007
Version: 0.3.5.9008
Authors@R: c(
person("Brendan", "Rocks", email = "[email protected]",
role = c("aut")),
Expand Down Expand Up @@ -48,14 +48,15 @@ Imports:
stats,
stringr,
utils,
tibble
tibble,
lifecycle,
jsonlite,
Suggests:
clipr (>= 0.3.0),
conflicted,
gargle (>= 0.3.0),
here,
jose,
jsonlite,
knitr,
openssl,
png,
Expand All @@ -67,3 +68,4 @@ VignetteBuilder: knitr
RoxygenNote: 7.1.1
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RdMacros: lifecycle
18 changes: 18 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,38 @@

S3method(as.data.frame,boxr_collab)
S3method(as.data.frame,boxr_collab_list)
S3method(as.data.frame,boxr_comment)
S3method(as.data.frame,boxr_comment_list)
S3method(as.data.frame,boxr_object_list)
S3method(as.data.frame,boxr_version_list)
S3method(as_tibble,boxr_collab)
S3method(as_tibble,boxr_collab_list)
S3method(as_tibble,boxr_comment)
S3method(as_tibble,boxr_comment_list)
S3method(as_tibble,boxr_version_list)
S3method(print,boxr_collab)
S3method(print,boxr_collab_list)
S3method(print,boxr_comment)
S3method(print,boxr_comment_list)
S3method(print,boxr_dir_comparison)
S3method(print,boxr_dir_wide_operation_result)
S3method(print,boxr_file_reference)
S3method(print,boxr_folder_reference)
S3method(print,boxr_object_list)
S3method(print,boxr_version_list)
S3method(summary,boxr_dir_comparison)
S3method(summary,boxr_dir_wide_operation_result)
export("%>%")
export(box_add_description)
export(box_auth)
export(box_auth_on_attach)
export(box_auth_service)
export(box_browse)
export(box_collab_create)
export(box_collab_delete)
export(box_collab_get)
export(box_comment_create)
export(box_comment_get)
export(box_delete_file)
export(box_delete_folder)
export(box_dir_create)
Expand All @@ -38,19 +50,25 @@ export(box_read)
export(box_read_csv)
export(box_read_excel)
export(box_read_json)
export(box_read_rds)
export(box_read_tsv)
export(box_restore_file)
export(box_restore_folder)
export(box_save)
export(box_save_image)
export(box_save_rds)
export(box_search)
export(box_search_files)
export(box_search_folders)
export(box_search_trash)
export(box_setwd)
export(box_source)
export(box_ul)
export(box_version_api)
export(box_version_history)
export(box_version_number)
export(box_write)
export(boxr_options)
importFrom(lifecycle,deprecate_soft)
importFrom(magrittr,"%>%")
importFrom(tibble,as_tibble)
16 changes: 14 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
## Improvements

* new tools to manage [collaborations](https://developer.box.com/reference/resources/collaboration/):
- `box_dir_invite()` is deprecated in favvor of `box_collab_create()`.
- adds `box_collab_create()` which supports file and group based collaborations.
- `box_dir_invite()` is deprecated in favor of `box_collab_create()`.
- adds `box_collab_create()`, which supports file and group based collaborations.
- also adds `box_collab_get()` to check existing collaborations, and `box_collab_delete()` to delete.
- `box_collab_create()` and `box_collab_get()` each return the (list-based) response from the Box API.
If you prefer to work with data frames, these return-objects each have `as.data.frame()` and `as_tibble()` methods.

* `box_previous_versions()` is deprecated in favor of `box_version_history()`:
- returns a data frame that includes columns `version_no` (numeric) and `version_id`, rather than `version` (character) and `file_version_id`.
- exports an internal function `box_version_api()`, if you are interested in the unparsed content of the response from the API.

* new function `box_version_number()` returns the current version of a file; this number is consistent with the `version_no` argument used by functions such as `box_dl()`.

* new functions `box_read_rds()` and `box_save_rds()` to work with `RDS` files directly on Box.

* new function `box_browse()` to open a browser window directly to a given folder or file on Box's web app.

* new functions `box_comment_create()` and `box_comment_get()` to create or get comments on Box files. These functions return specially classed `lists` of the API response, on which you can use `as.data.frame()` or `as_tibble()`.

* uses `httr::RETRY()` for API requests to handle momentary issues with network connectivity. Thanks @jameslamb and @chircollab!

## Bug Fixes
Expand Down
5 changes: 5 additions & 0 deletions R/boxr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@
#' @docType package
#' @keywords package
NULL

## usethis namespace: start
#' @importFrom lifecycle deprecate_soft
## usethis namespace: end
NULL
4 changes: 2 additions & 2 deletions R/boxr__internal_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ boxGet <- function(file_id, local_file, version_id = NULL, version_no = NULL,
version_no <- as.numeric(version_no)
assertthat::assert_that(is.numeric(version_no))

versions <- box_previous_versions(file_id)
versions <- box_version_history(file_id)

# Check that the version number exists!
if (version_no > (nrow(versions) + 1)) {
Expand All @@ -60,7 +60,7 @@ boxGet <- function(file_id, local_file, version_id = NULL, version_no = NULL,

# If the version number is for an old version, take the id
if (!is.null(version_no) && version_no <= nrow(versions)) {
version_id <- versions$file_version_id[version_no]
version_id <- versions$version_id[version_no]
}
}

Expand Down
19 changes: 19 additions & 0 deletions R/boxr__internal_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ collab_item_helper <- function(dir_id, file_id) {
list(id = as.character(item_id), type = item_type)
}

# related to collab_item_helper(), how can we combine these in a helper's helper?
comment_item_helper <- function(file_id, comment_id) {
assertthat::assert_that(
is.null(file_id) | is.null(comment_id),
msg = "You can specify only one of `file_id` or `comment_id`, both were set."
)

item_id <- file_id %||% comment_id

assertthat::assert_that(
!is.null(item_id),
msg = "You must specify at least one of `file_id` or `comment_id`, both were NULL."
)

item_type <- ifelse(!is.null(file_id), "file", "comment")

list(id = as.character(item_id), type = item_type)
}

collab_access_helper <- function(user_id, group_id, login) {

arg <- function(x) as.integer(!is_void(x))
Expand Down
29 changes: 23 additions & 6 deletions R/boxr__internal_verb_exit.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,36 @@ returnDwOp <- function(op_detail) {
"new local directories created",
"new remote directories created"
)

# old solution

file_list <-
lapply(
items_list,
function(item)
suppressWarnings(
data.frame(dplyr::bind_rows(lapply(
op_detail$files, function(x) data.frame(x[item])
)))

lapply(op_detail$files,
function(x) {
data.frame(x[item]) %>%
dplyr::mutate_all(as.character)
}) %>%
dplyr::bind_rows()


# data.frame(dplyr::bind_rows(
# lapply(
# op_detail$files, function(x) {
# y <- data.frame(x[item])
# if ("mode" %in% names(y)) {
# y["mode"] <- unclass(y["mode"])
# y
# }
# y
# }
# )))

)
)

out <-
structure(
list(
Expand Down
7 changes: 3 additions & 4 deletions R/boxr_add_description.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#' Add description to a Box file
#'
#' This function will attach a description to a Box file; it will
#' overwrite the Box file's existing description.
#' These functions will attach a description or comment to a Box file. A new
#' description will overwrite an existing one.
#'
#' Files hosted at Box can have small text-descriptions that
#' you can be use to annotate files, or even to
#' leave 'git commit' style messages.
#'
#' @inheritParams box_dl
#'
#' @return Object with S3 class [`boxr_file_reference`][boxr_S3_classes].
#'
#' @export
#'
box_add_description <- function(file_id, description) {
file_id <- handle_file_id(file_id)

Expand Down
24 changes: 15 additions & 9 deletions R/boxr_collab.R
Original file line number Diff line number Diff line change
Expand Up @@ -230,31 +230,37 @@ box_collab_get <- function(dir_id = NULL, file_id = NULL) {
"https://api.box.com/2.0/{item_type}s/{item_id}/collaborations"
)

resp <- httr::RETRY(
response <- httr::RETRY(
"GET",
url = url,
get_token(),
terminate_on = box_terminal_http_codes()
)

resp <- httr::content(resp)
resp <- structure(resp, class = "boxr_collab_list")

if (identical(resp$type, "error")) {
content <- httr::content(response)

if (identical(content$type, "error")) {
stop(
glue::glue(
"Error getting collaborators for {item_type} {item_id}: {resp$message}"
"Error getting collaborators for {item_type} {item_id}: {content$message}"
)
)
}
}

# result should be only the entries member
# - the rest of the content has only pagination information.
# - this is what we did for box_ls().
# - this approach it would permit pagination.
result <- content$entries
result <- structure(result, class = "boxr_collab_list")

message(
glue::glue(
"Box {item_type} {item_id} has {length(resp$entries)} collaborator(s)."
"Box {item_type} {item_id} has {length(result)} collaborator(s)."
)
)

invisible(resp)
invisible(result)
}

#' Delete Box collaboration
Expand Down
Loading

0 comments on commit 90df3f8

Please sign in to comment.