Skip to content

refactor: remove get_apps() and usage of undocumented applications API #415

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export(create_random_name)
export(create_tag)
export(create_tag_tree)
export(dashboard_url)
export(dashboard_url_chr)
export(delete_bundle)
export(delete_image)
export(delete_runtime_cache)
Expand Down
55 changes: 0 additions & 55 deletions R/connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -383,61 +383,6 @@ Connect <- R6::R6Class(
invisible(self$DELETE(v1_url("tags", id)))
},

# content listing ----------------------------------------------------------

# filter is a named list, e.g. list(name = 'appname')
# this function supports pages
#' @description Get content items.
#' @param filter Named list containing filter conditions.
#' @param .collapse How multiple filters are combined.
#' @param .limit The limit.
#' @param page_size The page size.
get_apps = function(
filter = NULL,
.collapse = "&",
.limit = Inf,
page_size = 25
) {
path <- unversioned_url("applications")
query <- list(
count = min(page_size, .limit)
)
if (!is.null(filter)) {
query$filter <- paste(
sapply(seq_along(filter), function(i) {
sprintf("%s:%s", names(filter)[i], filter[[i]])
}),
collapse = .collapse
)
}

prg <- optional_progress_bar(
format = "downloading page :current (:tick_rate/sec) :elapsedfull",
total = NA,
clear = FALSE
)

# handle paging
prg$tick()
res <- self$GET(path, query = query)

all <- res$applications
all_l <- length(all)
query$start <- 1
while (length(res$applications) > 0 && all_l < .limit) {
prg$tick()

query$start <- query$start + page_size
query$page_size <- min(page_size, .limit - all_l)
query$cont <- res$continuation
res <- self$GET(path, query = query)

all <- c(all, res$applications)
all_l <- length(all)
}
all
},

#' @description Get a schedule.
#' @param schedule_id The schedule identifier.
get_schedule = function(schedule_id) {
Expand Down
12 changes: 8 additions & 4 deletions R/content.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ Content <- R6::R6Class(
#' @description Return the URL for this content in the Posit Connect dashboard.
#' @param pane The pane in the dashboard to link to.
get_dashboard_url = function(pane = "") {
dashboard_url_chr(self$connect$server, self$content$guid, pane = pane)
url <- self$content$dashboard_url
if (nzchar(pane)) {
url <- paste0(url, "/", pane)
}
url
},
#' @description Return the jobs for this content
jobs = function() {
Expand Down Expand Up @@ -370,7 +374,7 @@ Content <- R6::R6Class(
cat(" Content GUID: ", self$get_content()$guid, "\n", sep = "")
cat(
" Content URL: ",
dashboard_url_chr(self$get_connect()$server, self$get_content()$guid),
self$get_content()$dashboard_url,
"\n",
sep = ""
)
Expand Down Expand Up @@ -662,7 +666,7 @@ content_ensure <- function(
}
} else {
# name-based deployment
content <- connect$get_apps(list(name = name))
content <- connect$content(name = name, include = NULL)
if (length(content) > 1) {
stop(glue::glue(
"Found {length(content)} content items ",
Expand All @@ -689,7 +693,7 @@ content_ensure <- function(
content <- content[[1]]
if (!"existing" %in% .permitted) {
stop(glue::glue(
"Content with name {name} already exists at {dashboard_url_chr(connect$server, content$guid)}"
"Content with name {name} already exists at {content$dashboard_url}"
))
}
message(glue::glue(
Expand Down
32 changes: 1 addition & 31 deletions R/deploy.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ ContentTask <- R6::R6Class(
cat(" Content GUID: ", self$get_content()$guid, "\n", sep = "")
cat(
" URL: ",
dashboard_url_chr(self$get_connect()$server, self$get_content()$guid),
self$get_content()$dashboard_url,
"\n",
sep = ""
)
Expand Down Expand Up @@ -715,33 +715,3 @@ poll_task <- function(task, wait = 1, callback = message) {
dashboard_url <- function(content, pane = "") {
content$get_dashboard_url(pane = pane)
}

#' Build a Dashboard URL from Character Vectors
#'
#' Returns the URL for the content dashboard (opened to the selected pane).
#' NOTE: this takes a character object for performance optimization.
#'
#' @param connect_url character The base URL of the Connect server
#' @param content_guid character The guid for the content item in question
#' @param pane character The pane in the dashboard to link to
#'
#' @return character The dashboard URL for the content provided
#'
#' @family content functions
#' @export
dashboard_url_chr <- function(connect_url, content_guid, pane = "") {
purrr::pmap_chr(
list(x = connect_url, y = content_guid, z = pane),
function(x, y, z) {
paste(
x,
"connect",
"#",
"apps",
y,
z,
sep = "/"
)
}
)
}
6 changes: 3 additions & 3 deletions R/promote.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ promote <- function(from, to, to_key, from_key, name) {
from_client <- connect(server = from, api_key = from_key)
to_client <- connect(server = to, api_key = to_key)

# find app on "from" server
from_app <- from_client$get_apps(list(name = name))
# find content on "from" server
from_app <- from_client$content(name = name, include = NULL)
if (length(from_app) != 1) {
stop(sprintf(
"Found %d apps matching app name %s on %s. Content must have a unique name.",
Expand All @@ -39,7 +39,7 @@ promote <- function(from, to, to_key, from_key, name) {
from
))
}
from_app <- content_item(from_client, guid = from_app[[1]]$guid)
from_app <- Content$new(connect = from_client, content = from_app[[1]])

# download bundle
bundle <- download_bundle(from_app)
Expand Down
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ generate_R6_print_output <- # nolint: object_name_linter
ex_content <- list(
guid = "content-guid",
title = "content-title",
dashboard_url = "http://test_host/connect/#/apps/content-guid/",
url = "http://content-url"
)
cnt1 <- Content$new(connect = con, ex_content)
Expand Down
1 change: 0 additions & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ reference:
- browse_solo
- create_random_name
- dashboard_url
- dashboard_url_chr
- delete_runtime_cache


Expand Down
24 changes: 0 additions & 24 deletions man/PositConnect.Rd

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

1 change: 0 additions & 1 deletion man/content_delete.Rd

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

1 change: 0 additions & 1 deletion man/content_item.Rd

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

1 change: 0 additions & 1 deletion man/content_title.Rd

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

1 change: 0 additions & 1 deletion man/content_update.Rd

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

1 change: 0 additions & 1 deletion man/create_random_name.Rd

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

1 change: 0 additions & 1 deletion man/dashboard_url.Rd

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

54 changes: 0 additions & 54 deletions man/dashboard_url_chr.Rd

This file was deleted.

1 change: 0 additions & 1 deletion man/delete_thumbnail.Rd

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

1 change: 0 additions & 1 deletion man/delete_vanity_url.Rd

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

1 change: 0 additions & 1 deletion man/deploy_repo.Rd

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

1 change: 0 additions & 1 deletion man/environment.Rd

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

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

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

1 change: 0 additions & 1 deletion man/get_image.Rd

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

1 change: 0 additions & 1 deletion man/get_job.Rd

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

Loading