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

create org functions and update site #15

Merged
merged 1 commit into from
Feb 28, 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
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export(ona_data_list)
export(ona_form_delete)
export(ona_form_list)
export(ona_form_publish)
export(ona_org_delete)
export(ona_org_list)
export(ona_org_register)
export(ona_project_delete)
export(ona_project_info)
export(ona_project_list)
Expand Down
145 changes: 145 additions & 0 deletions R/ona_org.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
################################################################################
#
#'
#' Register an organisation
#'
#' @param base_url ONA URL. Default is \url{https://api.ona.io}.
#' @param auth_mode Password or token? Default is token.
#' @param org Organisation short name or username.
#' @param name Organisation full name. If NULL (default), short name is used.
#'
#' @return Invisible. Organisation registered and created in ONA account
#'
#' @examples
#' ona_org_register(org = "okapi_organisation")
#'
#' @export
#'
#
################################################################################

ona_org_register <- function(base_url = "https://api.ona.io",
auth_mode = c("token", "password"),
org, name = NULL) {
## Get authentication mode
auth_mode <- match.arg(auth_mode)

## Configure authentication/headers
config <- ona_configure(auth_mode = auth_mode)

## Create name of project
if (is.null(name)) {
name <- org
}

## Create body to POST
.body <- list(
org = org,
name = name
)

## Apply POST
response <- httr::POST(
url = base_url,
path = "api/v1/orgs",
body = .body,
config = config
)

## Read JSON response
x <- jsonlite::fromJSON(
txt = httr::content(x = response, as = "text", encoding = "UTF-8")
)

## Return
x
}



################################################################################
#
#'
#' List organisations
#'
#' @param base_url ONA URL. Default is \url{https://api.ona.io}.
#' @param auth_mode Password or token? Default is token.
#'
#' @return A tibble of organisations.
#'
#' @examples
#' ona_org_list()
#'
#' @export
#'
#'
#
################################################################################

ona_org_list <- function(base_url = "https://api.ona.io",
auth_mode = c("token", "password")) {
## Get authentication mode
auth_mode <- match.arg(auth_mode)

## Configure authentication/headers
config <- ona_configure(auth_mode = auth_mode)

## Apply GET
response <- httr::GET(
url = base_url,
path = "api/v1/orgs",
config = config
)

## Read JSON
x <- jsonlite::fromJSON(
txt = httr::content(x = response, as = "text", encoding = "UTF-8")
)

## Convert output to tibble
x <- tibble::tibble(x)

## Return output
x
}



################################################################################
#
#'
#' Delete registered organisation
#'
#' @param base_url ONA URL. Default is \url{https://api.ona.io}.
#' @param auth_mode Password or token? Default is token.
#' @param org Organisation short name or username.
#'
#' @return Delete specified organisation from specific ONA account.
#'
#' @examples
#' org_list <- ona_org_list()
#' org_name <- org_list[["org"]]
#' ona_org_delete(org = org_name)
#'
#' @export
#'
#
################################################################################

ona_org_delete <- function(base_url = "https://api.ona.io",
auth_mode = c("token", "password"),
org) {
##
auth_mode <- match.arg(auth_mode)

## Configure authentication/headers
config <- ona_configure(auth_mode = auth_mode)

## Apply DELETE
httr::DELETE(
url = base_url,
config = config,
path = paste("api/v1/orgs", org, sep = "/"),
body = NULL
)
}
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pandoc: 2.14.0.3
pkgdown: 2.0.2
pkgdown_sha: ~
articles: {}
last_built: 2022-02-28T03:21Z
last_built: 2022-02-28T05:17Z
urls:
reference: https://rapidsurveys.io/okapi/reference
article: https://rapidsurveys.io/okapi/articles
Expand Down
16 changes: 16 additions & 0 deletions docs/reference/index.html

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

2 changes: 1 addition & 1 deletion docs/reference/ona_form_delete.html

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

36 changes: 20 additions & 16 deletions docs/reference/ona_form_publish.html

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

Loading