From 72cba2dd46f81134e58553ba94a5bba029e9ce5b Mon Sep 17 00:00:00 2001 From: jak3sch <66489548+jak3sch@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:09:48 +0200 Subject: [PATCH] fixed ff_rosters() franchise_id for sleeper (#436) * fix for #435 - replaced roster_id with owner_id from sleeper api * revert sleeper_rosters() * added new column to sleeper_userleagues() with roster_id * updated version number and changelog --- DESCRIPTION | 4 ++-- NEWS.md | 1 + R/sleeper_userleagues.R | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0d69e090..7b6f98ad 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: ffscrapr Title: API Client for Fantasy Football League Platforms -Version: 1.4.8.18 +Version: 1.4.8.19 Authors@R: c(person(given = "Tan", family = "Ho", @@ -57,5 +57,5 @@ LazyData: true VignetteBuilder: knitr Encoding: UTF-8 -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Roxygen: list(markdown = TRUE) diff --git a/NEWS.md b/NEWS.md index edf43a19..4b6a9844 100644 --- a/NEWS.md +++ b/NEWS.md @@ -29,6 +29,7 @@ row per player-team-season (v1.4.8.13) (thanks @john-b-edwards!) - Bugfix espn `ff_starters()` to return less than or equal to max week (v1.4.8.16) - [BREAKING] `mfl_players()` and `sleeper_players()` outputs now try to return more standardized column types (v1.4.8.17) +- `sleeper_userleagues()` output has a new column roster_id which is the same ID as franchise_id in `sleeper_rosters()` (1.4.8.19) (#436) # ffscrapr 1.4.8 diff --git a/R/sleeper_userleagues.R b/R/sleeper_userleagues.R index 0968bcc7..fab49dce 100644 --- a/R/sleeper_userleagues.R +++ b/R/sleeper_userleagues.R @@ -37,7 +37,8 @@ ff_userleagues.sleeper_conn <- function(conn = NULL, user_name = NULL, season = dplyr::mutate( league_id = as.character(league_id), franchise_name = purrr::map_chr(.data$league_id, .sleeper_userteams, user_id), - franchise_id = user_id + franchise_id = user_id, + roster_id = purrr::map_int(.data$league_id, .sleeper_rosterid, user_id) ) return(df_leagues) @@ -75,3 +76,17 @@ sleeper_userleagues <- function(user_name, season = NULL) { return(df_teams) } + +#' Get Roster ID +#' @noRd + +.sleeper_rosterid <- function(league_id, user_id) { + df_teams <- sleeper_getendpoint(glue::glue("league/{league_id}/rosters")) %>% + purrr::pluck("content") %>% + tibble::tibble() %>% + tidyr::hoist(1, "owner_id", "roster_id") %>% + dplyr::filter(.data$owner_id == user_id) %>% + dplyr::pull("roster_id") + + return(df_teams) +}