Skip to content

Commit

Permalink
Merge pull request #146 from sckott/sckott-sess
Browse files Browse the repository at this point in the history
added 4 tiny functions, stolen from the python client
  • Loading branch information
Luke Winslow committed Dec 30, 2015
2 parents b2f0c80 + 72e701d commit e96fa0b
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 0 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(current_session)
export(folder_create)
export(identifier_exists)
export(is.sbitem)
export(is_logged_in)
export(item_append_files)
export(item_create)
export(item_exists)
Expand All @@ -28,6 +29,7 @@ export(item_upload_create)
export(query_item_identifier)
export(query_item_in_folder)
export(query_items)
export(sb_ping)
export(sbtools_DELETE)
export(sbtools_GET)
export(sbtools_POST)
Expand All @@ -36,6 +38,8 @@ export(session_age)
export(session_age_reset)
export(session_check_reauth)
export(session_expired)
export(session_info)
export(session_logout)
export(session_validate)
export(set_endpoint)
export(set_expiration)
Expand Down
12 changes: 12 additions & 0 deletions R/is_logged_in.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Check whether you're logged into a ScienceBase session
#'
#' @export
#' @param ... Additional parameters are passed on to \code{\link[httr]{GET}}
#' @param session SB session object from \code{\link{authenticate_sb}}
#' @return Logical, \code{TRUE} or \code{FALSE}
#' @examples \dontrun{
#' is_logged_in()
#' }
is_logged_in <- function(..., session = current_session()) {
session_info(..., session = session)$isLoggedIn
}
12 changes: 12 additions & 0 deletions R/sb_ping.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Ping ScienceBase to see if it's available
#'
#' @export
#' @param ... Additional parameters are passed on to \code{\link[httr]{GET}}
#' @return list, with \code{"OK"} if ScienceBase is up
#' @examples \dontrun{
#' sb_ping()
#' }
sb_ping <- function(...) {
x <- GET(paste0(pkg.env$url_item, 'ping'), ...)
jsonlite::fromJSON(content(x, "text"))
}
15 changes: 15 additions & 0 deletions R/session_info.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#' Get session info
#'
#' @export
#' @param ... Additional parameters are passed on to \code{\link[httr]{GET}}
#' @param session SB session object from \code{\link{authenticate_sb}}
#' @return list, if not logged in states that, but if logged in, user details
#' @examples \dontrun{
#' session_info()
#' }
session_info <- function(..., session = current_session()) {
x <- GET(paste0(pkg.env$url_base, "jossoHelper/sessionInfo"),
handle = session, ...)
stop_for_status(x)
jsonlite::fromJSON(content(x, "text"))
}
20 changes: 20 additions & 0 deletions R/session_logout.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#' Logout of a ScienceBase session
#'
#' @export
#' @param ... Additional parameters are passed on to \code{\link[httr]{GET}}
#' @param session SB session object from \code{\link{authenticate_sb}}
#' @return invisible, returns nothing if logged out, or errors with message
#' @examples \dontrun{
#' session_logout()
#' }
session_logout <- function(..., session = current_session()) {
if (!is_logged_in(session = session)) {
stop("You're not logged in. See ?authenticate_sb", call. = FALSE)
}
ret <- httr::POST(paste0(pkg.env$url_base, 'j_spring_security_logout'), handle = session, ...)
if (ret$status_code != 200) {
stop("Logout did not succeed", call. = FALSE)
}
pkg.env$session <- NULL
invisible()
}
25 changes: 25 additions & 0 deletions man/is_logged_in.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/is_logged_in.R
\name{is_logged_in}
\alias{is_logged_in}
\title{Check whether you're logged into a ScienceBase session}
\usage{
is_logged_in(..., session = current_session())
}
\arguments{
\item{...}{Additional parameters are passed on to \code{\link[httr]{GET}}}
\item{session}{SB session object from \code{\link{authenticate_sb}}}
}
\value{
Logical, \code{TRUE} or \code{FALSE}
}
\description{
Check whether you're logged into a ScienceBase session
}
\examples{
\dontrun{
is_logged_in()
}
}

23 changes: 23 additions & 0 deletions man/sb_ping.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/sb_ping.R
\name{sb_ping}
\alias{sb_ping}
\title{Ping ScienceBase to see if it's available}
\usage{
sb_ping(...)
}
\arguments{
\item{...}{Additional parameters are passed on to \code{\link[httr]{GET}}}
}
\value{
list, with \code{"OK"} if ScienceBase is up
}
\description{
Ping ScienceBase to see if it's available
}
\examples{
\dontrun{
sb_ping()
}
}

25 changes: 25 additions & 0 deletions man/session_info.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/session_info.R
\name{session_info}
\alias{session_info}
\title{Get session info}
\usage{
session_info(..., session = current_session())
}
\arguments{
\item{...}{Additional parameters are passed on to \code{\link[httr]{GET}}}

\item{session}{SB session object from \code{\link{authenticate_sb}}}
}
\value{
list, if not logged in states that, but if logged in, user details
}
\description{
Get session info
}
\examples{
\dontrun{
session_info()
}
}

25 changes: 25 additions & 0 deletions man/session_logout.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/session_logout.R
\name{session_logout}
\alias{session_logout}
\title{Logout of a ScienceBase session}
\usage{
session_logout(..., session = current_session())
}
\arguments{
\item{...}{Additional parameters are passed on to \code{\link[httr]{GET}}}

\item{session}{SB session object from \code{\link{authenticate_sb}}}
}
\value{
invisible, returns nothing if logged out, or errors with message
}
\description{
Logout of a ScienceBase session
}
\examples{
\dontrun{
session_logout()
}
}

0 comments on commit e96fa0b

Please sign in to comment.