Skip to content

Commit

Permalink
Add quiet parameter to all API calls (#105)
Browse files Browse the repository at this point in the history
* Add quiet parameter to all API calls.
* Make URL calls quiet by default
  • Loading branch information
jason-p-pickering authored Aug 2, 2022
1 parent 455b6e4 commit 81b7438
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 87 deletions.
10 changes: 8 additions & 2 deletions R/callDATIMapi.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
#' @param timeout how long should a reponse be waited for
#' @param api_version defaults to current but can pass in version number
#' @param verbose return raw content with data
#' @param quiet Echo the URL which is called to the console.
#' @return Result of DATIM API query returned as named list.
#'
api_get <- function(path,
d2_session,
retry = 1, timeout = 60,
api_version = NULL, verbose = FALSE) {
api_version = NULL,
verbose = FALSE,
quiet = TRUE) {

base_url <- d2_session$base_url
handle <- d2_session$handle
Expand Down Expand Up @@ -77,7 +80,10 @@ api_get <- function(path,

# removes whitespace
url <- gsub(" ", "", url)
print(url)
if (!quiet) {
print(url)
}

# retry api get block, only retries if reponse code not in 400s
i <- 1
response_code <- 5
Expand Down
7 changes: 5 additions & 2 deletions R/getAnalytics.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' it will be made upon logining in to datim with loginToDATIM
#' @param retry retry
#' @param verbose return raw content with data
#' @param quiet Echo the URL which is called to the console if TRUE.
#' @return data frame with the rows of the response

getAnalytics <- function(...,
Expand All @@ -33,7 +34,8 @@ getAnalytics <- function(...,
d2_session = dynGet("d2_default_session", inherits = TRUE),
retry = 1,
timeout = 60,
verbose = FALSE) {
verbose = FALSE,
quiet = TRUE) {

# cap time out at 5 minutes
if (timeout > 300) {
Expand Down Expand Up @@ -81,7 +83,8 @@ getAnalytics <- function(...,
d2_session = d2_session,
retry = retry,
timeout = timeout,
verbose = verbose)
verbose = verbose,
quiet = quiet)

if (verbose) {
meta_data <- resp$api_responses
Expand Down
7 changes: 5 additions & 2 deletions R/getDataValueSets.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
#' @param retry number of times to retry
#' @param timeout number of seconds to wait during call
#' @param verbose return raw content with data
#' @param quiet Echo the URL which is called to the console if TRUE.
#' @return Data frame with the data requested
#'
getDataValueSets <- function(variable_keys = NULL, #keys,
variable_values = NULL, #values,
d2_session = dynGet("d2_default_session",
inherits = TRUE),
retry = 1, timeout = 180,
verbose = FALSE) {
verbose = FALSE,
quiet = TRUE) {

#Test that the provided variables have their associated values used for
# munging
Expand Down Expand Up @@ -80,7 +82,8 @@ getDataValueSets <- function(variable_keys = NULL, #keys,
d2_session = d2_session,
retry = retry,
timeout = timeout,
verbose = verbose
verbose = verbose,
quiet = quiet
)

if (verbose) {
Expand Down
8 changes: 6 additions & 2 deletions R/getMetadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ simplifyStructure <- function(resp) {
#' @param retry number of times to retry
#' @param timeout integer - seconds to wait for a response, default = 180
#' @param verbose return raw content with data
#' @param quiet Echo the URL which is called to the console if TRUE.
#' @return the metadata response in json format and flattened
#'

Expand All @@ -90,7 +91,9 @@ getMetadata <- function(end_point,
d2_session = dynGet("d2_default_session",
inherits = TRUE),
retry = 1,
timeout = 180, verbose = FALSE) {
timeout = 180,
verbose = FALSE,
quiet = TRUE) {
if (!is.character(fields)) {
stop("The fields argument of getMetadata should be of type character")
}
Expand Down Expand Up @@ -127,7 +130,8 @@ getMetadata <- function(end_point,
path = path, d2_session = d2_session, retry = retry,
timeout = timeout,
api_version = NULL,
verbose = verbose
verbose = verbose,
quiet = quiet
)

if (verbose) {
Expand Down
Loading

0 comments on commit 81b7438

Please sign in to comment.