R/sb_ping.R

Defines functions sb_ping

Documented in sb_ping

#' Ping ScienceBase to see if it's available
#' 
#' @export
#' @param ... Additional parameters are passed on to \code{\link[httr]{GET}}
#' @return Boolean (TRUE) indicating if a connection to ScienceBase can be established 
#' and if it is responding as expected. FALSE otherwise. 
#' @examples \donttest{
#' #TRUE if all is well and SB can be contacted
#' sb_ping()
#' }
sb_ping <- function(...) {

	tryCatch({
		x <- GET(paste0(pkg.env$url_item, 'ping'), 
						 timeout = httr::timeout(default_timeout()),
						 ...)
		res = jsonlite::fromJSON(content(x, "text"))
		if(is(res, 'list') & !is.null(res$result) & res$result == 'OK'){
			return(TRUE)
		}
	}, error=function(e){
		return(FALSE)
	})
	
	return(FALSE)
}

Try the sbtools package in your browser

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

sbtools documentation built on May 1, 2023, 1:07 a.m.