1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
shinyAppsClient <- function(service, authInfo) {
list(
status = function() {
GET(service, authInfo, "/internal/status")
},
service = function() {
"shinyapps.io"
},
currentUser = function() {
GET(service, authInfo, "/users/current/")
},
accountsForUser = function(userId) {
path <- "/accounts/"
query <- ""
listRequest(service, authInfo, path, query, "accounts")
},
getAccountUsage = function(accountId, usageType = "hours", applicationId = NULL,
from = NULL, until = NULL, interval = NULL) {
path <- paste("/accounts/", accountId, "/usage/", usageType, "/", sep = "")
query <- list()
if (!is.null(applicationId))
query$application <- applicationId
if (!is.null(from))
query$from <- from
if (!is.null(until))
query$until <- until
if (!is.null(interval))
query$interval <- interval
GET(service, authInfo, path, queryString(query))
},
getBundle = function(bundleId) {
path <- paste("/bundles/", bundleId, sep = "")
GET(service, authInfo, path)
},
updateBundleStatus = function(bundleId, status) {
path <- paste("/bundles/", bundleId, "/status", sep = "")
json <- list()
json$status <- status
POST_JSON(service, authInfo, path, json)
},
createBundle = function(application, content_type, content_length, checksum) {
json <- list()
json$application <- application
json$content_type <- content_type
json$content_length <- content_length
json$checksum <- checksum
POST_JSON(service, authInfo, "/bundles", json)
},
listApplications = function(accountId, filters = list()) {
path <- "/applications/"
query <- paste(filterQuery(
c("account_id", "type", names(filters)),
c(accountId, "shiny", unname(filters))
), collapse = "&")
listRequest(service, authInfo, path, query, "applications")
},
getApplication = function(applicationId, deploymentRecordVersion) {
path <- paste("/applications/", applicationId, sep = "")
application <- GET(service, authInfo, path)
application$application_id <- application$id
application
},
getApplicationMetrics = function(applicationId, series, metrics, from = NULL, until = NULL, interval = NULL) {
path <- paste("/applications/", applicationId, "/metrics/", series, "/", sep = "")
query <- list()
m <- paste(lapply(metrics, function(x) { paste("metric", urlEncode(x), sep = "=") }), collapse = "&")
if (!is.null(from))
query$from <- from
if (!is.null(until))
query$until <- until
if (!is.null(interval))
query$interval <- interval
GET(service, authInfo, path, paste(m, queryString(query), sep = "&"))
},
getLogs = function(applicationId, entries = 50) {
path <- paste0("/applications/", applicationId, "/logs")
query <- paste0("count=", entries, "&tail=0")
GET(service, authInfo, path, query)
},
createApplication = function(name, title, template, accountId, appMode, contentCategory = NULL, spaceId = NULL) {
json <- list()
json$name <- name
# the title field is only used on connect
json$template <- template
json$account <- as.numeric(accountId)
application <- POST_JSON(service, authInfo, "/applications/", json)
list(
id = application$id,
application_id = application$id,
url = application$url
)
},
listApplicationProperties = function(applicationId) {
path <- paste("/applications/", applicationId, "/properties/", sep = "")
GET(service, authInfo, path)
},
setApplicationProperty = function(applicationId, propertyName,
propertyValue, force = FALSE) {
path <- paste("/applications/", applicationId, "/properties/",
propertyName, sep = "")
v <- list()
v$value <- propertyValue
query <- paste("force=", if (force) "1" else "0", sep = "")
PUT_JSON(service, authInfo, path, v, query)
},
unsetApplicationProperty = function(applicationId, propertyName,
force = FALSE) {
path <- paste("/applications/", applicationId, "/properties/",
propertyName, sep = "")
query <- paste("force=", if (force) "1" else "0", sep = "")
DELETE(service, authInfo, path, query)
},
uploadApplication = function(applicationId, bundlePath) {
path <- paste("/applications/", applicationId, "/upload", sep = "")
POST(
service,
authInfo,
path,
contentType = "application/x-gzip",
file = bundlePath
)
},
deployApplication = function(application, bundleId = NULL, spaceId = NULL) {
path <- paste("/applications/", application$id, "/deploy", sep = "")
json <- list()
if (length(bundleId) > 0 && nzchar(bundleId))
json$bundle <- as.numeric(bundleId)
else
json$rebuild <- FALSE
POST_JSON(service, authInfo, path, json)
},
terminateApplication = function(applicationId) {
path <- paste("/applications/", applicationId, "/terminate", sep = "")
POST(service, authInfo, path)
},
purgeApplication = function(applicationId) {
path <- paste("/applications/", applicationId, "/purge", sep = "")
POST(service, authInfo, path)
},
inviteApplicationUser = function(applicationId, email,
invite_email = NULL, invite_email_message = NULL) {
path <- paste("/applications/", applicationId, "/authorization/users",
sep = "")
json <- list()
json$email <- email
if (!is.null(invite_email))
json$invite_email <- invite_email
if (!is.null(invite_email_message))
json$invite_email_message <- invite_email_message
POST_JSON(service, authInfo, path, json)
},
addApplicationUser = function(applicationId, userId) {
path <- paste("/applications/", applicationId, "/authorization/users/",
userId, sep = "")
PUT(service, authInfo, path, NULL)
},
removeApplicationUser = function(applicationId, userId) {
path <- paste("/applications/", applicationId, "/authorization/users/",
userId, sep = "")
DELETE(service, authInfo, path, NULL)
},
listApplicationAuthorization = function(applicationId) {
path <- paste("/applications/", applicationId, "/authorization",
sep = "")
listRequest(service, authInfo, path, NULL, "authorization")
},
listApplicationUsers = function(applicationId) {
path <- paste("/applications/", applicationId, "/authorization/users",
sep = "")
listRequest(service, authInfo, path, NULL, "users")
},
listApplicationGroups = function(applicationId) {
path <- paste("/applications/", applicationId, "/authorization/groups",
sep = "")
listRequest(service, authInfo, path, NULL, "groups")
},
listApplicationInvitations = function(applicationId) {
path <- "/invitations/"
query <- paste(filterQuery("app_id", applicationId), collapse = "&")
listRequest(service, authInfo, path, query, "invitations")
},
resendApplicationInvitation = function(invitationId, regenerate = FALSE) {
path <- paste("/invitations/", invitationId, "/send", sep = "")
json <- list()
json$regenerate <- regenerate
POST_JSON(service, authInfo, path, json)
},
listTasks = function(accountId, filters = NULL) {
if (is.null(filters)) {
filters <- vector()
}
path <- "/tasks/"
filters <- c(filterQuery("account_id", accountId), filters)
query <- paste(filters, collapse = "&")
listRequest(service, authInfo, path, query, "tasks", max = 100)
},
getTaskInfo = function(taskId) {
path <- paste("/tasks/", taskId, sep = "")
GET(service, authInfo, path)
},
getTaskLogs = function(taskId) {
path <- paste("/tasks/", taskId, "/logs/", sep = "")
GET(service, authInfo, path)
},
waitForTask = function(taskId, quiet = FALSE) {
if (!quiet) {
cat("Waiting for task: ", taskId, "\n", sep = "")
}
path <- paste("/tasks/", taskId, sep = "")
lastStatus <- NULL
while (TRUE) {
# check status
status <- GET(service, authInfo, path)
# display status to the user if it changed
if (!identical(lastStatus, status$description)) {
if (!quiet)
cat(" ", status$status, ": ", status$description, "\n", sep = "")
lastStatus <- status$description
}
# are we finished? (note: this codepath is the only way to exit this function)
if (status$finished) {
if (identical(status$status, "success")) {
return(NULL)
} else {
# always show task log on error
cli::cat_rule("Begin Task Log", line = "#")
taskLog(taskId, authInfo$name, authInfo$server, output = "stderr")
cli::cat_rule("End Task Log", line = "#")
stop(status$error, call. = FALSE)
}
}
# wait for 1 second before polling again
Sys.sleep(1)
}
}
)
}
|