R/list_groups.R

Defines functions list_groups

Documented in list_groups

#' List Groups
#'
#' Retrieve a listing of all groups in the specified GSuite domain.
#'
#' @param domain Required. A GSuite domain: 'somedomain.org'
#'
#' @return JSON object with information about all groups in the specified GSuite domain.
#' @export
#' @importFrom glue glue
#' @importFrom httr add_headers content GET
#' @importFrom rlang format_error_bullets inform
list_groups <- function(domain) {
  if (missing(domain) ) {
    rlang::inform(rlang::format_error_bullets(c("x" = 'Please specify a GSuite domain.')))
    } else {
      access_token <- get_access_token()
      if(is.null(access_token)){
        rlang::inform(rlang::format_error_bullets(c("x" = 'Error: Unauthenticated')))
        } else {
          auth_header <- httr::add_headers('Authorization' = glue::glue('Bearer {access_token}'))
          httr::content(httr::GET(glue::glue('https://www.googleapis.com/admin/directory/v1/groups/?domain={domain}'),
                                  auth_header)
                        )
          }
      }
}
thewileylab/googleGroupR documentation built on Oct. 7, 2022, 4:35 a.m.