R/oc_api.R

Defines functions oc_api print.oc_api

Documented in oc_api print.oc_api

#' Query Opencast base api
#'
#' Returns key characteristics of the API such as the server name and the default version.
#'
#' This function expects the hostname, username and password to be set as environment variables.
#'
#' @return A list containing the default api version and server url.
#' @importFrom httr modify_url
#' @export
#' @examples
#' Sys.setenv(OPENCAST_HOST = "https://legacy.opencast.org")
#' Sys.setenv(OPENCAST_USERNAME = "admin")
#' Sys.setenv(OPENCAST_PASSWORD = "opencast")
#'
#' oc_api()
oc_api <- function() {
  # Set the url path
  path <- "/api/"

  # Construct the url for the api call
  url <- modify_url(oc_hostname(), path = path)

  # Query the api and return the response
  oc_package_query(url)
}

#' Print result of oc_api()
#'
#' Print a structured return of the oc_api() function.
#'
#' @param x The return of the function this print function relates to.
#' @param ... Possible further options to the print function.
#' @return A structured print of the return by the oc_api() function.
#' @seealso \code{\link{oc_api}}
#' @importFrom utils str
#' @export
#' @examples
#' Sys.setenv(OPENCAST_HOST = "https://legacy.opencast.org")
#' Sys.setenv(OPENCAST_USERNAME = "admin")
#' Sys.setenv(OPENCAST_PASSWORD = "opencast")
#'
#' resp <- oc_api()
#'
#' resp
print.oc_api <- function(x, ...) {
  cat("<Opencast ", x$path, ">\n", sep = "")
  str(x$content)
  invisible(x)
}

Try the opencastR package in your browser

Any scripts or data that you put into this service are public.

opencastR documentation built on March 19, 2020, 5:12 p.m.