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

feat: new function set_content_image(), deprecate old set_image_* functions #302

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 0.3.0
Date: 2024-09-04 18:50:37 UTC
SHA: 2e2c8869b54029acd6270eadee13cddb8967765c
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export(repo_check_branches)
export(repo_check_branches_ref)
export(repo_check_manifest_dirs)
export(schedule_describe)
export(set_content_image)
export(set_content_tag_tree)
export(set_content_tags)
export(set_environment_all)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Unreleased

## Breaking changes

- `set_image_path()`, `set_image_url()`, and `set_image_webshot()` have been
deprecated and will be removed in a future update. They have been replaced by
`set_content_image(content, path)`, which works both with local file paths and
remote URLs to images.

## Enhancements and fixes

- Fixed a bug where timestamps from Connect not in UTC were parsed as `NA` (#290)
Expand Down
60 changes: 38 additions & 22 deletions R/deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -487,49 +487,65 @@ has_image <- function(content) {
#'
#' Set the Content Image using a variety of methods.
#'
#' NOTE: `set_image_webshot()` requires [webshot2::webshot()], but currently
#' skips and warns for any content that requires authentication until the
#' `webshot2` package supports authentication.
#'
#' @param content A content object
#' @param path The path to an image on disk
#' @param url The url for an image
#' @param ... Additional arguments passed on to [webshot2::webshot()]
#' @param path A file path or URL to an image
#'
#' @rdname set_image
#' @family content functions
#' @rdname set_content_image
#' @export
set_image_path <- function(content, path) {
warn_experimental("set_image_path")
set_content_image <- function(content, path) {
warn_experimental("set_content_image")
validate_R6_class(content, "Content")
guid <- content$get_content()$guid

valid_path <- NULL
if (file.exists(path)) {
valid_path <- path
} else {
parsed <- httr::parse_url(path)
if (parsed$scheme %in% c("http", "https")) {
valid_path <- fs::file_temp(pattern = "image", ext = fs::path_ext(parsed[["path"]]))
httr::GET(url, httr::write_disk(valid_path))
on.exit(unlink(valid_path))
}
}
if (is.null(valid_path)) {
stop("Could not locate image at `path`")
}

guid <- content$get_content()$guid
con <- content$get_connect()

res <- con$POST(
path = unversioned_url("applications", guid, "image"),
body = httr::upload_file(path)
body = httr::upload_file(valid_path)
)

# return the input (in case it inherits more than just Content)
content
}

#' @rdname set_image

#' @rdname set_content_image
#' @export
set_image_url <- function(content, url) {
warn_experimental("set_image_url")
validate_R6_class(content, "Content")
parsed_url <- httr::parse_url(url)
imgfile <- fs::file_temp(pattern = "image", ext = fs::path_ext(parsed_url[["path"]]))
httr::GET(url, httr::write_disk(imgfile))
set_image_path <- function(content, path) {
lifecycle::deprecate_warn("0.3.1", "set_image_path()", "set_content_image()")
set_content_image(content, path)
}

set_image_path(content = content, path = imgfile)

#' @rdname set_content_image
#' @export
set_image_url <- function(content, path) {
lifecycle::deprecate_warn("0.3.1", "set_image_url()", "set_content_image()")
set_content_image(content, path)
}

#' @rdname set_image


#' @rdname set_content_image
#' @export
set_image_webshot <- function(content, ...) {
lifecycle::deprecate_warn("0.3.1", "set_image_webshot()", "set_content_image()")
warn_experimental("set_image_webshot")
validate_R6_class(content, "Content")
imgfile <- fs::file_temp(pattern = "webshot", ext = ".png")
Expand Down Expand Up @@ -561,7 +577,7 @@ set_image_webshot <- function(content, ...) {
!!!args
))

set_image_path(content = content, path = imgfile)
set_content_image(content = content, path = imgfile)
}


Expand Down
6 changes: 3 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ content <- client %>%
# set an image for content

content %>%
set_image_path("./my/local/image.png")
set_content_image("./my/local/image.png")

content %>%
set_image_url("http://url.example.com/image.png")
set_content_image("http://url.example.com/image.png")

# set image and a vanity URL

content %>%
set_image_path("./my/local/image.png") %>%
set_content_image("./my/local/image.png") %>%
set_vanity_url("/my-awesome-app")

# change access_type to "anyone"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ content <- client %>%
# set an image for content

content %>%
set_image_path("./my/local/image.png")
set_content_image("./my/local/image.png")

content %>%
set_image_url("http://url.example.com/image.png")
set_content_image("http://url.example.com/image.png")

# set image and a vanity URL

content %>%
set_image_path("./my/local/image.png") %>%
set_content_image("./my/local/image.png") %>%
set_vanity_url("/my-awesome-app")

# change access_type to "anyone"
Expand Down
2 changes: 1 addition & 1 deletion man/content_delete.Rd

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

2 changes: 1 addition & 1 deletion man/content_item.Rd

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

2 changes: 1 addition & 1 deletion man/content_title.Rd

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

2 changes: 1 addition & 1 deletion man/content_update.Rd

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

2 changes: 1 addition & 1 deletion man/create_random_name.Rd

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

2 changes: 1 addition & 1 deletion man/dashboard_url.Rd

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

2 changes: 1 addition & 1 deletion man/dashboard_url_chr.Rd

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

2 changes: 1 addition & 1 deletion man/delete_vanity_url.Rd

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

2 changes: 1 addition & 1 deletion man/deploy_repo.Rd

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

2 changes: 1 addition & 1 deletion man/environment.Rd

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

4 changes: 2 additions & 2 deletions man/get_bundles.Rd

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

2 changes: 1 addition & 1 deletion man/get_image.Rd

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

2 changes: 1 addition & 1 deletion man/get_vanity_url.Rd

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

2 changes: 1 addition & 1 deletion man/git.Rd

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

2 changes: 1 addition & 1 deletion man/jobs.Rd

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

2 changes: 1 addition & 1 deletion man/permissions.Rd

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

23 changes: 10 additions & 13 deletions man/set_image.Rd → man/set_content_image.Rd

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

2 changes: 1 addition & 1 deletion man/set_run_as.Rd

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

2 changes: 1 addition & 1 deletion man/set_vanity_url.Rd

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

2 changes: 1 addition & 1 deletion man/swap_vanity_url.Rd

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

2 changes: 1 addition & 1 deletion man/verify_content_name.Rd

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

Loading
Loading