Commit 913322f1 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

put on gitlab

parents
^.*\.Rproj$
^\.Rproj\.user$
.Rproj.user
.Rhistory
.RData
Package: alapur
Type: Package
Version: 0.0.1
Authors@R: c(person("Jean-Marie", "Lepioufle", , "jml@nilu.no", role=c("aut","cre")),
person("NILU",role="cph"))
Title: alapur
Description: Client api for aladin-ocpu.
Depends:
R (>= 3.2.0)
Imports:
httr,
dplyr,
tibble
License: GPL-3
Encoding: UTF-8
LazyData: false
RoxygenNote: 5.0.1
# Generated by roxygen2: do not edit by hand
export(alapu_get)
export(alapu_post)
export(config_server)
export(endpoints_alapu)
export(endpoints_package)
export(endpoints_session)
export(resp_content)
export(session_key)
#' config_server
#' config_server
#' @param url url
#' @param override override
#' @keywords alapu
#' @export
#' @examples
#' \dontrun{
#' config_server()
#' }
config_server <- function(url,override = FALSE) {
old <- try(getOption("alapu_server"))
if (inherits(old,"try-error")){
old <- NULL
}
if ((!override) && (!is.null(old))) {
config <- c(url,old)
} else config <- url
options(alapu_server = config)
invisible(old)
}
#' endpoints_alapu
#' endpoints_alapu
#' @param api api endpoint
#' @param pkgname pkgname
#' @param key session key
#' @param epoint endpoint
#' @param object object
#' @param format format
#' @param filename filename
#' @keywords alapu
#' @export
#' @examples
#' \dontrun{
#' endpoints_alapu()
#' }
endpoints_alapu <- function(api=c("package","session"),pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL){
api <- match.arg(api,c("package","session"))
res <- switch(api,
"package" = endpoints_package(pkgname=pkgname,epoint=epoint,object=object,format=format),
"session" = endpoints_session(key=key,epoint=epoint,object=object,format=format,filename=filename),
stop("endpoints not recognized"))
class(res) <- "alapu_endpoints"
return(res)
}
#' endpoints_package
#' endpoints_package
#' @param pkgname pkgname
#' @param epoint endpoint
#' @param object object
#' @param format format
#' @keywords alapu
#' @export
#' @examples
#' \dontrun{
#' endpoints_package()
#' }
endpoints_package <- function(pkgname=NULL,epoint=NULL,object=NULL,format=NULL){
if (is.null(pkgname) || is.null(epoint)) {
stop("argument 'pkgname' and 'epoint' required")
}
epoint <- match.arg(epoint,c("info","www","R","data","man","html"))
if ((epoint == "data") || (epoint == "man")) {
if (is.null(object) || is.null(format)) {
stop("argument 'object' and 'format' required")
}
}
res <- switch(epoint,
"info" = alapu_url("library",pkgname,"info"),
"www" = alapu_url("library",pkgname,"www"),
"R" = alapu_url("library",pkgname,"R",object=object,format=format),
"data" = alapu_url("library",pkgname,"data",object=object,format=format),
"man" = alapu_url("library",pkgname,"man",object=object,format=format),
"html" = alapu_url("library",pkgname,"html"),
stop("epoint unknown ",epoint)
)
return(res)
}
#' endpoints_session
#' endpoints_session
#' @param key session key
#' @param epoint endpoint
#' @param object object
#' @param format format
#' @param filename filename
#' @keywords alapu
#' @export
#' @examples
#' \dontrun{
#' endpoints_session()
#' }
endpoints_session <- function(key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL){
if (is.null(key) || is.null(epoint)) {
stop("argument 'key' and 'epoint' required")
}
epoint <- match.arg(epoint,c("-","R","graphics","source","stdout","console","zip","tar","files"))
if ((epoint == "R") ) {
if (is.null(object) || is.null(format)) {
stop("argument 'object' and 'format' required")
}
}
if ((epoint == "files") ) {
if (is.null(filename) ) {
stop("argument 'filename' required")
}
}
res <- switch(epoint,
"-" = alapu_url("tmp",key),
"R" = alapu_url("tmp",key,"R",object=object,format=format),
"graphics" = alapu_url("tmp",key,"graphics"),
"source" = alapu_url("tmp",key,"source"),
"stdout" = alapu_url("tmp",key,"stdout"),
"console" = alapu_url("tmp",key,"console"),
"zip" = alapu_url("tmp",key,"zip"),
"tar" = alapu_url("tmp",key,"tar"),
"files" = alapu_url("tmp",key,"files",filename=filename),
stop("epoint unknown ",epoint)
)
return(res)
}
#' resp_content
#' resp_content
#' @param x alpu_post_res or alpu_get_res object
#' @param as as
#' @param type type
#' @param encoding encoding
#' @param ... other options
#' @keywords alapu
#' @export
#' @examples
#' \dontrun{
#' resp_content()
#' }
resp_content <- function(x,as = NULL, type = NULL, encoding = NULL, ...){
res <- httr::content(x,as = as, type = type, encoding = encoding, ...)
return(res)
}
#' session_key
#' session_key
#' @param x alpu_post_res object
#' @keywords alapu
#' @export
#' @examples
#' \dontrun{
#' session_key()
#' }
session_key <- function(x){
res <- httr::headers(x)$`x-ocpu-session`
return(res)
}
alapu_url <- function(...){
try(url_server <- getOption(x="alapu_server")[1])
if (inherits(url_server,"try-error")){
stop("alapu_server not defined, use config_server")
}
param <- c(as.list(environment()), list(...))
indice <- which(unlist(lapply(param,is.null)))
if (length(indice)) {
param <- param[-indice]
}
res <- do.call("file.path",param)
return(res)
}
#' alapu_post
#' alapu_post
#' @param api api endpoint
#' @param pkgname pkgname
#' @param key session
#' @param epoint endpoint
#' @param object object
#' @param format format
#' @param filename filename
#' @param ... options for post
#' @keywords alapu
#' @export
#' @examples
#' \dontrun{
#' alapu_post()
#' }
alapu_post <- function(api,pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL,...){
url <- endpoints_alapu(api=api,pkgname=pkgname,key=key,epoint=epoint,object=object,format=format,filename=filename)
res <- httr::POST(url,body=list(...),encode = "json")
class(res) <- c("alapu_post_res",class(res))
return(res)
}
#' alapu_get
#' alapu_get
#' @param api api endpoint
#' @param pkgname pkgname
#' @param key session
#' @param epoint endpoint
#' @param object object
#' @param format format
#' @param filename filename
#' @param ... options for get
#' @keywords alapu
#' @export
#' @examples
#' \dontrun{
#' alapu_get()
#' }
alapu_get <- function(api,pkgname=NULL,key=NULL,epoint=NULL,object=NULL,format=NULL,filename=NULL,...){
url <- endpoints_alapu(api=api,pkgname=pkgname,key=key,epoint=epoint,object=object,format=format,filename=filename)
res <- httr::GET(url,...)
class(res) <- c("alapu_get_res",class(res))
return(res)
}
Version: 1.0
RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
Encoding: UTF-8
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/verb.R
\name{alapu_get}
\alias{alapu_get}
\title{alapu_get
alapu_get}
\usage{
alapu_get(api, pkgname = NULL, key = NULL, epoint = NULL, object = NULL,
format = NULL, filename = NULL, ...)
}
\arguments{
\item{api}{api endpoint}
\item{pkgname}{pkgname}
\item{key}{session}
\item{epoint}{endpoint}
\item{object}{object}
\item{format}{format}
\item{filename}{filename}
\item{...}{options for get}
}
\description{
alapu_get
alapu_get
}
\examples{
\dontrun{
alapu_get()
}
}
\keyword{alapu}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/verb.R
\name{alapu_post}
\alias{alapu_post}
\title{alapu_post
alapu_post}
\usage{
alapu_post(api, pkgname = NULL, key = NULL, epoint = NULL,
object = NULL, format = NULL, filename = NULL, ...)
}
\arguments{
\item{api}{api endpoint}
\item{pkgname}{pkgname}
\item{key}{session}
\item{epoint}{endpoint}
\item{object}{object}
\item{format}{format}
\item{filename}{filename}
\item{...}{options for post}
}
\description{
alapu_post
alapu_post
}
\examples{
\dontrun{
alapu_post()
}
}
\keyword{alapu}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/config.R
\name{config_server}
\alias{config_server}
\title{config_server
config_server}
\usage{
config_server(url, override = FALSE)
}
\arguments{
\item{url}{url}
\item{override}{override}
}
\description{
config_server
config_server
}
\examples{
\dontrun{
config_server()
}
}
\keyword{alapu}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/endpoints.R
\name{endpoints_alapu}
\alias{endpoints_alapu}
\title{endpoints_alapu
endpoints_alapu}
\usage{
endpoints_alapu(api = c("package", "session"), pkgname = NULL, key = NULL,
epoint = NULL, object = NULL, format = NULL, filename = NULL)
}
\arguments{
\item{api}{api endpoint}
\item{pkgname}{pkgname}
\item{key}{session key}
\item{epoint}{endpoint}
\item{object}{object}
\item{format}{format}
\item{filename}{filename}
}
\description{
endpoints_alapu
endpoints_alapu
}
\examples{
\dontrun{
endpoints_alapu()
}
}
\keyword{alapu}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/endpoints.R
\name{endpoints_package}
\alias{endpoints_package}
\title{endpoints_package
endpoints_package}
\usage{
endpoints_package(pkgname = NULL, epoint = NULL, object = NULL,
format = NULL)
}
\arguments{
\item{pkgname}{pkgname}
\item{epoint}{endpoint}
\item{object}{object}
\item{format}{format}
}
\description{
endpoints_package
endpoints_package
}
\examples{
\dontrun{
endpoints_package()
}
}
\keyword{alapu}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/endpoints.R
\name{endpoints_session}
\alias{endpoints_session}
\title{endpoints_session
endpoints_session}
\usage{
endpoints_session(key = NULL, epoint = NULL, object = NULL,
format = NULL, filename = NULL)
}
\arguments{
\item{key}{session key}
\item{epoint}{endpoint}
\item{object}{object}
\item{format}{format}
\item{filename}{filename}
}
\description{
endpoints_session
endpoints_session
}
\examples{
\dontrun{
endpoints_session()
}
}
\keyword{alapu}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/resp_content.R
\name{resp_content}
\alias{resp_content}
\title{resp_content
resp_content}
\usage{
resp_content(x, as = NULL, type = NULL, encoding = NULL, ...)
}
\arguments{
\item{x}{alpu_post_res or alpu_get_res object}
\item{as}{as}
\item{type}{type}
\item{encoding}{encoding}
\item{...}{other options}
}
\description{
resp_content
resp_content
}
\examples{
\dontrun{
resp_content()
}
}
\keyword{alapu}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/session_key.R
\name{session_key}
\alias{session_key}
\title{session_key
session_key}
\usage{
session_key(x)
}
\arguments{
\item{x}{alpu_post_res object}
}
\description{
session_key
session_key
}
\examples{
\dontrun{
session_key()
}
}
\keyword{alapu}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment