R/get_match_history_2.R

Defines functions get_match_history_2

Documented in get_match_history_2

#' @title A list of matches
#'
#' @description This function is a wrapper of RDota2::get_match_history. The purpose of this
#'     function is to try to collect the history of matches until your success or fail, without
#'     returning a error.
#'
#'
get_match_history_2 <- function(...) {
    while (TRUE) {
        if (isTRUE(curl::has_internet())) {
            content <-  R.utils::withTimeout(
                                     RDota2::get_match_history(...), 
                                     timeout = 3,
                                     onTimeout = "silent"
                                 )
            
            if (content$response[["status_code"]] %in% c(429, 503, 500, 777)) {
                Sys.sleep(30)
            } else if (content$response[["status_code"]] %in% c(400, 404, 401, 403)) {
                content <- NULL
                break
            } else {
                break
            }
        } else {
            Sys.sleep(2)
        }
    }

    return(content)
}
Andryas/RDota2Plus documentation built on May 7, 2019, 8:19 a.m.