Skip to content

Commit

Permalink
Merge pull request #1 from colearendt/test-manifest
Browse files Browse the repository at this point in the history
Add user endpoints and manifest fixes
  • Loading branch information
Sean Lopp authored Oct 15, 2018
2 parents 0c10036 + dea0992 commit a52560b
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 9 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ Maintainer: Sean Lopp <[email protected]>
Description: Helpful class for interacting with Connect's API and some example utility functions.
License: GPL-2
Encoding: UTF-8
Imports: R6,
httr
Imports:
R6,
httr,
rlang
RoxygenNote: 6.0.1
Suggests: rmarkdown,
htmltools,
Expand Down
73 changes: 72 additions & 1 deletion R/connect.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ Connect <- R6::R6Class(
check_debug(req, res)
httr::content(res, as = parser)
},

PUT = function(path, body, encode = 'json') {
req <- paste0(self$host, '/__api__/', path)
res <- httr::PUT(
req,
httr::add_headers(Authorization = paste0('Key ', self$api_key)),
body = body,
encode = encode
)
self$raise_error(res)
check_debug(req, res)
httr::content(res, as = 'parsed')
},

POST = function(path, body, encode = 'json') {
req <- paste0(self$host, '/__api__/', path)
Expand Down Expand Up @@ -145,11 +158,69 @@ Connect <- R6::R6Class(
path = sprintf('tasks/%s?first_status=%d', task_id, start)
self$GET(path)
},

get_users = function(page_number = 1){
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)
self$GET(path)
},

create_users = function(
email, first_name, last_name,
password, user_must_set_password,
user_role, username
) {
path = sprintf('v1/users')
self$POST(path = path,
body = list(
email = email,
first_name = first_name,
last_name = last_name,
password = password,
user_must_set_password = user_must_set_password,
user_role = user_role,
username = username
))
},

lock_user = function(user_guid) {
path = sprintf('v1/users/%s/lock', user_guid)
message(path)
self$POST(path = path,
body = list(locked = TRUE)
)
},

unlock_user = function(user_guid) {
path = sprintf('v1/users/%s/lock', user_guid)
self$POST(
path = path,
body = list(locked = FALSE)
)
},

update_user = function(user_guid, email, ...) {
path = sprintf('v1/users/%s', user_guid)
self$PUT(
path = path,
body = c(list(email = email), rlang::dots_list(...))
)
},

create_app = function(name) {
path = sprintf('applications')
self$POST(path, list(name = name))
self$POST(path, list(name = tolower(gsub("\\s","",name)), title = name ))
},

get_docs = function(docs = "api") {
stopifnot(docs %in% c("admin", "user", "api"))
utils::browseURL(paste0(self$host, '/__docs__/', docs))
}

)
)

Expand Down
22 changes: 16 additions & 6 deletions R/promote.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,27 @@ promote <- function(from,
warning(sprintf('Updating EXISTING app %d with name %s on %s', to_app$id, app_name, to))
}

#upload bundle
new_bundle_id <- to_client$upload_bundle(bundle, to_app$id)
to_app_url <- deploy_bundle(
connect = to_client,
bundle = bundle,
app = to_app
)

return(to_app_url)
}

deploy_bundle <- function(connect, bundle, app){
#upload bundle
new_bundle_id <- connect$upload_bundle(bundle, app$id)

#activate bundle
task_id <- to_client$activate_bundle(to_app$id, new_bundle_id)

task_id <- connect$activate_bundle(app$id, new_bundle_id)
#poll task
start <- 0
while (task_id > 0) {
Sys.sleep(2)
status <- to_client$get_task(task_id, start)
status <- connect$get_task(task_id, start)
if (length(status$status) > 0) {
lapply(status$status, print)
start <- status$last_status
Expand All @@ -70,5 +80,5 @@ promote <- function(from,
task_id = 0
}
}
return(to_app$url)
return(app$url)
}
17 changes: 17 additions & 0 deletions connectApiUtils.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source

0 comments on commit a52560b

Please sign in to comment.