Skip to content

Commit 4f6641c

Browse files
ASA-151: Add documentation to R6 class
1 parent 53129e9 commit 4f6641c

File tree

2 files changed

+278
-0
lines changed

2 files changed

+278
-0
lines changed

R-package/R/client.R

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
1+
#' Class representing an active session connected to the American Soccer Analysis public API.
2+
#'
3+
#' Does not take any arguments to initialize.
14
#' @export
25
AmericanSoccerAnalysis <- R6::R6Class("AmericanSoccerAnalysis",
36
public = list(
7+
#' @field API_VERSION Latest API version.
48
API_VERSION = "v1",
9+
10+
#' @field LEAGUES List of stylized league names.
511
LEAGUES = c("nwsl", "mls", "uslc", "usl1", "nasl"),
12+
13+
#' @field BASE_URL API base URL.
614
BASE_URL = NULL,
15+
16+
#' @field players Data frame containing players from all leagues.
717
players = NULL,
18+
19+
#' @field teams Data frame containing teams from all leagues.
820
teams = NULL,
21+
22+
#' @field stadia Data frame containing stadia from all leagues.
923
stadia = NULL,
24+
25+
#' @field managers Data frame containing managers from all leagues.
1026
managers = NULL,
27+
28+
#' @field referees Data frame containing referees from all leagues.
1129
referees = NULL,
30+
31+
#' @description
32+
#' Creates a new `AmericanSoccerAnalysis` object.
33+
#' @return A new `AmericanSoccerAnalysis` object.
1234
initialize = function() {
1335
self$BASE_URL <- glue::glue("https://app.americansocceranalysis.com/api/{self$API_VERSION}/")
1436
self$players <- get_entity("player", self)
@@ -17,26 +39,65 @@ AmericanSoccerAnalysis <- R6::R6Class("AmericanSoccerAnalysis",
1739
self$managers <- get_entity("manager", self)
1840
self$referees <- get_entity("referee", self)
1941
},
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.
2048
get_players = function(leagues, ids, names) {
2149
players <- filter_entity(self$players, self$LEAGUES, leagues, ids, names)
2250
return(players)
2351
},
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.
2458
get_teams = function(leagues, ids, names) {
2559
teams <- filter_entity(self$teams, self$LEAGUES, leagues, ids, names)
2660
return(teams)
2761
},
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.
2868
get_stadia = function(leagues, ids, names) {
2969
stadia <- filter_entity(self$stadia, self$LEAGUES, leagues, ids, names)
3070
return(stadia)
3171
},
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.
3278
get_managers = function(leagues, ids, names) {
3379
managers <- filter_entity(self$managers, self$LEAGUES, leagues, ids, names)
3480
return(managers)
3581
},
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.
3688
get_referees = function(leagues, ids, names) {
3789
referees <- filter_entity(self$referees, self$LEAGUES, leagues, ids, names)
3890
return(referees)
3991
},
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.
40101
get_games = function(leagues, game_ids, team_ids, team_names, seasons, stages) {
41102
games <- get_games(self, leagues, game_ids, team_ids, team_names, seasons, stages)
42103
return(games)

R-package/man/AmericanSoccerAnalysis.Rd

Lines changed: 217 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)