-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from sckott/sckott-sess
added 4 tiny functions, stolen from the python client
- Loading branch information
Showing
9 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
|