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

Add function to delete assets #16

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: objr
Title: Wrapper for Objective APIs
Version: 0.0.0.9002
Version: 0.0.0.9003
Authors@R: c(
person("Scottish Government", , , "[email protected]", role = "cph"),
person("Alice", "Hannah", , "[email protected]", c("aut", "cre"))
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export(allow_bypass_2fa)
export(asset_info)
export(comments)
export(create_folder)
export(delete_asset)
export(download_file)
export(my_user_id)
export(my_workspaces)
Expand Down
27 changes: 27 additions & 0 deletions R/assets.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,30 @@ asset_info <- function(asset_uuid,
response[c("uuid", "name", "type", "extension", "description")]

}


#' Delete an asset
#'
#' @param asset_uuid UUID of asset
#' @inheritParams objr
#'
#' @export

delete_asset <- function(asset_uuid,
use_proxy = FALSE) {

response <- objr(
endpoint = "assets",
method = "DELETE",
url_path = list(asset_uuid),
use_proxy = use_proxy
) |>
httr2::resp_body_json()

if(tolower(response$status) == "complete") {
cli::cli_alert_success("Asset deleted: {asset_uuid}.")
}

invisible(response)

}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ reference:
- download_file
- upload_file
- new_version
- delete_asset

- subtitle: Comments
desc: View comments and create new threads and replies in workspaces
Expand Down
16 changes: 16 additions & 0 deletions man/delete_asset.Rd

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

14 changes: 14 additions & 0 deletions tests/testthat/api/assets/test_asset_uuid-DELETE.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
structure(list(method = "POST", url = "https://api/assets/test_asset_uuid",
status_code = 200L, headers = structure(list(
Date = "Tue, 09 Apr 2024 13:20:11 GMT",
`Content-Type` = "application/json", `Transfer-Encoding` = "chunked",
Connection = "keep-alive", `X-CONNECT-MDC` = "apisyjgCiSS",
`X-Frame-Options` = "deny", `X-XSS-Protection` = "1; mode=block",
`Cache-Control` = "no-cache, no-store", Expires = "0",
Pragma = "no-cache", `Strict-Transport-Security` = "max-age=31536000 ; includeSubDomains",
`Content-Security-Policy` = "script-src 'self' 'unsafe-inline'",
`X-Content-Type-Options` = "nosniff", `Referrer-Policy` = "strict-origin-when-cross-origin",
`Feature-Policy` = "vibrate 'none'; geolocation 'none'",
Authorization = "REDACTED", `Set-Cookie` = "REDACTED"), class = "httr2_headers"),
body = charToRaw("{\"model\":[\"Asset\"],\"uuid\":[\"test_asset_uuid\"],\"status\":[\"COMPLETE\"]}"),
cache = new.env(parent = emptyenv())), class = "httr2_response")
36 changes: 36 additions & 0 deletions tests/testthat/test-assets.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,39 @@ with_mock_api({
})

})


# delete_asset ----

without_internet({

test_that("Valid request", {

expect_DELETE(
delete_asset(asset_uuid = "test_asset_uuid"),
paste0("https://secure.objectiveconnect.co.uk/publicapi/1/assets/",
"test_asset_uuid")
)

})

})

with_mock_api({

test_that("Function returns invisible", {

expect_invisible(
suppressMessages(delete_asset(asset_uuid = "test_asset_uuid"))
)

})

test_that("Function returns success message", {

expect_message(delete_asset(asset_uuid = "test_asset_uuid"))

})

})