add get_path method (#91)
This commit is contained in:
Родитель
c194175530
Коммит
6158983c05
1
NEWS.md
1
NEWS.md
|
@ -1,5 +1,6 @@
|
|||
# Microsoft365R 2.3.1.9000
|
||||
|
||||
- Add a `get_path()` method for drive items, which returns the path to the item starting from the root. Needed as Graph doesn't seem to store the path in an unmangled form anywhere.
|
||||
- Fix broken methods for accessing items in shared OneDrive/SharePoint folders (#89).
|
||||
- Fix a bug in sending file attachments in Teams chats (#87).
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
#' - `upload(src, dest, blocksize)`: Upload a file. Only applicable for a folder item.
|
||||
#' - `create_folder(path)`: Create a folder. Only applicable for a folder item.
|
||||
#' - `get_item(path)`: Get a child item (file or folder) under this folder.
|
||||
#' - `get_parent_folder()`: Get the parent folder for this item. Returns the root folder for the root.
|
||||
#' - `get_parent_folder()`: Get the parent folder for this item, as a drive item object. Returns the root folder for the root.
|
||||
#' - `get_path()`: Get the absolute path for this item, as a character string.
|
||||
#' - `is_folder()`: Information function, returns TRUE if this item is a folder.
|
||||
#'
|
||||
#' @section Initialization:
|
||||
|
@ -306,6 +307,12 @@ public=list(
|
|||
invisible(NULL)
|
||||
},
|
||||
|
||||
get_path=function()
|
||||
{
|
||||
path <- private$make_absolute_path()
|
||||
sub("^.+root:?/?", "/", path)
|
||||
},
|
||||
|
||||
print=function(...)
|
||||
{
|
||||
file_or_dir <- if(self$is_folder()) "file folder" else "file"
|
||||
|
|
|
@ -35,7 +35,8 @@ Class representing an item (file or folder) in a OneDrive or SharePoint document
|
|||
\item \code{upload(src, dest, blocksize)}: Upload a file. Only applicable for a folder item.
|
||||
\item \code{create_folder(path)}: Create a folder. Only applicable for a folder item.
|
||||
\item \code{get_item(path)}: Get a child item (file or folder) under this folder.
|
||||
\item \code{get_parent_folder()}: Get the parent folder for this item. Returns the root folder for the root.
|
||||
\item \code{get_parent_folder()}: Get the parent folder for this item, as a drive item object. Returns the root folder for the root.
|
||||
\item \code{get_path()}: Get the absolute path for this item, as a character string.
|
||||
\item \code{is_folder()}: Information function, returns TRUE if this item is a folder.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ test_that("Drive item methods work",
|
|||
root <- od$get_item("/")
|
||||
expect_is(root, "ms_drive_item")
|
||||
expect_equal(root$properties$name, "root")
|
||||
expect_equal(root$get_path(), "/")
|
||||
|
||||
rootp <- root$get_parent_folder()
|
||||
expect_is(rootp, "ms_drive_item")
|
||||
|
@ -68,6 +69,7 @@ test_that("Drive item methods work",
|
|||
folder1 <- root$create_folder(tmpname1)
|
||||
expect_is(folder1, "ms_drive_item")
|
||||
expect_true(folder1$is_folder())
|
||||
expect_equal(folder1$get_path(), paste0("/", tmpname1))
|
||||
|
||||
folder1p <- folder1$get_parent_folder()
|
||||
expect_equal(rootp$properties$name, "root")
|
||||
|
@ -76,6 +78,7 @@ test_that("Drive item methods work",
|
|||
folder2 <- folder1$create_folder(tmpname2)
|
||||
expect_is(folder2, "ms_drive_item")
|
||||
expect_true(folder2$is_folder())
|
||||
expect_equal(folder2$get_path(), paste0("/", tmpname1, "/", tmpname2))
|
||||
|
||||
folder2p <- folder2$get_parent_folder()
|
||||
expect_equal(folder2p$properties$name, folder1$properties$name)
|
||||
|
@ -85,6 +88,7 @@ test_that("Drive item methods work",
|
|||
expect_is(file1, "ms_drive_item")
|
||||
expect_false(file1$is_folder())
|
||||
expect_error(file1$create_folder("bad"))
|
||||
expect_equal(file1$get_path(), paste0("/", basename(src)))
|
||||
|
||||
file1p <- file1$get_parent_folder()
|
||||
expect_equal(file1p$properties$name, "root")
|
||||
|
@ -100,6 +104,7 @@ test_that("Drive item methods work",
|
|||
|
||||
expect_silent(file2 <- folder1$upload(src))
|
||||
expect_is(file2, "ms_drive_item")
|
||||
expect_equal(file2$get_path(), paste0("/", tmpname1, "/", basename(src)))
|
||||
|
||||
file2p <- file2$get_parent_folder()
|
||||
expect_equal(file2p$properties$name, folder1$properties$name)
|
||||
|
|
Загрузка…
Ссылка в новой задаче