Skip to content

Commit

Permalink
set default values for parameters of $connect() to NULL (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
flahn committed Jan 14, 2022
1 parent 1738db7 commit 89891c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions R/client.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ NULL
#' \item{\code{$isLoggedIn()}}{returns a logical describing whether the user is logged in}
#' \item{\code{$getHost()}}{returns the host URL}
#' \item{\code{$stopIfNotConnected()}}{throws an error if called and the client is not connected}
#' \item{\code{$connect(url,version)}}{connects to a specific version of a back-end}
#' \item{\code{$connect(url=NULL,version=NULL)}}{connects to a specific version of a back-end}
#' \item{\code{$api_version()}}{returns the openEO API version this client is compliant to}
#' \item{\code{$login(login_type = NULL,user=NULL, password=NULL,provider=NULL,config=NULL)}}{creates an \code{\link{IAuth}} object based on the login_type}
#' \item{\code{$logout()}}{invalidates the access_token and terminates the current session}
Expand Down Expand Up @@ -136,14 +136,14 @@ OpenEOClient <- R6Class(
}
},

connect = function(url,version,exchange_token="access_token") {
connect = function(url=NULL,version=NULL,exchange_token="access_token") {
tryCatch({
if (missing(url) && length(self$getHost()) == 0) {
if (is.null(url) && length(self$getHost()) == 0) {
message("Note: Host-URL is missing")
return(invisible(self))
}

if (!missing(url)) {
if (!is.null(url)) {
private$setHost(url)
}
response = NULL
Expand All @@ -154,7 +154,7 @@ OpenEOClient <- R6Class(
if (length(response) == 0) return(invisible(NULL))

private$exchange_token = exchange_token
if (!missing(version) && !is.null(version)) {
if (!is.null(version)) {
# url is not specific, then resolve /.well-known/openeo and check if the version is allowed
hostInfo = private$backendVersions()$versions

Expand Down
2 changes: 1 addition & 1 deletion man/OpenEOClient.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions tests/testthat/test-client.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ test_that("connect with invalid url fails when setting via initialization", {
expect_error(x$connect(),regexp = "resolve host: example.foo")
})

test_that("connect with missing url fails when setting via initialization", {
x = openeo:::OpenEOClient$new(host = NULL)
expect_message(x$connect(),regexp = "Host-URL is missing")
})

test_that("connect with valid url", {
skip_if_offline()
x = openeo:::OpenEOClient$new(host = "https://openeo.cloud")
Expand Down

0 comments on commit 89891c8

Please sign in to comment.