R/GetSettledSpecialFixtures.R

#' Get Settled Special Fixtures
#'
#' @param sportid (optional) an integer giving the sport, if missing, a menu of options is presented
#' @param leagueids (optional) integer vector with league IDs.
#' @param since (optional) numeric This is used to receive incremental updates.
#' Use the value of last from previous fixtures response.
#'
#' @return a data.frame of settled special fixtures
#' @export
#' @import data.table
#' @examples
#' \donttest{
#' SetCredentials("TESTAPI", "APITEST")
#' AcceptTermsAndConditions(accepted=TRUE)
#' # Can be run without arguments
#' GetSettledSpecialFixtures()}
GetSettledSpecialFixtures <- function(sportid, 
                               leagueids = NULL, 
                               since = NULL) {
  

  if (missing(sportid)) {
    cat('No Sports Selected, choose one:\n')
    ViewSports()
    sportid <- readline('Selection (id): ')
  }
  
  message(
    Sys.time(),
    '| Pulling Settled Special Fixtures for - sportid: ', sportid,
    if (!is.null(leagueids)) sprintf(' leagueids: %s', paste(leagueids, collapse = ', ')),
    if (!is.null(since)) sprintf(' since: %s', since)
  )
  r <- sprintf('%s/v1/fixtures/special/settled',.PinnacleAPI$url) %>%
    GET(add_headers(Authorization = authorization(),
                    "Content-Type" = "application/json"),
        query = list(sportId = sportid,
                     leagueIds = if (!is.null(leagueids)) paste(leagueids,collapse = ',') else NULL,
                     since = since)) %>%
    
    content(type = "text", encoding = "UTF-8") 
  if (identical(r, '')) return(data.frame())

  r %>%
    jsonlite::fromJSON(flatten = TRUE) %>%
    as.data.table %>%
    expandListColumns() %>%
    with({

      if (all(sapply(.,is.atomic))) .
      else expandListColumns(.)
    }) %>%
    as.data.frame()
  
}

Try the pinnacle.API package in your browser

Any scripts or data that you put into this service are public.

pinnacle.API documentation built on May 2, 2019, 10:24 a.m.