R/get_standings.R

Defines functions get_standings

#' Get Standings
#'
#' @param config httr config object linked to oauth token
#' @param league_id league ID string; retrieved automatically from sign-in if not stipulated
#'
#' @return tibble of standings
#' @export
#'
#' @examples
#' get_standings(config)
get_standings <- function(config, league_id = NULL) {
  if (is.null(league_id)) {
    team_key <- get_team_key(config)
    league_id <- strsplit(team_key, "\\.") %>%
      unlist() %>%
      .[1:3] %>%
      str_c(collapse=".")
  }

  path <- paste("league", league_id, "standings", sep = "/")
  resp <- get_data(path, config) %>%
    content(as = "parsed")$fantasy_content$league[[2]]$standings[[1]]$teams

  # subset result to ignore last list "count"
  resp <- resp[-length(resp)]

  for (i in length(resp)) {
    # TODO get each team, get a big tibble together, add it to master tibble
  }
}
TK2575/fantasyFootballData documentation built on May 17, 2019, 10:37 a.m.