Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.0.0.9006 #27

Merged
merged 39 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
604d9c3
Increment version number to 0.0.0.9006
alice-hannah Oct 7, 2024
6908d68
Add FAQ re compatibility with eRDM
alice-hannah Oct 7, 2024
8f610d3
Add .lintr to Rbuildignore
alice-hannah Oct 7, 2024
b1a386a
Adjust nolint comments
alice-hannah Oct 7, 2024
26f1277
Add context for 404 error (asset not found)
alice-hannah Oct 7, 2024
1341e2f
Add function to rename asset
alice-hannah Oct 7, 2024
509e980
Test rename_asset
alice-hannah Oct 7, 2024
08294df
Add rename_asset to pkgdown reference
alice-hannah Oct 7, 2024
f639692
Fix bug in var names from asset_info
alice-hannah Oct 8, 2024
ca91878
Add function to get data frame of document versions
alice-hannah Oct 8, 2024
d4cfdd7
Test versions function
alice-hannah Oct 8, 2024
8193778
Move versions fn to R/documents.R
alice-hannah Oct 8, 2024
3dc313f
Add fn to rollback doc to previous version
alice-hannah Oct 8, 2024
27905e6
Test rollback_to_version()
alice-hannah Oct 8, 2024
251eabf
Add function to download document version
alice-hannah Oct 9, 2024
9c2f1e2
Use new utils fns for download_file()
alice-hannah Oct 9, 2024
00fc5c8
Use magrittr pipe instead of base (to avoid R version dependency)
alice-hannah Oct 9, 2024
6a7096f
Set default value for overwrite
alice-hannah Oct 9, 2024
86a7610
Add extra error checks
alice-hannah Oct 10, 2024
7cf5e42
Test create_file and rename_file
alice-hannah Oct 10, 2024
66a23aa
Use with_tempfile()
alice-hannah Oct 10, 2024
f2faa83
Fix incorrect file name
alice-hannah Oct 10, 2024
693bd4b
Add more context to error message
alice-hannah Oct 10, 2024
7ffdb04
New fn to get file name from Content-Disposition header
alice-hannah Oct 11, 2024
2bc9b1f
Add read_data_version function and combine Rd docs
alice-hannah Oct 11, 2024
4153e6f
Add download_helper()
alice-hannah Oct 11, 2024
1d685fd
Import rlang::.data and magrittr::`%>%` and remove %>% export
alice-hannah Oct 17, 2024
7b83ec5
Use tidyr::hoist for converting response body (list) to tibble
alice-hannah Oct 17, 2024
bcd23b9
Remove code to add time (as.POSIXct auto sets to 00:00:00)
alice-hannah Oct 18, 2024
96c4ece
Improve error handling fn
alice-hannah Oct 22, 2024
ad6c70f
Use tidyr::hoist
alice-hannah Oct 22, 2024
a19360c
Add add_participants fn
alice-hannah Oct 22, 2024
c3d7df1
If permissions not supplied, pass NULL to API request
alice-hannah Oct 22, 2024
858e59a
Test add_participants()
alice-hannah Oct 22, 2024
694d297
Add new fn and vignette link
alice-hannah Oct 23, 2024
18e2ebc
Address lintr feedback
alice-hannah Oct 23, 2024
56a5cfc
Combine upload docs and rename arg to uuid
alice-hannah Oct 31, 2024
3e513db
Add default values for size and page to docs
alice-hannah Oct 31, 2024
a7bab19
Fix bug in download_helper
alice-hannah Nov 1, 2024
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^\.lintr$
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
Package: objr
Title: Wrapper for Objective APIs
Version: 0.0.0.9005
Version: 0.0.0.9006
Authors@R: c(
person("Scottish Government", , , "statistics.enquiries@gov.scot", role = "cph"),
person("Alice", "Hannah", , "alice.hannah@gov.scot", role = c("aut", "cre"))
)
Description: An R package wrapper for Objective APIs including Objective
Connect.
License: MIT + file LICENCE
URL:https://github.com/ScotGovAnalysis/objr,
URL: https://github.com/ScotGovAnalysis/objr,
https://ScotGovAnalysis.github.io/objr/
BugReports: https://github.com/ScotGovAnalysis/objr/issues
Imports:
cli,
curl,
dplyr,
httr2,
magrittr,
rlang,
rstudioapi
rstudioapi,
tidyr
Suggests:
httptest2,
knitr,
Expand Down
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
# Generated by roxygen2: do not edit by hand

export(add_participants)
export(allow_bypass_2fa)
export(asset_info)
export(assets)
export(comments)
export(create_folder)
export(delete_asset)
export(download_file)
export(download_file_version)
export(my_user_id)
export(new_reply)
export(new_thread)
export(objr)
export(participant_bypass_2fa)
export(participants)
export(read_data)
export(read_data_version)
export(rename_asset)
export(rollback_to_version)
export(upload_file)
export(upload_file_version)
export(versions)
export(workspaces)
export(write_data)
export(write_data_version)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
84 changes: 56 additions & 28 deletions R/assets.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
#' @param workspace_uuid UUID of workspace
#' @param type List of asset types to return. Defaults to all types;
#' document, folder and link.
#' @param page Page number of responses to return (0..N).
#' @param size Number of results to be returned per page.
#' @inheritParams objr
#' @inheritParams workspaces
#'
#' @return Data frame
#' @return Tibble
#'
#' @export

Expand All @@ -30,11 +29,8 @@ assets <- function(workspace_uuid,
use_proxy = use_proxy
)

content <-
httr2::resp_body_json(response)$content |>
lapply(\(x) data.frame(asset_info_list(x)))

Reduce(dplyr::bind_rows, content)
tidyr::tibble(content = httr2::resp_body_json(response)$content) %>%
asset_info_list()

}

Expand All @@ -44,7 +40,7 @@ assets <- function(workspace_uuid,
#' @param asset_uuid UUID of asset
#' @inheritParams objr
#'
#' @return Named list containing: uuid, name, type, extension, description.
#' @return Tibble
#'
#' @export

Expand All @@ -55,10 +51,11 @@ asset_info <- function(asset_uuid,
endpoint = "assets",
url_path = list(asset_uuid),
use_proxy = use_proxy
) |>
) %>%
httr2::resp_body_json()

asset_info_list(response)
dplyr::tibble(content = list(response)) %>%
asset_info_list()

}

Expand All @@ -81,7 +78,7 @@ delete_asset <- function(asset_uuid,
method = "DELETE",
url_path = list(asset_uuid),
use_proxy = use_proxy
) |>
) %>%
httr2::resp_body_json()

