From b9e5b72b6ae1dd60fd805b1835e30899c0acc035 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Fri, 18 Jan 2019 08:43:14 -0500 Subject: [PATCH 01/62] bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 533bb07b..87358513 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: connectApiUtils Type: Package Title: Utilities for Interacting with RStudio Connect's API -Version: 0.1.0 +Version: 0.1.0.9000 Author: Sean Lopp Maintainer: Sean Lopp Description: Helpful class for interacting with Connect's API and some example utility functions. From 437f187d578022afd784745619e5468076956a0f Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Fri, 18 Jan 2019 08:43:24 -0500 Subject: [PATCH 02/62] move create_app to experimental endpoint --- R/connect.R | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/R/connect.R b/R/connect.R index a8084b1b..2d5d1f75 100644 --- a/R/connect.R +++ b/R/connect.R @@ -211,9 +211,16 @@ Connect <- R6::R6Class( ) }, - create_app = function(name) { - path = sprintf('applications') - self$POST(path, list(name = tolower(gsub("\\s","",name)), title = name )) + create_app = function(name, title = name, ...) { + path = sprintf('experimental/content') + other_params <- rlang::dots_list(...) + self$POST( + path, + c( + list(name = tolower(gsub("\\s","",name)), title = title ), + other_params + ) + ) }, get_docs = function(docs = "api") { From 374b660057db3da20442a2fa6086380f8fd6cbd9 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Fri, 18 Jan 2019 08:46:41 -0500 Subject: [PATCH 03/62] add wait parameter move tasks to experimental endpoint --- R/connect.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/connect.R b/R/connect.R index 2d5d1f75..994a6c2c 100644 --- a/R/connect.R +++ b/R/connect.R @@ -154,8 +154,8 @@ Connect <- R6::R6Class( task_id }, - get_task = function(task_id, start = 0) { - path = sprintf('tasks/%s?first_status=%d', task_id, start) + get_task = function(task_id, start = 0, wait = 5) { + path = sprintf('experimental/tasks/%s?first=%d&wait=%d', task_id, start, wait) self$GET(path) }, From cf64caeb6dd3549af1b26fd76d98c534e3767a19 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 05:47:17 -0500 Subject: [PATCH 04/62] fix deployment endpoint --- R/connect.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/connect.R b/R/connect.R index 994a6c2c..737537ea 100644 --- a/R/connect.R +++ b/R/connect.R @@ -147,9 +147,9 @@ Connect <- R6::R6Class( new_bundle_id }, - activate_bundle = function(app_id, bundle_id) { - path <- sprintf('applications/%d/deploy', app_id) - res <- self$POST(path, list(bundle = bundle_id)) + activate_bundle = function(app_guid, bundle_id) { + path <- sprintf('experimental/content/%s/deploy', app_guid) + res <- self$POST(path, list(bundle_id = as.character(bundle_id))) task_id <- res$id task_id }, From 25c52d6123ca7e39d2ffa250ca28f5d34b9ba3b6 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 05:48:07 -0500 Subject: [PATCH 05/62] rename activate_bundle to deploy_bundle --- R/connect.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/connect.R b/R/connect.R index 737537ea..4664e26f 100644 --- a/R/connect.R +++ b/R/connect.R @@ -147,10 +147,10 @@ Connect <- R6::R6Class( new_bundle_id }, - activate_bundle = function(app_guid, bundle_id) { + deploy_bundle = function(app_guid, bundle_id) { path <- sprintf('experimental/content/%s/deploy', app_guid) res <- self$POST(path, list(bundle_id = as.character(bundle_id))) - task_id <- res$id + task_id <- res[["task_id"]] task_id }, From c5387ebfe4e14f2a54b8e6618cf360cd1e0a6766 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 05:50:36 -0500 Subject: [PATCH 06/62] add news --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 NEWS.md diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 00000000..db50ef49 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,5 @@ +# connectApiUtils 0.1.0.9000 + +* Rename `connect$activate_bundle` to `connect$deploy_bundle` +* Update `connect` R6 object to be compatible with Connect 1.7.0 APIs +* Added a `NEWS.md` file to track changes to the package. From 3fdccc0b973e378b0dbcdf9aa209d0f5ed8bd2ae Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:27:48 -0500 Subject: [PATCH 07/62] rename create_app to content_create --- R/connect.R | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/R/connect.R b/R/connect.R index 4664e26f..eb92d66e 100644 --- a/R/connect.R +++ b/R/connect.R @@ -133,6 +133,18 @@ Connect <- R6::R6Class( path <- sprintf('schedules/%d', schedule_id) self$GET(path) }, + + content_create = function(name, title = name, ...) { + path = sprintf('experimental/content') + other_params <- rlang::dots_list(...) + self$POST( + path, + c( + list(name = tolower(gsub("\\s","",name)), title = title ), + other_params + ) + ) + }, download_bundle = function(bundle_id, to_path = tempfile()) { path <- sprintf('bundles/%d/download', bundle_id) @@ -211,18 +223,6 @@ Connect <- R6::R6Class( ) }, - create_app = function(name, title = name, ...) { - path = sprintf('experimental/content') - other_params <- rlang::dots_list(...) - self$POST( - path, - c( - list(name = tolower(gsub("\\s","",name)), title = title ), - other_params - ) - ) - }, - get_docs = function(docs = "api") { stopifnot(docs %in% c("admin", "user", "api")) utils::browseURL(paste0(self$host, '/__docs__/', docs)) From ae0348333fb8433d632de85e242e99c86c0c4470 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:28:02 -0500 Subject: [PATCH 08/62] rename upload_bundle to content_upload --- R/connect.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/connect.R b/R/connect.R index eb92d66e..33facf7d 100644 --- a/R/connect.R +++ b/R/connect.R @@ -152,10 +152,11 @@ Connect <- R6::R6Class( to_path }, - upload_bundle = function(bundle_path, app_id) { - path <- sprintf('applications/%d/upload', app_id) + content_upload = function(bundle_path, app_guid) { + # todo : add X-Content-Checksum + path <- sprintf('experimental/content/%d/upload', app_guid) res <- self$POST(path, httr::upload_file(bundle_path), 'raw') - new_bundle_id <- res$id + new_bundle_id <- res[["task_id"]] new_bundle_id }, From 57d8567cd14050071a4e205376d6f78fa055def9 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:28:14 -0500 Subject: [PATCH 09/62] rename deploy_bundle to content_deploy --- R/connect.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/connect.R b/R/connect.R index 33facf7d..8e9fbed1 100644 --- a/R/connect.R +++ b/R/connect.R @@ -160,7 +160,7 @@ Connect <- R6::R6Class( new_bundle_id }, - deploy_bundle = function(app_guid, bundle_id) { + content_deploy = function(app_guid, bundle_id) { path <- sprintf('experimental/content/%s/deploy', app_guid) res <- self$POST(path, list(bundle_id = as.character(bundle_id))) task_id <- res[["task_id"]] From e32ab9b7ae634dda55a1c62fa5ec5a866e9a341a Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:28:20 -0500 Subject: [PATCH 10/62] add get_content endpoint --- R/connect.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/connect.R b/R/connect.R index 8e9fbed1..1cc6f8e1 100644 --- a/R/connect.R +++ b/R/connect.R @@ -166,6 +166,12 @@ Connect <- R6::R6Class( task_id <- res[["task_id"]] task_id }, + + get_content = function(app_guid) { + path <- sprintf("experimental/content/%s", app_guid) + res <- self$GET(path) + return(res) + } get_task = function(task_id, start = 0, wait = 5) { path = sprintf('experimental/tasks/%s?first=%d&wait=%d', task_id, start, wait) From 4f8af0ce7b6e5d4bf9bb109445a55a196cc7fe31 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:39:09 -0500 Subject: [PATCH 11/62] add dependency on glue --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 87358513..2b8a6c2e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,7 +10,8 @@ Encoding: UTF-8 Imports: R6, httr, - rlang + rlang, + glue RoxygenNote: 6.0.1 Suggests: rmarkdown, htmltools, From 5893b9e500a10d7f87f4753d491a2b5605358b6f Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:39:30 -0500 Subject: [PATCH 12/62] add get_audit_logs endpoint --- R/connect.R | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/R/connect.R b/R/connect.R index 1cc6f8e1..9a2af72b 100644 --- a/R/connect.R +++ b/R/connect.R @@ -233,8 +233,21 @@ Connect <- R6::R6Class( get_docs = function(docs = "api") { stopifnot(docs %in% c("admin", "user", "api")) utils::browseURL(paste0(self$host, '/__docs__/', docs)) + }, + + get_audit_logs = function(limit = 20L, previous = NULL, next = NULL, asc_order = TRUE) { + path <- glue::glue( + "v1/audit_logs?limit={limit}", + "{protect(previous, '&previous=')}", + "{protect(next, '&next=')}", + "&ascOrder={asc_order}" + ) + self$GET( + path = path + ) } + ) ) From 9e92f2cf1cc2f0dc88d5bb5447b15e2b60fb902c Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:42:41 -0500 Subject: [PATCH 13/62] add protect utility function --- R/utils.R | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 R/utils.R diff --git a/R/utils.R b/R/utils.R new file mode 100644 index 00000000..514883c5 --- /dev/null +++ b/R/utils.R @@ -0,0 +1,7 @@ +protect <- function(expr, prefix) { + if (is.null(expr)) { + return("") + } else { + return(paste0(prefix, expr)) + } +} From ed6a34740bb8e547b1d0ceb5dd6a51ce3245a154 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:42:50 -0500 Subject: [PATCH 14/62] change project settings --- connectApiUtils.Rproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/connectApiUtils.Rproj b/connectApiUtils.Rproj index 21a4da08..8de5cfd3 100644 --- a/connectApiUtils.Rproj +++ b/connectApiUtils.Rproj @@ -12,6 +12,8 @@ Encoding: UTF-8 RnwWeave: Sweave LaTeX: pdfLaTeX +AutoAppendNewline: Yes + BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source From be533c86b4004479c305f1a295eb9d8518a6886e Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:44:33 -0500 Subject: [PATCH 15/62] fix variable assignment --- R/connect.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/connect.R b/R/connect.R index 9a2af72b..a77c4d15 100644 --- a/R/connect.R +++ b/R/connect.R @@ -135,7 +135,7 @@ Connect <- R6::R6Class( }, content_create = function(name, title = name, ...) { - path = sprintf('experimental/content') + path <- sprintf('experimental/content') other_params <- rlang::dots_list(...) self$POST( path, @@ -174,17 +174,17 @@ Connect <- R6::R6Class( } get_task = function(task_id, start = 0, wait = 5) { - path = sprintf('experimental/tasks/%s?first=%d&wait=%d', task_id, start, wait) + path <- sprintf('experimental/tasks/%s?first=%d&wait=%d', task_id, start, wait) self$GET(path) }, get_users = function(page_number = 1){ - path = sprintf('v1/users?page_number=%d', page_number) + path <- sprintf('v1/users?page_number=%d', page_number) self$GET(path) }, get_users_remote = function(prefix) { - path = sprintf('v1/users/remote?prefix=%s', prefix) + path <- sprintf('v1/users/remote?prefix=%s', prefix) self$GET(path) }, @@ -193,7 +193,7 @@ Connect <- R6::R6Class( password, user_must_set_password, user_role, username ) { - path = sprintf('v1/users') + path <- sprintf('v1/users') self$POST(path = path, body = list( email = email, @@ -207,7 +207,7 @@ Connect <- R6::R6Class( }, lock_user = function(user_guid) { - path = sprintf('v1/users/%s/lock', user_guid) + path <- sprintf('v1/users/%s/lock', user_guid) message(path) self$POST(path = path, body = list(locked = TRUE) @@ -215,7 +215,7 @@ Connect <- R6::R6Class( }, unlock_user = function(user_guid) { - path = sprintf('v1/users/%s/lock', user_guid) + path <- sprintf('v1/users/%s/lock', user_guid) self$POST( path = path, body = list(locked = FALSE) @@ -223,7 +223,7 @@ Connect <- R6::R6Class( }, update_user = function(user_guid, email, ...) { - path = sprintf('v1/users/%s', user_guid) + path <- sprintf('v1/users/%s', user_guid) self$PUT( path = path, body = c(list(email = email), rlang::dots_list(...)) From bff91852d95ef12cae8da458a540a91bf0b58510 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:54:20 -0500 Subject: [PATCH 16/62] fix experimental endpoint paths --- R/connect.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/connect.R b/R/connect.R index a77c4d15..9edb5a0a 100644 --- a/R/connect.R +++ b/R/connect.R @@ -135,7 +135,7 @@ Connect <- R6::R6Class( }, content_create = function(name, title = name, ...) { - path <- sprintf('experimental/content') + path <- sprintf('v1/experimental/content') other_params <- rlang::dots_list(...) self$POST( path, @@ -154,27 +154,27 @@ Connect <- R6::R6Class( content_upload = function(bundle_path, app_guid) { # todo : add X-Content-Checksum - path <- sprintf('experimental/content/%d/upload', app_guid) + path <- sprintf('v1/experimental/content/%d/upload', app_guid) res <- self$POST(path, httr::upload_file(bundle_path), 'raw') new_bundle_id <- res[["task_id"]] new_bundle_id }, content_deploy = function(app_guid, bundle_id) { - path <- sprintf('experimental/content/%s/deploy', app_guid) + path <- sprintf('v1/experimental/content/%s/deploy', app_guid) res <- self$POST(path, list(bundle_id = as.character(bundle_id))) task_id <- res[["task_id"]] task_id }, get_content = function(app_guid) { - path <- sprintf("experimental/content/%s", app_guid) + path <- sprintf("v1/experimental/content/%s", app_guid) res <- self$GET(path) return(res) } get_task = function(task_id, start = 0, wait = 5) { - path <- sprintf('experimental/tasks/%s?first=%d&wait=%d', task_id, start, wait) + path <- sprintf('v1/experimental/tasks/%s?first=%d&wait=%d', task_id, start, wait) self$GET(path) }, From 5e775ec69f9e7c2cb8a27e16a835aa245427ca30 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:54:30 -0500 Subject: [PATCH 17/62] add headers --- R/connect.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/connect.R b/R/connect.R index 9edb5a0a..41a57bdb 100644 --- a/R/connect.R +++ b/R/connect.R @@ -229,7 +229,11 @@ Connect <- R6::R6Class( body = c(list(email = email), rlang::dots_list(...)) ) }, + + # instrumentation -------------------------------------------- + # misc utilities -------------------------------------------- + get_docs = function(docs = "api") { stopifnot(docs %in% c("admin", "user", "api")) utils::browseURL(paste0(self$host, '/__docs__/', docs)) @@ -248,6 +252,7 @@ Connect <- R6::R6Class( } + # end -------------------------------------------------------- ) ) From 3db247464ce4b6d9cb11a83b137be465d13fa362 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:54:47 -0500 Subject: [PATCH 18/62] add get_server_settings_r function --- R/connect.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/connect.R b/R/connect.R index 41a57bdb..7b3ff531 100644 --- a/R/connect.R +++ b/R/connect.R @@ -249,8 +249,14 @@ Connect <- R6::R6Class( self$GET( path = path ) - } + }, + get_server_settings_r = function() { + path <- "v1/server_settings/r" + self$GET( + path = path + ) + } # end -------------------------------------------------------- ) From a48dfe535e6332649bbc9a24e7e9b852f535d5cb Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 08:58:28 -0500 Subject: [PATCH 19/62] add get_server_settings endpoint --- R/connect.R | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/R/connect.R b/R/connect.R index 7b3ff531..d0f713a4 100644 --- a/R/connect.R +++ b/R/connect.R @@ -256,6 +256,13 @@ Connect <- R6::R6Class( self$GET( path = path ) + }, + + get_server_settings = function() { + path <- "server_settings" + self$GET( + path = path + ) } # end -------------------------------------------------------- From f5cfafdfb145d54699f0925a66da0f7af83ba553 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:01:26 -0500 Subject: [PATCH 20/62] add headers --- R/connect.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/connect.R b/R/connect.R index d0f713a4..070baa47 100644 --- a/R/connect.R +++ b/R/connect.R @@ -134,6 +134,8 @@ Connect <- R6::R6Class( self$GET(path) }, + # content ---------------------------------------------------------- + content_create = function(name, title = name, ...) { path <- sprintf('v1/experimental/content') other_params <- rlang::dots_list(...) @@ -178,6 +180,8 @@ Connect <- R6::R6Class( self$GET(path) }, + # users ----------------------------------------------- + get_users = function(page_number = 1){ path <- sprintf('v1/users?page_number=%d', page_number) self$GET(path) From 05bfbb9b368dc4d28da83bfc395229e0520eb46e Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:08:54 -0500 Subject: [PATCH 21/62] add testthat --- DESCRIPTION | 6 ++++-- tests/testthat.R | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 tests/testthat.R diff --git a/DESCRIPTION b/DESCRIPTION index 2b8a6c2e..3a0cfce0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,11 +13,13 @@ Imports: rlang, glue RoxygenNote: 6.0.1 -Suggests: rmarkdown, +Suggests: + rmarkdown, htmltools, flexdashboard, webshot, lubridate, ggplot2, - gridExtra + gridExtra, + testthat Remotes: slopp/webshot diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 00000000..b72b1cff --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(connectApiUtils) + +test_check("connectApiUtils") From 8877e7d015f34759d7d1c46b94b61803f40a018c Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:16:48 -0500 Subject: [PATCH 22/62] fix comma --- R/connect.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/connect.R b/R/connect.R index 070baa47..321a0016 100644 --- a/R/connect.R +++ b/R/connect.R @@ -173,7 +173,7 @@ Connect <- R6::R6Class( path <- sprintf("v1/experimental/content/%s", app_guid) res <- self$GET(path) return(res) - } + }, get_task = function(task_id, start = 0, wait = 5) { path <- sprintf('v1/experimental/tasks/%s?first=%d&wait=%d', task_id, start, wait) From 12a4a887d34b5c5fb983df6781d06d7592d3f12f Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:16:57 -0500 Subject: [PATCH 23/62] avoid next keyword --- R/connect.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/connect.R b/R/connect.R index 321a0016..16c49dd5 100644 --- a/R/connect.R +++ b/R/connect.R @@ -243,11 +243,11 @@ Connect <- R6::R6Class( utils::browseURL(paste0(self$host, '/__docs__/', docs)) }, - get_audit_logs = function(limit = 20L, previous = NULL, next = NULL, asc_order = TRUE) { + get_audit_logs = function(limit = 20L, previous = NULL, nxt = NULL, asc_order = TRUE) { path <- glue::glue( "v1/audit_logs?limit={limit}", - "{protect(previous, '&previous=')}", - "{protect(next, '&next=')}", + "{safequery(previous, '&previous=')}", + "{safequery(nxt, '&next=')}", "&ascOrder={asc_order}" ) self$GET( From a674e2310a4ba18017dc0e8519ffdc2925974e8e Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:24:20 -0500 Subject: [PATCH 24/62] add inst_content_visits endpoint --- R/connect.R | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/R/connect.R b/R/connect.R index 16c49dd5..7cb5825e 100644 --- a/R/connect.R +++ b/R/connect.R @@ -235,6 +235,34 @@ Connect <- R6::R6Class( }, # instrumentation -------------------------------------------- + + inst_content_visits = function( + content_guid = NULL, + min_data_version = NULL, + from = NULL, + to = NULL, + limit = 20, + previous = NULL, + nxt = NULL, + asc_order = TRUE + ) { + path <- glue::glue( + "v1/instrumentation/content/visits?", + glue::glue( + "{safequery(content_guid, 'content_guid=')}", + "{safequery(min_data_version, 'content_guid=')}", + "{safequery(from, 'from=')}", + "{safequery(to, 'to=')}", + "{safequery(limit, 'limit=')}", + "{safequery(previous, 'previous=')}", + "{safequery(nxt, 'next=')}", + "{safequery(asc_order, 'asc_order=')}", + .sep = "&" + ) + ) + + self$GET(path) + }, # misc utilities -------------------------------------------- From 1eac17637f4669572a839b470d5fcfe5f8cef62e Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:24:38 -0500 Subject: [PATCH 25/62] rename function and add default --- R/utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 514883c5..b34b8510 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,4 +1,4 @@ -protect <- function(expr, prefix) { +safequery <- function(expr, prefix = "") { if (is.null(expr)) { return("") } else { From b9a4b74caab53d70569b8cb54e79e520e6ba5ef4 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:32:58 -0500 Subject: [PATCH 26/62] wire up some utility tests --- tests/testthat/test_utils.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/testthat/test_utils.R diff --git a/tests/testthat/test_utils.R b/tests/testthat/test_utils.R new file mode 100644 index 00000000..71fc79d5 --- /dev/null +++ b/tests/testthat/test_utils.R @@ -0,0 +1,16 @@ +context("utils") + +test_that("safequery handles values correctly", { + pref <- "prefixed" + nullval = NULL + expect_identical(safe_query(nullval, pref), "") + + oneval <- "blah" + expect_identical(safe_query(oneval, pref), paste0(pref, oneval)) + + moreval <- c("blah", "blah2") + expect_identical(safe_query(moreval, pref), paste0(pref, paste(moreval, collapse = "|"))) + + morenull <- c(NULL, NULL) + expect_identical(safe_query(morenull, pref, "|"), "") +}) From 837bd002f549353aa4f62015cce8922e7e80be04 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:33:13 -0500 Subject: [PATCH 27/62] rename safe_query and add option for multiples --- R/utils.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index b34b8510..9c2781b7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,7 +1,7 @@ -safequery <- function(expr, prefix = "") { +safe_query <- function(expr, prefix = "", collapse = "|") { if (is.null(expr)) { return("") } else { - return(paste0(prefix, expr)) + return(paste0(prefix, glue::glue_collapse(expr, sep = collapse))) } } From b3d6c5103b9fe529b41e08ff2a78b4b052a448d8 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:34:06 -0500 Subject: [PATCH 28/62] minor namespace fixes rename safequery to safe_query --- R/connect.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/R/connect.R b/R/connect.R index 7cb5825e..84aa921c 100644 --- a/R/connect.R +++ b/R/connect.R @@ -249,14 +249,14 @@ Connect <- R6::R6Class( path <- glue::glue( "v1/instrumentation/content/visits?", glue::glue( - "{safequery(content_guid, 'content_guid=')}", - "{safequery(min_data_version, 'content_guid=')}", - "{safequery(from, 'from=')}", - "{safequery(to, 'to=')}", - "{safequery(limit, 'limit=')}", - "{safequery(previous, 'previous=')}", - "{safequery(nxt, 'next=')}", - "{safequery(asc_order, 'asc_order=')}", + "{safe_query(content_guid, 'content_guid=')}", + "{safe_query(min_data_version, 'content_guid=')}", + "{safe_query(from, 'from=')}", + "{safe_query(to, 'to=')}", + "{safe_query(limit, 'limit=')}", + "{safe_query(previous, 'previous=')}", + "{safe_query(nxt, 'next=')}", + "{safe_query(asc_order, 'asc_order=')}", .sep = "&" ) ) @@ -274,8 +274,8 @@ Connect <- R6::R6Class( get_audit_logs = function(limit = 20L, previous = NULL, nxt = NULL, asc_order = TRUE) { path <- glue::glue( "v1/audit_logs?limit={limit}", - "{safequery(previous, '&previous=')}", - "{safequery(nxt, '&next=')}", + "{safe_query(previous, '&previous=')}", + "{safe_query(nxt, '&next=')}", "&ascOrder={asc_order}" ) self$GET( From 75b4cbcbd7012b25da3adc0044c4ef61ee03860b Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:41:05 -0500 Subject: [PATCH 29/62] add inst_shiny_usage function --- R/connect.R | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/R/connect.R b/R/connect.R index 84aa921c..482d4f16 100644 --- a/R/connect.R +++ b/R/connect.R @@ -264,6 +264,35 @@ Connect <- R6::R6Class( self$GET(path) }, + inst_shiny_usage = function( + content_guid = NULL, + min_data_version = NULL, + from = NULL, + to = NULL, + limit = 20, + previous = NULL, + nxt = NULL, + asc_order = TRUE + ) { + + path <- glue::glue( + "v1/instrumentation/shiny/usage?", + glue::glue( + "{safe_query(content_guid, 'content_guid=')}", + "{safe_query(min_data_version, 'content_guid=')}", + "{safe_query(from, 'from=')}", + "{safe_query(to, 'to=')}", + "{safe_query(limit, 'limit=')}", + "{safe_query(previous, 'previous=')}", + "{safe_query(nxt, 'next=')}", + "{safe_query(asc_order, 'asc_order=')}", + .sep = "&" + ) + ) + + self$GET(path) + }, + # misc utilities -------------------------------------------- get_docs = function(docs = "api") { From 2c08c94f90187f3fce999dad5fa35574b443cf0e Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Sat, 19 Jan 2019 09:43:00 -0500 Subject: [PATCH 30/62] update news --- NEWS.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index db50ef49..1f4c4f8d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,19 @@ # connectApiUtils 0.1.0.9000 -* Rename `connect$activate_bundle` to `connect$deploy_bundle` +BREAKING: +* Rename a handful of functions: + - `connect$activate_bundle` to `connect$content_deploy` + - `connect$create_app` to `connect$content_create` + - `connect$upload_bundle` to `connect$content_upload` +* Switch endpoints from using `app_id` to `app_guid` + +OTHER: +* Add some endpoints: + - `get_content` + - `get_audit_logs` + - `get_server_settings` + - `get_server_settings_r` + - `inst_shiny_usage` + - `inst_content_visits` * Update `connect` R6 object to be compatible with Connect 1.7.0 APIs * Added a `NEWS.md` file to track changes to the package. From c924e00d6895a502682d471291b651378e3ef005 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Mon, 21 Jan 2019 15:14:53 -0500 Subject: [PATCH 31/62] add download_github helper --- R/github.R | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 R/github.R diff --git a/R/github.R b/R/github.R new file mode 100644 index 00000000..da7586e7 --- /dev/null +++ b/R/github.R @@ -0,0 +1,24 @@ +#' @export +download_github <- function(repo, ref = "master") { + current_wd <- getwd() + on.exit(setwd(current_wd), add = TRUE) + + temp_dir <- fs::dir_create(fs::path(fs::path_temp(), fs::file_temp("dir_")), recursive = TRUE) + tar_file <- fs::path(temp_dir, "repo.tar.gz") + setwd(temp_dir) + + req <- httr::GET( + glue::glue( + "https://api.github.com/repos/{repo}/tarball/{ref}" + ), + httr::write_disk(tar_file) + ) + + # un-tar and enter the repo + untar("repo.tar.gz") + setwd(fs::dir_ls(type = "directory")) + + final_loc <- getwd() + + return(final_loc) +} From a7c4634831e81c454561da5f519b45ac2fc2ddbd Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Mon, 21 Jan 2019 15:16:42 -0500 Subject: [PATCH 32/62] add dependency on fs package --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3a0cfce0..8e7b6126 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -11,7 +11,8 @@ Imports: R6, httr, rlang, - glue + glue, + fs RoxygenNote: 6.0.1 Suggests: rmarkdown, From daec36791b0804527e35cbb5e28b9f4f8092f23e Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Mon, 21 Jan 2019 15:57:04 -0500 Subject: [PATCH 33/62] add content_ensure function to ensure content exists --- R/promote.R | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/R/promote.R b/R/promote.R index b1e542df..425a4b6c 100644 --- a/R/promote.R +++ b/R/promote.R @@ -64,6 +64,31 @@ promote <- function(from, return(to_app_url) } +#' @export +content_ensure <- function(connect, name, title = name, ...) { + + content <- connect$get_apps(list(name = name)) + if (length(content) > 1) { + stop(glue::glue("Found {length(to_content)} content items ", + "matching {content_name} on {connect$host}", + ", content must have a unique name.")) + } else if (length(content) == 0) { + # create app + content <- connect$content_create( + name = name, + title = title, + ... + ) + message(glue::glue("Creating NEW content {content$guid} ", + "with name {name} on {connect$host}")) + } else { + content <- content[[1]] + message(glue::glue("Found EXISTING content {content$guid} with ", + "name {name} on {connect$host}")) + } + return(content) +} + #' @export dir_bundle <- function(path = ".") { before_wd <- getwd() From 5c8e41ee702810f5168232b4fca11f8e09261d91 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Mon, 21 Jan 2019 15:57:23 -0500 Subject: [PATCH 34/62] update roxygen --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8e7b6126..9862a340 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,7 +13,7 @@ Imports: rlang, glue, fs -RoxygenNote: 6.0.1 +RoxygenNote: 6.1.1 Suggests: rmarkdown, htmltools, From 749d1b257700172cd2e901f41f4fa2829b20ebf3 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Mon, 21 Jan 2019 15:57:36 -0500 Subject: [PATCH 35/62] export download_github and content_ensure functions --- NAMESPACE | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 47895d7f..5edcc829 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,8 +6,10 @@ export(audit_r_versions) export(audit_runas) export(audit_vanity_urls) export(cache_apps) +export(content_ensure) export(deploy_bundle) export(dir_bundle) +export(download_github) export(poll_task) export(promote) export(tag_page) From 1fe08fe612d69760c7b9eac9852cce5ab0616bf3 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Mon, 21 Jan 2019 15:58:02 -0500 Subject: [PATCH 36/62] add skeleton of yaml helper functions --- R/yaml.R | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 R/yaml.R diff --git a/R/yaml.R b/R/yaml.R new file mode 100644 index 00000000..3e07f8aa --- /dev/null +++ b/R/yaml.R @@ -0,0 +1,25 @@ +yaml_content <- function(filename = ".connect.yml") { + cfg <- config::get(value = "content", file = filename) +} + +yaml_content_deploy <- function( + name, + path = "./", + description = NULL, + tag = NULL, + url = NULL, + image = NULL +) { + bundle_path <- dir_bundle(path = path) + + # create_and_upload + + # should have a guid + + # tag helper + + # set vanity URL + + # set image path + +} From 5f4e972f8e37dd12fe602fac6dd7dd8cbc9a2da3 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Mon, 21 Jan 2019 16:19:35 -0500 Subject: [PATCH 37/62] add random_name function --- R/promote.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/promote.R b/R/promote.R index 425a4b6c..01b973ef 100644 --- a/R/promote.R +++ b/R/promote.R @@ -89,6 +89,10 @@ content_ensure <- function(connect, name, title = name, ...) { return(content) } +random_name <- function(length = 13) { + tolower(paste(sample(LETTERS, length, replace = TRUE), collapse = "")) +} + #' @export dir_bundle <- function(path = ".") { before_wd <- getwd() From 5814cc86f77da450522fd3a19b578025cbdbecfc Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Mon, 21 Jan 2019 21:51:24 -0500 Subject: [PATCH 38/62] make name random by default --- R/promote.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/promote.R b/R/promote.R index 01b973ef..af138f44 100644 --- a/R/promote.R +++ b/R/promote.R @@ -65,7 +65,7 @@ promote <- function(from, } #' @export -content_ensure <- function(connect, name, title = name, ...) { +content_ensure <- function(connect, name = random_name(), title = name, ...) { content <- connect$get_apps(list(name = name)) if (length(content) > 1) { From 07ea4f0e4112e60e1a0336069d84d99c3f833b61 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Mon, 21 Jan 2019 22:10:08 -0500 Subject: [PATCH 39/62] rename app_guid to guid --- R/connect.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/connect.R b/R/connect.R index 482d4f16..44eaeea2 100644 --- a/R/connect.R +++ b/R/connect.R @@ -154,23 +154,23 @@ Connect <- R6::R6Class( to_path }, - content_upload = function(bundle_path, app_guid) { + content_upload = function(bundle_path, guid) { # todo : add X-Content-Checksum - path <- sprintf('v1/experimental/content/%d/upload', app_guid) + path <- sprintf('v1/experimental/content/%d/upload', guid) res <- self$POST(path, httr::upload_file(bundle_path), 'raw') new_bundle_id <- res[["task_id"]] new_bundle_id }, - content_deploy = function(app_guid, bundle_id) { - path <- sprintf('v1/experimental/content/%s/deploy', app_guid) + content_deploy = function(guid, bundle_id) { + path <- sprintf('v1/experimental/content/%s/deploy', guid) res <- self$POST(path, list(bundle_id = as.character(bundle_id))) task_id <- res[["task_id"]] task_id }, - get_content = function(app_guid) { - path <- sprintf("v1/experimental/content/%s", app_guid) + get_content = function(guid) { + path <- sprintf("v1/experimental/content/%s", guid) res <- self$GET(path) return(res) }, From dc227c92e0a6fd38a935bca62a4d443153403b2c Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Mon, 21 Jan 2019 22:10:25 -0500 Subject: [PATCH 40/62] add some work to the yaml functions --- R/yaml.R | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/R/yaml.R b/R/yaml.R index 3e07f8aa..71de0320 100644 --- a/R/yaml.R +++ b/R/yaml.R @@ -1,25 +1,50 @@ yaml_content <- function(filename = ".connect.yml") { cfg <- config::get(value = "content", file = filename) + return(cfg) } yaml_content_deploy <- function( + connect, name, path = "./", description = NULL, tag = NULL, url = NULL, - image = NULL + image = NULL, + ... ) { bundle_path <- dir_bundle(path = path) - # create_and_upload + c_obj <- rlang::exec( + content_ensure, + connect = connect, + name = name, + description = description + ... + ) + + c_guid <- c_obj[["guid"]] + + c_upload <- connect$content_upload( + bundle_path = bundle_path, + guid = c_guid + ) + + # deploy - # should have a guid # tag helper + if (!is.null(tag)) { + + } # set vanity URL + if (!is.null(url)) { + + } # set image path - + if (!is.null(image)) { + + } } From 70afa4a633cb1572e9505b387c92e196f617ba9e Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 10:02:25 -0500 Subject: [PATCH 41/62] rewrite poll_task to copy the bash example --- R/promote.R | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/R/promote.R b/R/promote.R index af138f44..dcb89da3 100644 --- a/R/promote.R +++ b/R/promote.R @@ -116,18 +116,22 @@ deploy_bundle <- function(connect, bundle, app_id){ } #' @export -poll_task <- function(connect, task_id) { - start <- 0 - while (task_id > 0) { - Sys.sleep(2) - status <- connect$get_task(task_id, start) - if (length(status$status) > 0) { - lapply(status$status, print) - start <- status$last_status - } - if (status$finished) { - task_id = 0 - } +poll_task <- function(connect, task_id, wait = 1) { + finished <- FALSE + code <- -1 + first <- 0 + while (!finished) { + task_data <- connect$get_task(task_id, wait = wait, first = first) + finished <- task_data[["finished"]] + code <- task_data[["code"]] + first <- task_data[["last"]] + + lapply(task_data[["output"]], message) + } + + if (code != 0) { + msg <- task_data[["error"]] + stop(msg) } invisible() } From b2233b02c335b2589cbbff60b0449a3a7c344ad4 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 10:02:39 -0500 Subject: [PATCH 42/62] rename get_task variables --- R/connect.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/connect.R b/R/connect.R index 44eaeea2..60e53983 100644 --- a/R/connect.R +++ b/R/connect.R @@ -175,8 +175,8 @@ Connect <- R6::R6Class( return(res) }, - get_task = function(task_id, start = 0, wait = 5) { - path <- sprintf('v1/experimental/tasks/%s?first=%d&wait=%d', task_id, start, wait) + get_task = function(task_id, first = 0, wait = 5) { + path <- sprintf('v1/experimental/tasks/%s?first=%d&wait=%d', task_id, first, wait) self$GET(path) }, From a409dc9c39b2d0e5498b2ba9863933b62835ff78 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 10:02:44 -0500 Subject: [PATCH 43/62] switch to using glue --- R/connect.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/connect.R b/R/connect.R index 60e53983..ec6b94c0 100644 --- a/R/connect.R +++ b/R/connect.R @@ -156,7 +156,7 @@ Connect <- R6::R6Class( content_upload = function(bundle_path, guid) { # todo : add X-Content-Checksum - path <- sprintf('v1/experimental/content/%d/upload', guid) + path <- glue::glue('v1/experimental/content/{guid}/upload') res <- self$POST(path, httr::upload_file(bundle_path), 'raw') new_bundle_id <- res[["task_id"]] new_bundle_id From b4edad958de19a861173c616afc9b832b8931385 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 10:03:32 -0500 Subject: [PATCH 44/62] add random_name default fix typo make yaml_content_deploy functional --- R/yaml.R | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/R/yaml.R b/R/yaml.R index 71de0320..0c5d1091 100644 --- a/R/yaml.R +++ b/R/yaml.R @@ -5,7 +5,7 @@ yaml_content <- function(filename = ".connect.yml") { yaml_content_deploy <- function( connect, - name, + name = random_name(), path = "./", description = NULL, tag = NULL, @@ -19,7 +19,7 @@ yaml_content_deploy <- function( content_ensure, connect = connect, name = name, - description = description + description = description, ... ) @@ -30,8 +30,16 @@ yaml_content_deploy <- function( guid = c_guid ) - # deploy + c_task <- connect$content_deploy( + guid = c_guid, + bundle_id = c_upload + ) + # wait for task to complete + poll_task( + connect, + c_task + ) # tag helper if (!is.null(tag)) { From be327e8398d78415707b61da769df2979b6f8a6d Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 10:03:40 -0500 Subject: [PATCH 45/62] update news --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 1f4c4f8d..cc85ed50 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,7 +5,8 @@ BREAKING: - `connect$activate_bundle` to `connect$content_deploy` - `connect$create_app` to `connect$content_create` - `connect$upload_bundle` to `connect$content_upload` -* Switch endpoints from using `app_id` to `app_guid` +* Switch endpoints from using `app_id` to `guid` +* `get_task$start` renamed to `get_task$first` OTHER: * Add some endpoints: From 4c56767856c585f69a0292b9cf8da3370aa7e303 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 10:29:42 -0500 Subject: [PATCH 46/62] add deploy_github function --- R/github.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/R/github.R b/R/github.R index da7586e7..a9247054 100644 --- a/R/github.R +++ b/R/github.R @@ -22,3 +22,13 @@ download_github <- function(repo, ref = "master") { return(final_loc) } + +#' @export +deploy_github <- function(connect, repo, ref = "master", filename = ".connect.yml") { + download_dir <- download_github(repo = repo, ref = ref) + current_wd <- getwd() + on.exit(setwd(current_wd), add = TRUE) + + setwd(download_dir) + yaml_content(connect = connect, filename = filename) +} From 2eb5a840fad1df0b643689c257b1f73f6bd2bb53 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 10:30:08 -0500 Subject: [PATCH 47/62] finish up yaml_content --- R/yaml.R | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/R/yaml.R b/R/yaml.R index 0c5d1091..31316d44 100644 --- a/R/yaml.R +++ b/R/yaml.R @@ -1,5 +1,14 @@ -yaml_content <- function(filename = ".connect.yml") { +yaml_content <- function(connect, filename = ".connect.yml") { cfg <- config::get(value = "content", file = filename) + + res <- lapply( + cfg, + function(x, connect) { + rlang::exec(yaml_content_deploy, connect = connect, !!!x) + }, + connect = connect + ) + return(cfg) } From 67382244eba1fea8844f880d479aa7ba9a7ee287 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 10:31:03 -0500 Subject: [PATCH 48/62] add some notes that these apis need to be public --- R/yaml.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/yaml.R b/R/yaml.R index 31316d44..6dee4d87 100644 --- a/R/yaml.R +++ b/R/yaml.R @@ -52,16 +52,16 @@ yaml_content_deploy <- function( # tag helper if (!is.null(tag)) { - + # need public APIs } # set vanity URL if (!is.null(url)) { - + # need public APIs } # set image path if (!is.null(image)) { - + # need public APIs } } From 1f6fc1a7bdddd9c99fca553090410ab1b6d0892f Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 11:31:11 -0500 Subject: [PATCH 49/62] allow filename parameter to dir_bundle --- R/promote.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/promote.R b/R/promote.R index dcb89da3..0380299f 100644 --- a/R/promote.R +++ b/R/promote.R @@ -94,14 +94,14 @@ random_name <- function(length = 13) { } #' @export -dir_bundle <- function(path = ".") { +dir_bundle <- function(path = ".", filename = "bundle.tar.gz") { before_wd <- getwd() setwd(path) on.exit(expr = setwd(before_wd), add = TRUE) - utils::tar(tarfile = "bundle.tar.gz", files = ".", compression = "gzip", tar = "internal") + utils::tar(tarfile = filename, files = ".", compression = "gzip", tar = "internal") - return(fs::path_abs("bundle.tar.gz")) + return(fs::path_abs(filename)) } #' @export From 5c22a394e6a40fa385fa340adc9ca1e8e13a115e Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 13:11:29 -0500 Subject: [PATCH 50/62] add first pass at a check_connect_version function --- R/utils.R | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/R/utils.R b/R/utils.R index 9c2781b7..3a55d34f 100644 --- a/R/utils.R +++ b/R/utils.R @@ -5,3 +5,28 @@ safe_query <- function(expr, prefix = "", collapse = "|") { return(paste0(prefix, glue::glue_collapse(expr, sep = collapse))) } } + +check_connect_version <- function(connect) { + settings <- connect$get_server_settings() + using_version <- settings[["version"]] + + comp <- compareVersion(tested_version, using_version) + + msg <- switch( + as.character(comp), + "0" = NULL, + "1" = warning(glue::glue( + "You are using an older version of RStudio Connect", + "({using_version}) than was tested ({tested_version}).", + "Some APIs may not function as expected." + )), + "-1" = warning(glue::glue( + "You are using a newer version of RStudio Connect", + "({using_version}) than was tested ({tested_version}).", + "Some APIs may not function as expected." + )) + ) + invisible() +} + +tested_version <- "1.7.0-11" From 7b26ee5658ea3a418d4d9592c770e178fdbeb8f2 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 13:30:31 -0500 Subject: [PATCH 51/62] update news --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index cc85ed50..3c5de5ed 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,5 +16,7 @@ OTHER: - `get_server_settings_r` - `inst_shiny_usage` - `inst_content_visits` +* Add some helper functions: + - `deploy_github`, `download_github` * Update `connect` R6 object to be compatible with Connect 1.7.0 APIs * Added a `NEWS.md` file to track changes to the package. From 1e6db50cf04222d46a8bf5ffe08dd514decd629a Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 13:38:42 -0500 Subject: [PATCH 52/62] update namespace --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index 5edcc829..cb926ddd 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ export(audit_vanity_urls) export(cache_apps) export(content_ensure) export(deploy_bundle) +export(deploy_github) export(dir_bundle) export(download_github) export(poll_task) From 860da0999aae462a00aae2bf09216ff512555577 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 13:47:16 -0500 Subject: [PATCH 53/62] add a (possibly outlandish) connect helper --- R/connect.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/R/connect.R b/R/connect.R index ec6b94c0..d2042e4c 100644 --- a/R/connect.R +++ b/R/connect.R @@ -338,3 +338,13 @@ check_debug <- function(req, res) { } } +connect_input <- function(connect) { + if (R6::is.R6(connect)) { + # is an R6 object... we presume the right type + return(connect) + } else if (is.list(connect) && c("host","api_key") %in% names(connect)) { + return(Connect$new(host = connect[["host"]], api_key = connect[["api_key"]])) + } else { + stop("Input 'connect' is not an R6 object or a named list") + } +} From ce53b8f2b39cc87523241d5d252b9db5c1d0647b Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 13:58:41 -0500 Subject: [PATCH 54/62] add connect_input helper for experimentation --- R/yaml.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/yaml.R b/R/yaml.R index 6dee4d87..2ca6545c 100644 --- a/R/yaml.R +++ b/R/yaml.R @@ -22,6 +22,8 @@ yaml_content_deploy <- function( image = NULL, ... ) { + orig_connect <- connect + connect <- connect_input(connect) bundle_path <- dir_bundle(path = path) c_obj <- rlang::exec( From 8686e980694a32c0bf110cb70c14d9fa8255545e Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 14:01:12 -0500 Subject: [PATCH 55/62] add dependency on the config package --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9862a340..6509746e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,8 @@ Imports: httr, rlang, glue, - fs + fs, + config RoxygenNote: 6.1.1 Suggests: rmarkdown, From 0b3f2312eef54f54410f9271a2bdf36dfb76c744 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 16:10:43 -0500 Subject: [PATCH 56/62] rename package add rstudio tweak wording --- DESCRIPTION | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6509746e..3916b81f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,13 @@ -Package: connectApiUtils +Package: connectapi Type: Package Title: Utilities for Interacting with RStudio Connect's API Version: 0.1.0.9000 -Author: Sean Lopp -Maintainer: Sean Lopp -Description: Helpful class for interacting with Connect's API and some example utility functions. +Authors@R: c( + person("Sean", "Lopp", , "sean@rstudio.com", c("aut", "cre")), + person("Cole", "Arendt", , "cole@rstudio.com", c("aut")), + person("RStudio", role = c("cph", "fnd")) + ) +Description: Helpful R6 class for interacting with RStudio Connect's API and some example utility functions. License: GPL-2 Encoding: UTF-8 Imports: From ff25f563ca6f875f0c609c6be6d5def9067dca4a Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 16:11:05 -0500 Subject: [PATCH 57/62] rename rproj file --- connectApiUtils.Rproj => connectapi.Rproj | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename connectApiUtils.Rproj => connectapi.Rproj (100%) diff --git a/connectApiUtils.Rproj b/connectapi.Rproj similarity index 100% rename from connectApiUtils.Rproj rename to connectapi.Rproj From e8c935506a874eec09892eb7ef92b43e92cfada2 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 16:11:56 -0500 Subject: [PATCH 58/62] rename the package in news --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 3c5de5ed..9aeaf046 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# connectApiUtils 0.1.0.9000 +# connectapi 0.1.0.9000 BREAKING: * Rename a handful of functions: @@ -7,6 +7,7 @@ BREAKING: - `connect$upload_bundle` to `connect$content_upload` * Switch endpoints from using `app_id` to `guid` * `get_task$start` renamed to `get_task$first` +* rename the package to `connectapi` OTHER: * Add some endpoints: From 0a345c6aa6b4c978f431efe29330e61a2419d1e1 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 16:12:17 -0500 Subject: [PATCH 59/62] fix package reference --- R/tag_page.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tag_page.R b/R/tag_page.R index b71d0ff9..688bef1e 100644 --- a/R/tag_page.R +++ b/R/tag_page.R @@ -39,7 +39,7 @@ tag_page <- function(server, a }) - template <- system.file('tag_page_template.Rmd', package = "connectApiUtils") + template <- system.file('tag_page_template.Rmd', package = "connectapi") out_file <- sprintf('%s.html', tag) out_dir <- getwd() rmarkdown::render(template, From 9f93a9f0d68e80239c66ec2eaf2b6e5d556e1c36 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 16:12:49 -0500 Subject: [PATCH 60/62] fix package name references --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ba8f9d71..e7fe4523 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ This package is an **experimental WIP**. The package is designed to provide an R To get started: ```r -devtools::install_github('slopp/connectApiUtils') +devtools::install_github('rstudio/connectapi') ``` ## Client @@ -15,7 +15,7 @@ devtools::install_github('slopp/connectApiUtils') To create a client: ```r -library(connectApiUtils) +library(connectapi) client <- Connect$new( host = 'https://connect.example.com', api_key = '' From a3fbb993996d0721469a3a628104ce1bd2381dd7 Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 16:13:13 -0500 Subject: [PATCH 61/62] fix package name references --- tests/testthat.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat.R b/tests/testthat.R index b72b1cff..59ac4bbb 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,4 +1,4 @@ library(testthat) -library(connectApiUtils) +library(connectapi) -test_check("connectApiUtils") +test_check("connectapi") From d7e76bf2aa09172635f35bf88f6759230b586c3e Mon Sep 17 00:00:00 2001 From: Cole Arendt Date: Tue, 22 Jan 2019 16:14:09 -0500 Subject: [PATCH 62/62] tweak wording some more --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3916b81f..108bad91 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,13 @@ Package: connectapi Type: Package -Title: Utilities for Interacting with RStudio Connect's API +Title: Utilities for Interacting with the RStudio Connect Server API Version: 0.1.0.9000 Authors@R: c( person("Sean", "Lopp", , "sean@rstudio.com", c("aut", "cre")), person("Cole", "Arendt", , "cole@rstudio.com", c("aut")), person("RStudio", role = c("cph", "fnd")) ) -Description: Helpful R6 class for interacting with RStudio Connect's API and some example utility functions. +Description: Helpful R6 class for interacting with the RStudio Connect Server API and some example utility functions. License: GPL-2 Encoding: UTF-8 Imports: