From 6ed2c4164b0b2e8addab8085c84fb5f746a607d2 Mon Sep 17 00:00:00 2001 From: Levi Waldron Date: Sat, 31 Oct 2026 23:55:03 -0400 Subject: [PATCH] Add host argument to BEDbase() Closes #5 Co-authored-by: Claude Code --- R/bedbaser.R | 13 ++++++++++--- man/BEDbase.Rd | 6 ++++-- tests/testthat/test-bedbaser.R | 7 +++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/R/bedbaser.R b/R/bedbaser.R index 10e1dbb..d236c94 100644 --- a/R/bedbaser.R +++ b/R/bedbaser.R @@ -40,6 +40,9 @@ #' #' @param cache_path character(1) cache #' @param quietly logical(1) (default \code{FALSE}) display messages +#' @param host character(1) (default \code{"api.bedbase.org"}) API host, +#' e.g., a development or test server. Prefix with \code{http://} for a +#' server without TLS. #' #' @return BEDbase object #' @@ -49,7 +52,10 @@ #' bb_metadata(bedbase, ex_bed$id) #' #' @export -BEDbase <- function(cache_path, quietly = FALSE) { +BEDbase <- function(cache_path, quietly = FALSE, host = "api.bedbase.org") { + stopifnot(is.character(host), length(host) == 1L, nzchar(host)) + scheme <- if (startsWith(host, "http://")) "http" else "https" + host <- sub("^https?://", "", host) if (missing(cache_path)) { cache_path <- tools::R_user_dir("bedbaser", which = "cache") } @@ -61,12 +67,13 @@ BEDbase <- function(cache_path, quietly = FALSE) { bedsets = BiocFileCache::BiocFileCache(bedsets_path, ask = FALSE), AnVIL::Service( service = "bedbase", - host = "api.bedbase.org", + host = host, api_reference_version = .BEDBASE_API_REFERENCE_VERSION, authenticate = FALSE, package = "bedbaser", api_url = character(), - api_reference_url = "https://api.bedbase.org/v1/openapi.json", + schemes = scheme, + api_reference_url = paste0(scheme, "://", host, "/v1/openapi.json") ) ) ) diff --git a/man/BEDbase.Rd b/man/BEDbase.Rd index a871a06..00a7a55 100644 --- a/man/BEDbase.Rd +++ b/man/BEDbase.Rd @@ -7,7 +7,7 @@ \alias{setCache} \title{An R client for BEDbase} \usage{ -BEDbase(cache_path, quietly = FALSE) +BEDbase(cache_path, quietly = FALSE, host = "api.bedbase.org") \S4method{show}{BEDbase}(object) @@ -20,7 +20,9 @@ setCache(x, cache_path, quietly = TRUE) \item{quietly}{logical(1) (default \code{TRUE}) display messages} -\item{object}{BEDbase() object} +\item{host}{character(1) (default \code{"api.bedbase.org"}) API host, +e.g., a development or test server. Prefix with \code{http://} for a +server without TLS.} \item{x}{BEDbase() object} diff --git a/tests/testthat/test-bedbaser.R b/tests/testthat/test-bedbaser.R index 51803e5..c668a9d 100644 --- a/tests/testthat/test-bedbaser.R +++ b/tests/testthat/test-bedbaser.R @@ -191,3 +191,10 @@ test_that("show prints a summary", { expect_output(show(bedbase), "BEDbase client") expect_output(show(bedbase), "api.bedbase.org") }) + +test_that("BEDbase host argument is used", { + expect_equal(bedbase@host, "api.bedbase.org") + with_scheme <- BEDbase(tempdir(), quietly = TRUE, host = "https://api.bedbase.org") + expect_equal(with_scheme@host, "api.bedbase.org") + expect_error(BEDbase(tempdir(), quietly = TRUE, host = "")) +})