Skip to content
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

add functionality to publish form to specific project #13

Merged
merged 3 commits into from
Feb 27, 2022
Merged
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
27 changes: 20 additions & 7 deletions R/ona_form.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ ona_list_forms <- function(base_url = "https://api.ona.io",
#' @param xls_file Path to the XLSForm file.
#' @param xls_url URL to the XLSForm file.
#' @param dropbox_xls_url Dropbox URL to the XLSForm file.
#' @param project_id Project identifier of project to publish XLSForm to.
#' If NULL (default), XLSForm is published to the an account's default
#' project.
#'
#' @return A published form on ONA.
#'
Expand All @@ -71,7 +74,8 @@ ona_publish_form <- function(base_url = "https://api.ona.io",
auth_mode = c("token", "password"),
xls_file = NULL,
xls_url = NULL,
dropbox_xls_url = NULL) {
dropbox_xls_url = NULL,
project_id = NULL) {
##
auth_mode <- match.arg(auth_mode)

Expand All @@ -91,12 +95,21 @@ ona_publish_form <- function(base_url = "https://api.ona.io",
}

## Apply POST
httr::POST(
url = base_url,
config = config,
path = "api/v1/forms",
body = .body
)
if (is.null(project_id)) {
httr::POST(
url = base_url,
config = config,
path = "api/v1/forms",
body = .body
)
} else {
httr::POST(
url = base_url,
config = config,
path = paste("api/v1/projects", project_id, "forms", sep = "/"),
body = .body
)
}
}


Expand Down
34 changes: 25 additions & 9 deletions R/ona_projects.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ ona_project_info <- function(base_url = "https://api.ona.io",
#' @param auth_mode Password or token? Default is token.
#' @param project_id Project identifier.
#' @param username A character value or vector of username/s of user/s to share
#' a form with
#' a form with.
#' @param role A character value for the role the user/s will have on the
#' project. This can be *readonly*, *dataentry*, *editor*, or *manager*.
#' @param email Email message to send to user/s to whom project has been
#' shared with. If NULL (default), user/s will not be notified.
#'
#' @return Invisible. Project shared with specified users with specified
#' roles. A tibble of project information.
Expand All @@ -127,7 +129,8 @@ ona_share_project <- function(base_url = "https://api.ona.io",
project_id = NULL,
username = NULL,
role = c("readonly", "dataentry",
"editor", "manager")) {
"editor", "manager"),
email = NULL) {
## Get authentication mode
auth_mode <- match.arg(auth_mode)

Expand All @@ -138,13 +141,23 @@ ona_share_project <- function(base_url = "https://api.ona.io",
role <- match.arg(role)

## Apply PUT
httr::PUT(
url = base_url,
path = paste("api/v1/projects", project_id, "share", sep = "/"),
config = config,
body = list(username = username, role = role),
encoding = "json"
)
if (is.null(email)) {
httr::PUT(
url = base_url,
path = paste("api/v1/projects", project_id, "share", sep = "/"),
config = config,
body = list(username = username, role = role),
encoding = "json"
)
} else {
httr::PUT(
url = base_url,
path = paste("api/v1/projects", project_id, "share", sep = "/"),
config = config,
body = list(username = username, role = role, email_msg = email),
encoding = "json"
)
}

## Get project info
project_info <- ona_project_info(project_id = project_id)
Expand All @@ -162,3 +175,6 @@ ona_share_project <- function(base_url = "https://api.ona.io",
## Return output
x
}



7 changes: 6 additions & 1 deletion man/ona_publish_form.Rd

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

8 changes: 6 additions & 2 deletions man/ona_share_project.Rd

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