R/football_get_upcoming.R

Defines functions football_get_upcoming

Documented in football_get_upcoming

#' Get upcoming matches
#'
#' Hits the matches API fixed on \code{status=SCHEDULED}.
#'
#' @param team_id What is the team id
#' @param api Which API to use.
#' @param api_token Your API token.
#'
#' @return Base url for API
#'
#' @examples
#' football_get_upcoming()
#'
#' @export
football_get_upcoming <- function(
  team_id = 86,
  api = "football-data.org",
  api_token = Sys.getenv("API_FOOTBALL_DATA")
){
  # allow later api's to be added
  api_endpoint <- switch(
    api,
    "football-data.org" = glue::glue("teams/{team_id}/matches?status=SCHEDULED")
  )

  # get the data
  data <- football_pull(
    api = api,
    api_endpoint = api_endpoint,
    api_token = api_token)

  # clean football-data.org
  data_clean <- data$matches

  data_clean
}
epijim/FootballData documentation built on March 3, 2021, 11:52 p.m.