Skip to content

Commit

Permalink
Use mNav view for teams and members
Browse files Browse the repository at this point in the history
Allows addition of member names and team logos to respective functions
  • Loading branch information
k5cents committed Nov 9, 2023
1 parent 07a24a1 commit 48c2115
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
docs/
docs
inst/doc
.DS_Store
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: fflr
Title: Retrieve ESPN Fantasy Football Data
Version: 2.2.0.9001
Version: 2.2.0.9002
Authors@R:
person("Kiernan", "Nicholls", , "[email protected]", role = c("aut", "cre", "cph"))
Description: Format the raw data from the ESPN fantasy football API
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# fflr (development version)

* The functions `league_members()` and `league_teams()` have been adjusted to
add new columns. The order of columns has also been rearranged to focus on
the output of each function (all teams or all members), since some teams can
have multiple owners or multiple teams can have the same owner.
* Add `firstName` and `lastName` to `league_members()`
* Add `logo` and `logoType` to `league_teams()`
* Use latest package dependencies.

# fflr 2.2.0
Expand Down
3 changes: 3 additions & 0 deletions R/members.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ league_members <- function(leagueId = ffl_id(), leagueHistory = FALSE, ...) {
dat <- ffl_api(
leagueId = leagueId,
leagueHistory = leagueHistory,
view = "mNav",
...
)
if (leagueHistory && is.list(dat$teams)) {
Expand All @@ -23,6 +24,8 @@ league_members <- function(leagueId = ffl_id(), leagueHistory = FALSE, ...) {
}

out_member <- function(x) {
x <- x[, c("id", "displayName", "firstName", "lastName",
"isLeagueCreator", "isLeagueManager")]
x <- change_names(x, "id", "memberId")
as_tibble(x)
}
4 changes: 4 additions & 0 deletions R/teams.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ league_teams <- function(leagueId = ffl_id(), leagueHistory = FALSE, ...) {
dat <- ffl_api(
leagueId = leagueId,
leagueHistory = leagueHistory,
view = "mNav",
...
)
if (leagueHistory && is.list(dat$teams)) {
Expand All @@ -26,6 +27,9 @@ league_teams <- function(leagueId = ffl_id(), leagueHistory = FALSE, ...) {
}

out_team <- function(z, trim = FALSE) {
if ("logoType" %in% names(z)) {
z <- z[, c("id", "abbrev", "name", "logo", "logoType", "owners")]
}
z <- change_names(z, "id", "teamId")
z <- change_names(z, "owners", "memberId")
z$abbrev <- factor(z$teamId, labels = z$abbrev)
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-members.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
test_that("league members", {
m <- league_members(leagueId = "42654852")
expect_s3_class(m, "data.frame")
expect_length(m, 3)
expect_length(m, 6)
})

test_that("league members history with names", {
m <- league_members(leagueId = "42654852", leagueHistory = TRUE)
expect_type(m, "list")
expect_named(m)
expect_s3_class(m[[1]], "data.frame")
expect_length(m[[1]], 3)
expect_length(m[[1]], 6)
})

0 comments on commit 48c2115

Please sign in to comment.