if (tolower(response$status) == "complete") {
Expand All @@ -93,25 +90,56 @@ delete_asset <- function(asset_uuid,
}


na_if_null <- function(x) {
if (is.null(x)) NA else x
#' Rename an asset
#'
#' @param asset_uuid UUID of asset
#' @param new_name Character. New name to give asset.
#' @inheritParams objr
#'
#' @export

rename_asset <- function(asset_uuid,
new_name,
use_proxy = FALSE) {

response <- objr(
endpoint = "assets",
method = "PUT",
accept = "*/*",
url_path = list(asset_uuid, "name"),
body = list(name = new_name),
use_proxy = use_proxy
)

if (response$status_code == 204) {
cli::cli_alert_success("Asset renamed to {.val new_name}: {asset_uuid}.")
}

invisible(response)

}

asset_info_list <- function(x) {

list(
asset_name = x$name,
asset_ext = na_if_null(x$extension),
asset_type = x$type,
asset_uuid = x$uuid,
last_modified_by = paste(na_if_null(x[["modifiedBy"]]$givenName),
na_if_null(x[["modifiedBy"]]$familyName)),
last_modified = na_if_null(convert_from_epoch(x$modifiedTime)),
latest_version = na_if_null(x$contentVersion),
parent_name = na_if_null(x[["parent"]]$name),
parent_uuid = na_if_null(x[["parent"]]$uuid),
workspace_name = x[["workspace"]]$name,
workspace_uuid = x[["workspace"]]$uuid
)
tidyr::hoist(
x,
.data$content,
asset_name = "name",
asset_ext = "extension",
asset_type = "type",
asset_uuid = "uuid",
name1 = c("modifiedBy", "givenName"),
name2 = c("modifiedBy", "familyName"),
last_modified = "modifiedTime",
latest_version = "contentVersion",
parent_name = c("parent", "name"),
parent_uuid = c("parent", "uuid"),
workspace_name = c("workspace", "name"),
workspace_uuid = c("workspace", "uuid"),
.transform = list(last_modified = convert_from_epoch)
) %>%
dplyr::mutate(last_modified_by = paste(.data$name1, .data$name2),
.after = "last_modified") %>%
dplyr::select(-c("name1", "name2", "content"))

}
35 changes: 16 additions & 19 deletions R/comments.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,22 @@ comments <- function(created_after = NULL,
use_proxy = use_proxy
)

content <-
httr2::resp_body_json(response)$content |>
lapply(
\(content) {
data.frame(
type = content$commentType,
text = content$commentText,
author = paste(content$creator$givenName,
content$creator$familyName),
created_time = as.POSIXct(content$createdTime / 1000,
origin = "1970-01-01"),
thread_uuid = content$thread$uuid,
workspace_name = content$workspace$name,
workspace_uuid = content$workspace$uuid
)
}
)

Reduce(dplyr::bind_rows, content)
dplyr::tibble(content = httr2::resp_body_json(response)$content) %>%
tidyr::hoist(
.data$content,
type = "commentType",
text = "commentText",
name1 = c("creator", "givenName"),
name2 = c("creator", "familyName"),
created_time = "createdTime",
thread_uuid = c("thread", "uuid"),
workspace_name = c("workspace", "name"),
workspace_uuid = c("workspace", "uuid"),
.transform = list(created_time = convert_from_epoch)
) %>%
dplyr::mutate(author = paste(.data$name1, .data$name2),
.after = "text") %>%
dplyr::select(-c("name1", "name2", "content"))

}

Expand Down
2 changes: 1 addition & 1 deletion R/create_folder.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ create_folder <- function(folder_name,
description = description
),
use_proxy = use_proxy
) |>
) %>%
httr2::resp_body_json()

if (tolower(response$status) == "complete") {
Expand Down
72 changes: 72 additions & 0 deletions R/documents.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#' Get data frame of document versions
#'
#' @param document_uuid UUID of document (asset)
#' @inheritParams objr
#' @inheritParams workspaces
#'
#' @return Data frame
#'
#' @export

versions <- function(document_uuid,
page = NULL,
size = NULL,
use_proxy = FALSE) {

response <- objr(
endpoint = "documentversions",
url_query = list(documentUuid = document_uuid,
page = page,
size = size),
use_proxy = use_proxy
)

dplyr::tibble(content = httr2::resp_body_json(response)$content) %>%
tidyr::hoist(
.data$content,
asset_name = c("asset", "name"),
asset_ext = "extension",
asset_uuid = c("asset", "uuid"),
version = "version",
version_uuid = "uuid",
created_date = "createdTime",
name1 = c("createdBy", "givenName"),
name2 = c("createdBy", "familyName"),
workspace_name = c("asset", "workspace", "name"),
workspace_uuid = c("asset", "workspace", "uuid"),
.transform = list(created_date = convert_from_epoch)
) %>%
dplyr::mutate(created_by = paste(.data$name1, .data$name2),
.after = "created_date") %>%
dplyr::select(-c("name1", "name2", "content"))

}


#' Rollback a document to a previous version
#'
#' @param document_uuid UUID of document (asset)
#' @param version_uuid UUID of version to rollback to
#' @inheritParams objr
#'
#' @export

rollback_to_version <- function(document_uuid,
version_uuid,
use_proxy = FALSE) {

response <- objr(
endpoint = "documents",
method = "PUT",
url_path = list(document_uuid, "rollback"),
body = list(targetVersionUuid = version_uuid),
use_proxy = use_proxy
)

if (response$status_code == 204) {
cli::cli_alert_success("Document rollback successful.")
}

invisible(response)

}
Loading
Loading