Skip to content

Commit

Permalink
update espn base url (#428)
Browse files Browse the repository at this point in the history
* Update espn base url

* bumpver

* update httptest redactor

* update httptest requestor

* update base url in a few more places
  • Loading branch information
tanho63 authored May 29, 2024
1 parent a9c35cb commit 60b57fd
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: ffscrapr
Title: API Client for Fantasy Football League Platforms
Version: 1.4.8.17
Version: 1.4.8.18
Authors@R:
c(person(given = "Tan",
family = "Ho",
Expand Down
4 changes: 2 additions & 2 deletions R/espn_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ espn_getendpoint <- function(conn, ..., x_fantasy_filter = NULL) {

if (as.numeric(conn$season) < 2018) {
url_query <- httr::modify_url(
url = glue::glue("https://fantasy.espn.com/apis/v3/games/ffl/leagueHistory/{conn$league_id}?seasonId={conn$season}"),
url = glue::glue("https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/leagueHistory/{conn$league_id}?seasonId={conn$season}"),
query = list(...)
)
}

if (as.numeric(conn$season) >= 2018) {
url_query <- httr::modify_url(
url = glue::glue("https://fantasy.espn.com/apis/v3/games/ffl/seasons/{conn$season}/segments/0/leagues/{conn$league_id}"),
url = glue::glue("https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/{conn$season}/segments/0/leagues/{conn$league_id}"),
query = list(...)
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/espn_players.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ espn_players <- function(conn = NULL, season = NULL) {
xff <- httr::add_headers(`x-fantasy-filter` = xff)

url_query <- glue::glue(
"https://fantasy.espn.com/apis/v3/games/ffl/seasons/",
"https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/",
"{season}/players?scoringPeriodId=0&view=players_wl"
)

Expand Down
4 changes: 2 additions & 2 deletions R/espn_starters.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ff_starters.espn_conn <- function(conn, weeks = 1:17, ...) {
checkmate::assert_numeric(weeks)

settings_url_query <- glue::glue(
"https://fantasy.espn.com/apis/v3/games/ffl/seasons/",
"https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/",
"{conn$season}/segments/0/leagues/{conn$league_id}",
"?scoringPeriodId=0&view=mSettings"
)
Expand Down Expand Up @@ -126,7 +126,7 @@ ff_starters.espn_conn <- function(conn, weeks = 1:17, ...) {

.espn_week_starter <- function(matchup_period, nfl_week, conn) {
url_query <- glue::glue(
"https://fantasy.espn.com/apis/v3/games/ffl/seasons/",
"https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/",
"{conn$season}/segments/0/leagues/{conn$league_id}",
"?scoringPeriodId={nfl_week}&view=mMatchupScore&view=mBoxscore&view=mSettings&view=mRosterSettings"
)
Expand Down
2 changes: 1 addition & 1 deletion R/espn_transactions.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ff_transactions.espn_conn <- function(conn, limit = 1000, ...) {
xff <- httr::add_headers(`x-fantasy-filter` = xff)

url_query <- glue::glue(
"https://fantasy.espn.com/apis/v3/games/ffl/seasons/",
"https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/",
"{conn$season}/segments/0/leagues/{conn$league_id}/",
"communication/?view=kona_league_communication"
)
Expand Down
2 changes: 1 addition & 1 deletion inst/httptest/redact.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
httptest::set_redactor(
function(response){
httptest::gsub_response(response,"https\\://fantasy.espn.com/apis/v3/games/ffl/","espn/") %>%
httptest::gsub_response(response,"https\\://.*fantasy.espn.com/apis/v3/games/ffl/","espn/") %>%
httptest::gsub_response("https\\://api.myfantasyleague.com/","mfl/") %>%
httptest::gsub_response("https\\://api.sleeper.app/","sleeper/") %>%
httptest::gsub_response("https\\://www.fleaflicker.com/","flea/") %>%
Expand Down
2 changes: 1 addition & 1 deletion inst/httptest/request.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
httptest::set_requester(
function(request){
httptest::gsub_request(request,"https\\://fantasy.espn.com/apis/v3/games/ffl/","espn/") %>%
httptest::gsub_request(request,"https\\://.*fantasy.espn.com/apis/v3/games/ffl/","espn/") %>%
httptest::gsub_request("https\\://api.myfantasyleague.com/","mfl/") %>%
httptest::gsub_request("https\\://api.sleeper.app/","sleeper/") %>%
httptest::gsub_request("https\\://www.fleaflicker.com/","flea/") %>%
Expand Down
10 changes: 5 additions & 5 deletions vignettes/espn_getendpoint.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Accessing the ESPN Fantasy API is a bit of an adventure into an undocumented aby
The ESPN Fantasy API is typically accessed from two endpoints:

```
https://fantasy.espn.com/apis/v3/games/ffl/seasons/{season}/segments/0/leagues/{league_id} # for 2018 onward
https://fantasy.espn.com/apis/v3/games/ffl/leagueHistory/{league_id}?seasonId={season} # for 2017 or earlier
https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/{season}/segments/0/leagues/{league_id} # for 2018 onward
https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/leagueHistory/{league_id}?seasonId={season} # for 2017 or earlier
```

Here's a non-exhaustive list of view endpoints that I know of:
Expand All @@ -70,7 +70,7 @@ Alternatively, you can consult the source code of other API packages (including

ESPN's API is mostly structured as making requests of different views against the main league endpoint.

For example, [https://fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/899513?view=mDraftDetail](https://fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/899513?view=mDraftDetail)
For example, [https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/899513?view=mDraftDetail](https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/899513?view=mDraftDetail)

will pull up draft details for the 2020 league ID 899513. `espn_getendpoint` helps facilitate this request by allowing you to instead write:

Expand All @@ -89,7 +89,7 @@ You can also use the lower-level equivalent, `espn_getendpoint_raw`, which does
```{r message = FALSE, eval = eval}
draft_details_raw <- espn_getendpoint_raw(
conn,
"https://fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/899513?view=mDraftDetail")
"https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/899513?view=mDraftDetail")
draft_details_raw
```
Expand Down Expand Up @@ -129,7 +129,7 @@ player_scores <- espn_getendpoint(conn, view = "kona_player_info", x_fantasy_fil
player_scores_2 <- espn_getendpoint_raw(
conn,
"https://fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/899513?view=kona_player_info",
"https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/seasons/2020/segments/0/leagues/899513?view=kona_player_info",
httr::add_headers(`X-Fantasy-Filter` = xff))
```
Expand Down

0 comments on commit 60b57fd

Please sign in to comment.