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

Hide internal functions

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