Skip to content

Commit 9a188f1

Browse files
authored
Merge pull request #24 from KWB-R/dev
prepare release v0.1.0
2 parents 59c0857 + 3635d3e commit 9a188f1

File tree

70 files changed

+1861
-364
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1861
-364
lines changed

DESCRIPTION

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: kwb.nextcloud
22
Title: R Package for Accessing Nextcloud Using WebDAV API
3-
Version: 0.0.0.9000
3+
Version: 0.1.0
44
Authors@R:
55
c(person(given = "Michael",
66
family = "Rustler",
@@ -26,12 +26,15 @@ Roxygen: list(markdown = TRUE)
2626
RoxygenNote: 7.1.0
2727
Imports:
2828
httr (>= 1.4.1),
29-
kwb.utils (>= 0.5.1),
29+
kwb.file (>= 0.3.1),
30+
kwb.utils (>= 0.6.0),
3031
xml2 (>= 1.3.2)
3132
Remotes:
32-
github::kwb-r/kwb.utils@v0.5.1
33+
github::kwb-r/kwb.file@v0.3.1,
34+
github::kwb-r/kwb.utils@v0.6.0
3335
Suggests:
3436
covr,
3537
knitr,
36-
rmarkdown
38+
rmarkdown,
39+
testthat
3740
VignetteBuilder: knitr

LICENSE

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,21 @@
1-
YEAR: 2020
2-
COPYRIGHT HOLDER: Kompetenzzentrum Wasser Berlin gGmbH (KWB)
1+
MIT License
2+
3+
Copyright (c) 2020 Kompetenzzentrum Wasser Berlin gGmbH (KWB)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NAMESPACE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,31 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(create_folder)
4+
export(delete_file_or_folder)
5+
export(download_files)
6+
export(get_version_info)
7+
export(list_files)
8+
export(upload_file)
9+
importFrom(httr,GET)
10+
importFrom(httr,VERB)
11+
importFrom(httr,content)
12+
importFrom(httr,headers)
13+
importFrom(httr,http_error)
14+
importFrom(kwb.file,remove_common_root)
15+
importFrom(kwb.utils,catAndRun)
16+
importFrom(kwb.utils,createDirectory)
17+
importFrom(kwb.utils,defaultIfNULL)
18+
importFrom(kwb.utils,excludeNULL)
19+
importFrom(kwb.utils,listToDepth)
20+
importFrom(kwb.utils,moveColumnsToFront)
21+
importFrom(kwb.utils,noFactorDataFrame)
22+
importFrom(kwb.utils,orderBy)
23+
importFrom(kwb.utils,renameColumns)
24+
importFrom(kwb.utils,safeRowBindAll)
25+
importFrom(kwb.utils,selectColumns)
26+
importFrom(kwb.utils,stringList)
27+
importFrom(kwb.utils,toLookupList)
28+
importFrom(utils,read.table)
29+
importFrom(xml2,as_list)
30+
importFrom(xml2,xml_find_all)
31+
importFrom(xml2,xml_text)

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# kwb.nextcloud 0.1.0 (2020-06-04)
2+
3+
Exported functions:
4+
5+
* create_folder()
6+
* delete_file_or_folder(), TAKE CARE!
7+
* download_files()
8+
* get_version_info()
9+
* list_files()
10+
* upload_file()
11+
112
# kwb.nextcloud 0.0.0.9000
213

314
* Added a `NEWS.md` file to track changes to the package.

R/.test_main-functions.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
if (FALSE)
2+
{
3+
system.time(file_info <- kwb.nextcloud::list_files(
4+
path = "departments",
5+
pattern = "xlsx$",
6+
recursive = TRUE,
7+
max_depth = 2,
8+
full_info = TRUE,
9+
priority = 1L # only main columns, 2 = more columns, 3 = all columns
10+
))
11+
12+
names(file_info)
13+
View(file_info)
14+
15+
# Download files by href (important when downloading versions)
16+
downloaded_files <- kwb.nextcloud::download_files(file_info$href)
17+
18+
# Download files by path
19+
paths <- file.path(kwb.utils::getAttribute(file_info, "root"), file_info$file)
20+
downloaded_files_2 <- kwb.nextcloud::download_files(paths = paths)
21+
22+
kwb.utils::hsOpenWindowsExplorer(dirname(dirname(downloaded_files[1])))
23+
24+
# Get information on available versions. There seems to be only an entry for
25+
# files that have more than one version
26+
version_info <- kwb.nextcloud::get_version_info(
27+
file_info$fileid[! file_info$isdir]
28+
)
29+
30+
View(version_info)
31+
32+
merge(
33+
file_info[, c("file", "fileid")],
34+
version_info,
35+
all.x = TRUE,
36+
by = "fileid"
37+
)
38+
39+
kwb.nextcloud::download_files(href = version_info$href)
40+
}

R/.test_put-delete.R

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Make also private functions available
2+
kwb.utils::assignPackageObjects("kwb.nextcloud")
3+
4+
# Are we the test user?
5+
nextcloud_user()
6+
7+
# Ok, we seem to be the test user, let's mess around!
8+
9+
# List the files and folders on the main level
10+
list_files()
11+
12+
# Get the file and folder properties
13+
file_info <- list_files(full_info = TRUE)
14+
file_info
15+
16+
# Show only the files
17+
file_info <- exclude_directories(file_info)
18+
file_info
19+
20+
# Relative paths to the files
21+
file_info$file
22+
23+
# Download the files
24+
download_files(file_info$href)
25+
26+
# Create a folder on the cloud
27+
create_folder("testfolder-1")
28+
29+
# Did the folder arrive?
30+
"testfolder-1/" %in% list_files()
31+
32+
# Path to a local temporary file
33+
file <- file.path(tempdir(), "testfile.txt")
34+
35+
# Path to target folder on the cloud
36+
target_path <- "testfolder-1"
37+
38+
# Upload first version of the file
39+
writeLines("Hi folks version 1!", file)
40+
readLines(file)
41+
upload_file(file, target_path)
42+
43+
# Upload second version of the file
44+
writeLines("Hi folks version 2!", file)
45+
readLines(file)
46+
upload_file(file, target_path)
47+
48+
# Upload third version of the file
49+
writeLines("Hi folks version 3!", file)
50+
readLines(file)
51+
upload_file(file, target_path)
52+
53+
# Get the fileid of the uploaded file
54+
file_info <- list_files(target_path, full_info = TRUE)
55+
56+
fileid <- file_info$fileid[file_info$file == "testfile.txt"]
57+
fileid
58+
59+
# Show the versions of the file (identified by fileid)
60+
version_info <- get_version_info(fileid)
61+
62+
# There are two versions (the current version is not shown!)
63+
version_info
64+
65+
# Download all versions (unfortunately named by timestamp)
66+
downloaded_files <- download_files(version_info$href)
67+
downloaded_files
68+
69+
# Read the contents (should be version 1 and 2)
70+
lapply(downloaded_files, readLines)
71+
72+
# Delete a specific version? This seems to be not working
73+
nextcloud_request(version_info$href[1], "DELETE", really = really)
74+
75+
# Delete the file
76+
# I am using the string constant instead of "href" to see what I do!
77+
delete_file_or_folder("testfolder-1/testfile.txt", really = really)
78+
79+
# File deleted? Yes!
80+
list_files("testfolder-1")
81+
82+
# All versions deleted? Yes!!!
83+
get_version_info(fileid) # -> error
84+
85+
# Upload the testfile again
86+
upload_file(file, target_path)
87+
88+
# Check for success
89+
list_files(target_path)
90+
91+
# Now try to delete the whole directory
92+
delete_file_or_folder("testfolder-1", really = really)
93+
94+
# Try to list again
95+
list_files(target_path) # -> not found (any more)!
96+
97+
# List the upper level -> no more testfolder!
98+
list_files()

R/.test_request-body-generation.R

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Test generating request bodies
2+
if (FALSE)
3+
{
4+
# Example requests from https://github.com/dmfs/davwiki/wiki/PROPFIND
5+
6+
# <?xml version="1.0" encoding="utf-8" ?>
7+
# <D:propfind xmlns:D="DAV:">
8+
# <D:prop xmlns:R="http://ns.example.com/boxschema/">
9+
# <R:bigbox/>
10+
# <R:author/>
11+
# <R:DingALing/>
12+
# <R:Random/>
13+
# </D:prop>
14+
# </D:propfind>
15+
16+
cat(kwb.nextcloud:::request_body(
17+
kwb.nextcloud:::element_propfind(
18+
owncloud = FALSE,
19+
nextcloud = FALSE,
20+
kwb.nextcloud:::element_prop(
21+
kwb.nextcloud:::tag_xml("R:bigbox"),
22+
kwb.nextcloud:::tag_xml("R:author"),
23+
kwb.nextcloud:::tag_xml("R:DingALing"),
24+
kwb.nextcloud:::tag_xml("R:Random"),
25+
attributes = list("xmlns:R" = "http://ns.example.com/boxschema/")
26+
)
27+
)
28+
))
29+
30+
# <?xml version="1.0" encoding="utf-8" ?>
31+
# <propfind xmlns="DAV:">
32+
# <propname/>
33+
# </propfind>
34+
35+
cat(kwb.nextcloud:::request_body(
36+
kwb.nextcloud:::element_propfind(
37+
owncloud = FALSE,
38+
nextcloud = FALSE,
39+
kwb.nextcloud:::tag_xml("propname")
40+
)
41+
))
42+
43+
# <?xml version="1.0" encoding="utf-8" ?>
44+
# <D:propfind xmlns:D="DAV:">
45+
# <D:allprop/>
46+
# </D:propfind>
47+
48+
cat(kwb.nextcloud:::request_body(
49+
kwb.nextcloud:::element_propfind(
50+
owncloud = FALSE,
51+
nextcloud = FALSE,
52+
kwb.nextcloud:::tag_xml("d:allprop")
53+
)
54+
))
55+
56+
body <- kwb.nextcloud:::request_body(
57+
kwb.nextcloud:::element_propfind(
58+
kwb.nextcloud:::tag_xml("propname")
59+
)
60+
)
61+
62+
href <- kwb.nextcloud:::path_to_file_href("projects/finale/urban-systems")
63+
64+
xml <- nextcloud_request(
65+
href, verb = "PROPFIND", auth = auth, body = body, as = "parsed"
66+
)
67+
68+
cat(as.character(xml))
69+
}

R/create_folder.R

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# create_folder ----------------------------------------------------------------
2+
3+
#' Create a Folder on the Cloud
4+
#'
5+
#' @param path path to the folder to be created
6+
#' @inheritParams list_files
7+
#' @export
8+
#'
9+
create_folder <- function(
10+
path, user = nextcloud_user(), auth = nextcloud_auth()
11+
)
12+
{
13+
href <- path_to_file_href(path, user = user)
14+
15+
response <- nextcloud_request(href, "MKCOL", auth = auth)
16+
}

R/delete_file_or_folder.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# delete_file_or_folder --------------------------------------------------------
2+
3+
#' Delete a File or Folder on the Cloud
4+
#'
5+
#' @param path path to the file or folder to be deleted
6+
#' @param \dots further arguments passed to
7+
#' \code{kwb.nextcloud:::nextcloud_request}
8+
#' @inheritParams list_files
9+
#' @export
10+
#'
11+
delete_file_or_folder <- function(
12+
path, user = nextcloud_user(), auth = nextcloud_auth(), ...
13+
)
14+
{
15+
href <- path_to_file_href(path, user = user)
16+
17+
response <- nextcloud_request(href, "DELETE", auth = auth, ...)
18+
}

0 commit comments

Comments
 (0)