Commit 1621e571 authored by Matija Obreza's avatar Matija Obreza

Hide internal functions

parent cc7fae5f
......@@ -77,7 +77,7 @@ authorization <- function(authorization) {
}
#' Ensure that environment has OAuth token
check_auth <- function() {
.check_auth <- function() {
if (is.null(.genesysEnv$Authorization)) {
warning("You must first authorize with Genesys with user_login() or client_login(...).");
}
......@@ -155,8 +155,8 @@ client_login <- function() {
}
api_call <- function(path, method = "get") {
check_auth()
.api_call <- function(path, method = "get") {
.check_auth()
resp <- httr::GET(api_url(path), httr::add_headers(
Authorization = .genesysEnv$Authorization
)
......@@ -184,8 +184,8 @@ api_url <- function(path) {
paste0(.genesysEnv$server, "/api/v0", path)
}
get <- function(path, query = NULL) {
check_auth()
.get <- function(path, query = NULL) {
.check_auth()
resp <- httr::GET(api_url(path), query = query, httr::add_headers(
Authorization = .genesysEnv$Authorization
))
......@@ -203,8 +203,8 @@ get <- function(path, query = NULL) {
#' @param content.type Content-Type of the body
#'
#' @return httr response
post <- function(path, query = NULL, body = NULL, content.type = "application/json") {
check_auth()
.post <- function(path, query = NULL, body = NULL, content.type = "application/json") {
.check_auth()
content <- jsonlite::toJSON(body)
if (! is.null(body) && length(body) == 0) {
# If body is provided, but has length of 0
......
......@@ -19,7 +19,7 @@
#'
#' @export
me <- function() {
resp <- api_call("/me")
resp <- .api_call("/me")
message(jsonlite::toJSON(resp, pretty = TRUE))
invisible(resp)
}
......@@ -38,9 +38,9 @@ me <- function() {
#' accessions <- fetch_accessions(mcpd_filter(ORIGCTY = c("DEU", "SVN")))
#'
#' @return Paged data structure
fetch_accessions_page <- function(filters = list(), page = 0, size = 1000, selector = NULL) {
.fetch_accessions_page <- function(filters = list(), page = 0, size = 1000, selector = NULL) {
start_time <- as.numeric(as.numeric(Sys.time())*1000, digits=15)
resp <- post(path = "/acn/filter", query=list(p = page, l = size), body = filters)
resp <- .post(path = "/acn/filter", query=list(p = page, l = size), body = filters)
if (httr::status_code(resp) != 200) {
stop("Genesys responded with HTTP status code ", httr::status_code(resp), ". Expected 200.")
}
......@@ -80,11 +80,11 @@ fetch_accessions_page <- function(filters = list(), page = 0, size = 1000, selec
fetch_accessions <- function(filters = list(), page = NULL, size = 1000, selector = NULL, at.least = NULL) {
if (! is.null(page)) {
# Fetch page
return(fetch_accessions_page(filters, page, size, selector));
return(.fetch_accessions_page(filters, page, size, selector));
}
# Fetch first page to determine number of records
paged <- fetch_accessions_page(filters, page = 0, size, selector)
paged <- .fetch_accessions_page(filters, page = 0, size, selector)
pages <- paged$totalPages
for (page in 1:pages) {
......@@ -93,7 +93,7 @@ fetch_accessions <- function(filters = list(), page = NULL, size = 1000, selecto
message(paste("Not requesting data after page", .MAX_ALLOWED_PAGES, "Stopping."))
break
}
p <- fetch_accessions_page(filters, page, size, selector)
p <- .fetch_accessions_page(filters, page, size, selector)
paged$content <- c(paged$content, p$content)
paged$last <- p$last
......
Markdown is supported
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