Skip to content

Commit

Permalink
refactor(style): format the code using lsp document format provider
Browse files Browse the repository at this point in the history
... and run a few chores.
  • Loading branch information
vst committed Dec 2, 2022
1 parent d587b77 commit 56603ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
32 changes: 25 additions & 7 deletions R/base.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ RocketBase <- R6::R6Class("RocketBase", ## nolint
private$setup()
},

#' @description Prints rudimentary information about the remote PocketBase API instance.
#' @description Prints rudimentary information about the remote
#' PocketBase API instance.
info = function() {
cat(sprintf("PocketBase Instance URL: %s\n", self$url))
},
Expand Down Expand Up @@ -73,8 +74,8 @@ RocketBase <- R6::R6Class("RocketBase", ## nolint
self$bare <- crul::HttpClient$new(
url = self$url,
headers = list(
Authorization=sprintf("%s", private$token),
"User-Agent"=private$useragent()
Authorization = sprintf("%s", private$token),
"User-Agent" = private$useragent()
)
)
},
Expand All @@ -84,24 +85,41 @@ RocketBase <- R6::R6Class("RocketBase", ## nolint
## Build the HTTP client:
client <- crul::HttpClient$new(url = self$url)

## Define authentication endpoint path:
path <- "/api/admins/auth-with-password"

## Define credentials payload:
credentials <- list(
identity = private$identity,
password = private$password
)

## Issue the authentication request and get a response:
response <- client$post("/api/admins/auth-with-password", body=list(identity=private$identity, password=private$password))
response <- client$post(path, body = credentials)

## Check if response status is 200. If not, raise error as it implies that authentication has failed.
## If response status is not 200, raise error as it implies
## failed authentication:
if (response$status_code != 200) {
stop("Authentication failed.")
}

## Parse the content of the response:
content <- jsonlite::fromJSON(response$parse(encoding="UTF-8"))
content <- jsonlite::fromJSON(response$parse(encoding = "UTF-8"))

## Return the authentication token:
content$token
},

## Builds the user-agent string.
useragent = function() {
sprintf( "rocketbase/%s (%s; on:%s)", utils::packageVersion("rocketbase"), Sys.info()["sysname"], Sys.info()["nodename"])
## Get package version:
version <- utils::packageVersion("rocketbase")

## Get operating system:
sysname <- Sys.info()["sysname"]

## Build the "User-Agent" header value:
sprintf("rocketbase/%s (%s)", version, sysname)
}
)
)
3 changes: 2 additions & 1 deletion man/RocketBase.Rd

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

0 comments on commit 56603ba

Please sign in to comment.