|
| 1 | +#' Class representing an active session connected to the American Soccer Analysis public API. |
| 2 | +#' |
| 3 | +#' Does not take any arguments to initialize. |
| 4 | +#' @export |
| 5 | +AmericanSoccerAnalysis <- R6::R6Class("AmericanSoccerAnalysis", |
| 6 | + public = list( |
| 7 | + #' @field API_VERSION Latest API version. |
| 8 | + API_VERSION = "v1", |
| 9 | + |
| 10 | + #' @field LEAGUES List of stylized league names. |
| 11 | + LEAGUES = c("nwsl", "mls", "uslc", "usl1", "nasl"), |
| 12 | + |
| 13 | + #' @field BASE_URL API base URL. |
| 14 | + BASE_URL = NULL, |
| 15 | + |
| 16 | + #' @field players Data frame containing players from all leagues. |
| 17 | + players = NULL, |
| 18 | + |
| 19 | + #' @field teams Data frame containing teams from all leagues. |
| 20 | + teams = NULL, |
| 21 | + |
| 22 | + #' @field stadia Data frame containing stadia from all leagues. |
| 23 | + stadia = NULL, |
| 24 | + |
| 25 | + #' @field managers Data frame containing managers from all leagues. |
| 26 | + managers = NULL, |
| 27 | + |
| 28 | + #' @field referees Data frame containing referees from all leagues. |
| 29 | + referees = NULL, |
| 30 | + |
| 31 | + #' @description |
| 32 | + #' Creates a new `AmericanSoccerAnalysis` object. |
| 33 | + #' @return A new `AmericanSoccerAnalysis` object. |
| 34 | + initialize = function() { |
| 35 | + self$BASE_URL <- glue::glue("https://app.americansocceranalysis.com/api/{self$API_VERSION}/") |
| 36 | + self$players <- get_entity("player", self) |
| 37 | + self$teams <- get_entity("team", self) |
| 38 | + self$stadia <- get_entity("stadium", self) |
| 39 | + self$managers <- get_entity("manager", self) |
| 40 | + self$referees <- get_entity("referee", self) |
| 41 | + }, |
| 42 | + |
| 43 | + #' @description |
| 44 | + #' Retrieves a data frame containing player names, IDs, and other metadata. |
| 45 | + #' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1. |
| 46 | + #' @param ids Player IDs on which to filter. Accepts a character vector of length >= 1. |
| 47 | + #' @param names Player names on which to filter. Partial matches are accepted. Accepts a character vector of length >= 1. |
| 48 | + get_players = function(leagues, ids, names) { |
| 49 | + players <- filter_entity(self$players, self$LEAGUES, leagues, ids, names) |
| 50 | + return(players) |
| 51 | + }, |
| 52 | + |
| 53 | + #' @description |
| 54 | + #' Retrieves a data frame containing team names, abbreviations, and IDs. |
| 55 | + #' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1. |
| 56 | + #' @param ids Team IDs on which to filter. Accepts a character vector of length >= 1. |
| 57 | + #' @param names Team names on which to filter. Partial matches and abbreviations are accepted. Accepts a character vector of length >= 1. |
| 58 | + get_teams = function(leagues, ids, names) { |
| 59 | + teams <- filter_entity(self$teams, self$LEAGUES, leagues, ids, names) |
| 60 | + return(teams) |
| 61 | + }, |
| 62 | + |
| 63 | + #' @description |
| 64 | + #' Retrieves a data frame containing stadium names, IDs, and other metadata. |
| 65 | + #' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1. |
| 66 | + #' @param ids Stadium IDs on which to filter. Accepts a character vector of length >= 1. |
| 67 | + #' @param names Stadium names on which to filter. Partial matches are accepted. Accepts a character vector of length >= 1. |
| 68 | + get_stadia = function(leagues, ids, names) { |
| 69 | + stadia <- filter_entity(self$stadia, self$LEAGUES, leagues, ids, names) |
| 70 | + return(stadia) |
| 71 | + }, |
| 72 | + |
| 73 | + #' @description |
| 74 | + #' Retrieves a data frame containing manager names and IDs. |
| 75 | + #' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1. |
| 76 | + #' @param ids Manager IDs on which to filter. Accepts a character vector of length >= 1. |
| 77 | + #' @param names Manager names on which to filter. Partial matches are accepted. Accepts a character vector of length >= 1. |
| 78 | + get_managers = function(leagues, ids, names) { |
| 79 | + managers <- filter_entity(self$managers, self$LEAGUES, leagues, ids, names) |
| 80 | + return(managers) |
| 81 | + }, |
| 82 | + |
| 83 | + #' @description |
| 84 | + #' Retrieves a data frame containing referee names and IDs. |
| 85 | + #' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1. |
| 86 | + #' @param ids Referee IDs on which to filter. Accepts a character vector of length >= 1. |
| 87 | + #' @param names Referee names on which to filter. Partial matches are accepted. Accepts a character vector of length >= 1. |
| 88 | + get_referees = function(leagues, ids, names) { |
| 89 | + referees <- filter_entity(self$referees, self$LEAGUES, leagues, ids, names) |
| 90 | + return(referees) |
| 91 | + }, |
| 92 | + |
| 93 | + #' @description |
| 94 | + #' Retrieves a data frame containing game IDs, dates, opponents, scores, and other metadata. |
| 95 | + #' @param leagues Leagues on which to filter. Accepts a character vector of length >= 1. |
| 96 | + #' @param game_ids Game IDs on which to filter. Accepts a character vector of length >= 1. |
| 97 | + #' @param team_ids Team IDs on which to filter. Accepts a character vector of length >= 1. |
| 98 | + #' @param team_names Team names on which to filter. Partial matches and abbreviations are accepted. Accepts a character vector of length >= 1. |
| 99 | + #' @param seasons Seasons on which to filter. Accepts a character or integer vector of length >= 1. |
| 100 | + #' @param stages Stages (e.g., regular season, playoffs, etc.) on which to filter. See the \url{https://app.americansocceranalysis.com/api/v1/__swagger__/}{API documentation} for possible values. Accepts a character vector of length >= 1. |
| 101 | + get_games = function(leagues, game_ids, team_ids, team_names, seasons, stages) { |
| 102 | + games <- get_games(self, leagues, game_ids, team_ids, team_names, seasons, stages) |
| 103 | + return(games) |
| 104 | + } |
| 105 | + ) |
| 106 | +) |
0 commit comments