Skip to content

Commit

Permalink
Merge pull request #993 from rstudio/content-category-cloud
Browse files Browse the repository at this point in the history
set content category for outputs and revisions
  • Loading branch information
mslynch authored Sep 11, 2023
2 parents ad6c4aa + 0e0ffe2 commit 3e96601
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
9 changes: 6 additions & 3 deletions R/client-cloud.R
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ cloudClient <- function(service, authInfo) {
GET(service, authInfo, path, query)
},

createApplication = function(name, title, template, accountId, appMode) {
createApplication = function(name, title, template, accountId, appMode, contentCategory = NULL) {
json <- list()
json$name <- name
json$application_type <- if (appMode %in% c("rmd-static", "quarto-static", "static")) "static" else "connect"
Expand All @@ -180,6 +180,8 @@ cloudClient <- function(service, authInfo) {
json$space <- currentProject$space_id
}

json$content_category <- contentCategory

output <- POST_JSON(service, authInfo, "/outputs", json)
path <- paste0("/applications/", output$source_id)
application <- GET(service, authInfo, path)
Expand Down Expand Up @@ -224,9 +226,10 @@ cloudClient <- function(service, authInfo) {
)
},

createRevision = function(application) {
createRevision = function(application, contentCategory) {
path <- paste0("/outputs/", application$id, "/revisions")
revision <- POST_JSON(service, authInfo, path, data.frame())
json <- list(content_category = contentCategory)
revision <- POST_JSON(service, authInfo, path, json)
revision$application_id
},

Expand Down
2 changes: 1 addition & 1 deletion R/client-connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ connectClient <- function(service, authInfo) {
listApplicationsRequest(service, authInfo, path, query, "applications")
},

createApplication = function(name, title, template, accountId, appMode) {
createApplication = function(name, title, template, accountId, appMode, contentCategory) {
# add name; inject title if specified
details <- list(name = name)
if (!is.null(title) && nzchar(title))
Expand Down
2 changes: 1 addition & 1 deletion R/client-shinyapps.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ shinyAppsClient <- function(service, authInfo) {
GET(service, authInfo, path, query)
},

createApplication = function(name, title, template, accountId, appMode) {
createApplication = function(name, title, template, accountId, appMode, contentCategory) {
json <- list()
json$name <- name
# the title field is only used on connect
Expand Down
5 changes: 3 additions & 2 deletions R/deployApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ deployApp <- function(appDir = getwd(),
target$appTitle,
"shiny",
accountDetails$accountId,
appMetadata$appMode
appMetadata$appMode,
contentCategory
)
taskComplete(quiet, "Created application with id {.val {application$id}}")
} else {
Expand All @@ -402,7 +403,7 @@ deployApp <- function(appDir = getwd(),
taskComplete(quiet, "Found application {.url {application$url}}")

if (identical(application$type, "static")) {
application$application_id <- client$createRevision(application)
application$application_id <- client$createRevision(application, contentCategory)
}

application
Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test-client-cloud.R
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ test_that("Create static application", {
content = function(methodAndPath, match, contentFile, ...) {
content <- jsonlite::fromJSON(readChar(contentFile, file.info(contentFile)$size))
expect_equal(content$application_type, "static")
expect_equal(content$content_category, "document")
list(
"id" = 1,
"source_id" = 2,
Expand Down Expand Up @@ -339,7 +340,7 @@ test_that("Create static application", {
)
client <- cloudClient(fakeService, NULL)

app <- client$createApplication("test app", "unused?", "unused?", "unused?", "static")
app <- client$createApplication("test app", "unused?", "unused?", "unused?", "static", "document")

expect_equal(app$id, 1)
expect_equal(app$application_id, 2)
Expand All @@ -353,6 +354,7 @@ test_that("Create static server-side-rendered application", {
content <- jsonlite::fromJSON(readChar(contentFile, file.info(contentFile)$size))
expect_equal(content$application_type, "static")
expect_equal(content$render_by, "server")
expect_equal(content$content_category, "document")
list(
"id" = 1,
"source_id" = 2,
Expand Down Expand Up @@ -383,7 +385,7 @@ test_that("Create static server-side-rendered application", {
)
client <- cloudClient(fakeService, NULL)

app <- client$createApplication("test app", "unused?", "unused?", "unused?", "quarto-static")
app <- client$createApplication("test app", "unused?", "unused?", "unused?", "quarto-static", "document")

expect_equal(app$id, 1)
expect_equal(app$application_id, 2)
Expand Down Expand Up @@ -452,6 +454,7 @@ test_that("Create static RMD application", {
content <- jsonlite::fromJSON(readChar(contentFile, file.info(contentFile)$size))
expect_equal(content$application_type, "static")
expect_equal(content$render_by, "server")
expect_equal(content$content_category, "document")
list(
"id" = 1,
"source_id" = 2,
Expand Down Expand Up @@ -482,7 +485,7 @@ test_that("Create static RMD application", {
)
client <- cloudClient(fakeService, NULL)

app <- client$createApplication("test app", "unused?", "unused?", "1", "rmd-static")
app <- client$createApplication("test app", "unused?", "unused?", "1", "rmd-static", "document")

expect_equal(app$id, 1)
expect_equal(app$application_id, 2)
Expand Down

0 comments on commit 3e96601

Please sign in to comment.