Skip to content

Commit

Permalink
document
Browse files Browse the repository at this point in the history
  • Loading branch information
hongooi73 committed May 22, 2023
1 parent 75c5b32 commit c613e7c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 34 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# Microsoft365R 2.3.4.9000

## OneDrive/SharePoint

- Fix broken functionality for shared items in OneDrive/Sharepoint. In particular, this should allow using the MS365 backend with the pins package (#149/#129).
- The `list_shared_items`/`list_shared_files` method for drives now always returns a list of drive item objects, rather than a data frame. If the `info` argument is supplied with a value other than "items", a warning is issued.
- Add folder upload and download functionality for `ms_drive_item$upload()` and `download()`. Subfolders can also be transferred recursively, and optionally in parallel. There are also corresponding `ms_drive$upload_folder()` and `download_folder()` methods.
- Add the ability to use object IDs instead of file/folder paths in `ms_drive` methods, including getting, uploading and downloading. This can be useful since the object ID is immutable, whereas file paths can be changed. See `?ms_drive` for more details.

## Outlook

- Fix a bug in specifying multiple addresses in an email (#134, #151).

# Microsoft365R 2.3.4

Expand Down
30 changes: 18 additions & 12 deletions R/ms_drive.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,20 @@
#' Creating new objects of this class should be done via the `get_drive` methods of the [`ms_graph`], [`az_user`] or [`ms_site`] classes. Calling the `new()` method for this class only constructs the R object; it does not call the Microsoft Graph API to retrieve or create the actual drive.
#'
#' @section File and folder operations:
#' This class exposes methods for carrying out common operations on files and folders. They call down to the corresponding methods for the [`ms_drive_item`] class. In most cases an item can be specified either by path or ID. The former is more user-friendly but subject to change if the file is moved or renamed; the latter is an opaque string but is immutable regardless of file operations. In general, using the path should be good enough for most purposes.
#' This class exposes methods for carrying out common operations on files and folders. They call down to the corresponding methods for the [`ms_drive_item`] class. In most cases an item can be specified either by path or ID. The former is more user-friendly but subject to change if the file is moved or renamed; the latter is an opaque string but is immutable regardless of file operations.
#'
#' `get_item(path, itemid)` retrieves a file or folder, as an object of class [`ms_drive_item`]. Specify either the path or ID, not both.
#'
#' `open_item` opens the given file or folder in your browser. If the file has an unrecognised type, most browsers will attempt to download it.
#'
#' `delete_item` deletes a file or folder. By default, it will ask for confirmation first.
#'
#' `create_share_link(path, itemid, type, expiry, password, scope)` returns a shareable link to the item.
#'
#' `get_item_properties` is a convenience function that returns the properties of a file or folder as a list.
#'
#' `set_item_properties` sets the properties of a file or folder. The new properties should be specified as individual named arguments to the method. Any existing properties that aren't listed as arguments will retain their previous values or be recalculated based on changes to other properties, as appropriate. You can also call the `update` method on the corresponding `ms_drive_item` object.
#'
#' `list_items(path, info, full_names, pagesize)` lists the items under the specified path.
#'
#' `list_files` is a synonym for `list_items`.
Expand All @@ -51,16 +61,6 @@
#'
#' `create_folder` creates a folder with the specified path. Trying to create an already existing folder is an error.
#'
#' `create_share_link(path, type, expiry, password, scope)` returns a shareable link to the item.
#'
#' `delete_item` deletes a file or folder. By default, it will ask for confirmation first.
#'
#' `get_item` retrieves the file or folder with the given path or ID, as an object of class [`ms_drive_item`].
#'
#' `get_item_properties` is a convenience function that returns the properties of a file or folder as a list.
#'
#' `set_item_properties` sets the properties of a file or folder. The new properties should be specified as individual named arguments to the method. Any existing properties that aren't listed as arguments will retain their previous values or be recalculated based on changes to other properties, as appropriate. You can also call the `update` method on the corresponding `ms_drive_item` object.
#'
#' @section Shared items:
#' The `list_shared_items` method shows the files and folders that have been shared with you. This is a named list of drive items, that you can use to access the shared files/folders. The arguments are:
#' - `allow_external`: Whether to include items that were shared from outside tenants. The default is FALSE.
Expand Down Expand Up @@ -108,9 +108,15 @@
#' # file metadata (name, date created, etc)
#' drv$get_item_properties("myfile")
#'
#' # rename a file
#' # rename a file -- item ID remains the same, while name is changed
#' obj <- drv$get_item("myfile")
#' drv$set_item_properties("myfile", name="newname")
#'
#' # retrieve the renamed object by ID
#' id <- obj$properties$id
#' obj2 <- drv$get_item(itemid=id)
#' obj$properties$id == obj2$properties$id # TRUE
#'
#' # accessing shared files
#' shared_df <- drv$list_shared_items()
#' shared_df$remoteItem[[1]]$open()
Expand Down
44 changes: 25 additions & 19 deletions man/ms_drive.Rd

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

18 changes: 16 additions & 2 deletions tests/testthat/test01_onedrive.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ test_that("OneDrive personal works",
src <- "../resources/file.json"
dest <- file.path(newfolder, basename(src))
newsrc <- tempfile()
expect_silent(od$upload_file(src, dest))
expect_silent(od$download_file(dest, newsrc))
expect_silent(od$upload_file(src, dest=dest))
expect_silent(od$download_file(dest, dest=newsrc))

expect_true(files_identical(src, newsrc))

Expand Down Expand Up @@ -177,6 +177,20 @@ test_that("Nested folder creation/deletion works",
})


test_that("Get item by ID works",
{
dir1 <- make_name(10)
src <- "../resources/file.json"

obj <- od$upload_file(src, file.path(dir1, "file.json"))
id <- obj$properties$id
obj2 <- od$get_item(itemid=id)
expect_identical(obj$properties$id, obj2$properties$id)

expect_silent(obj2$delete(confirm=FALSE))
})


test_that("Folder upload/download works",
{
srcdir <- tempfile()
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test02_business_onedrive.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ test_that("OneDrive for Business works",
dest <- file.path(newfolder, basename(src))
newsrc <- tempfile()
expect_silent(od$upload_file(src, dest))
expect_silent(od$download_file(dest, newsrc))
expect_silent(od$download_file(dest, dest=newsrc))

expect_true(files_identical(src, newsrc))

Expand Down

0 comments on commit c613e7c

Please sign in to comment.