Skip to content

Commit 6f87be5

Browse files
authored
Cherrypick dp changes and httptest changes (#191)
* Cherrypick dp changes and httptest changes In order to submit to CRAN as v1.2.2 * restyle, rebuild readme * update cran comments * update README for url issues * ci skip * update crancomments, ci skip * add resubmission note, ci skip
1 parent 6d51060 commit 6f87be5

File tree

191 files changed

+4586
-575
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+4586
-575
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: ffscrapr
33
Title: API Client for Fantasy Football League Platforms
4-
Version: 1.2.1
4+
Version: 1.2.2
55
Authors@R:
66
person(given = "Tan",
77
family = "Ho",

NEWS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# ffscrapr 1.2.2
2+
Minor patches to dp_import functions to address issues discovered by CRAN checks.
3+
4+
Also adds minor helper function, `dp_cleannames`, which is a utility function for cleaning player names that removes common suffixes, preiods, and apostrophes.
5+
6+
### Minor patches
7+
- Refactored `dp_values()` and `dp_playerids()` functions to use httr backend for compat with httptest, preventing CRAN errors.
8+
- Added inst-level redactor for httptest.
9+
110
# ffscrapr 1.2.1
211

312
### Minor patches

R/dp_import.R

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@
2020
dp_values <- function(file = c("values.csv", "values-players.csv", "values-picks.csv")) {
2121
file_name <- match.arg(file)
2222

23-
utils::read.csv(
24-
glue::glue("https://github.com/DynastyProcess/data/raw/master/files/{file_name}"),
25-
stringsAsFactors = FALSE
26-
) %>%
27-
dplyr::mutate(scrape_date = lubridate::as_date(.data$scrape_date)) %>%
23+
url_query <- glue::glue("https://github.com/DynastyProcess/data/raw/master/files/{file_name}")
24+
25+
response <- httr::RETRY("GET", url_query, httr::accept("text/csv"))
26+
27+
if (httr::http_error(response)) {
28+
stop(glue::glue("GitHub request failed with error: <{httr::status_code(response)}> \n
29+
while calling <{url_query}>"), call. = FALSE)
30+
}
31+
32+
content <- response %>%
33+
httr::content() %>%
34+
utils::read.csv(text = ., stringsAsFactors = FALSE) %>%
2835
dplyr::mutate_at(dplyr::vars(dplyr::ends_with("id")), as.character) %>%
2936
tibble::tibble()
3037
}
@@ -44,10 +51,50 @@ dp_values <- function(file = c("values.csv", "values-players.csv", "values-picks
4451
#'
4552
#' @export
4653
dp_playerids <- function() {
47-
utils::read.csv(
48-
glue::glue("https://github.com/DynastyProcess/data/raw/master/files/db_playerids.csv"),
49-
stringsAsFactors = FALSE
50-
) %>%
54+
url_query <- "https://github.com/DynastyProcess/data/raw/master/files/db_playerids.csv"
55+
56+
response <- httr::RETRY("GET", url_query, httr::accept("text/csv"))
57+
58+
if (httr::http_error(response)) {
59+
stop(glue::glue("GitHub request failed with error: <{httr::status_code(response)}> \n
60+
while calling <{url_query}>"), call. = FALSE)
61+
}
62+
63+
content <- response %>%
64+
httr::content() %>%
65+
utils::read.csv(text = ., stringsAsFactors = FALSE) %>%
5166
dplyr::mutate_at(dplyr::vars(dplyr::ends_with("id")), as.character) %>%
5267
tibble::tibble()
68+
69+
return(content)
70+
}
71+
72+
#' Clean Names
73+
#'
74+
#' Applies some name-cleaning heuristics to facilitate joins.
75+
#' May eventually refer to a name-cleaning database, for now will just include basic regex.
76+
#'
77+
#' @param player_name a character (or character vector)
78+
#' @param lowercase defaults to FALSE - if TRUE, converts to lowercase
79+
#'
80+
#' @examples
81+
#' \donttest{
82+
#' dp_cleannames(c("A.J. Green", "Odell Beckham Jr.", "Le'Veon Bell Sr."))
83+
#' }
84+
#'
85+
#' @return a character vector of cleaned names
86+
#'
87+
#' @export
88+
89+
dp_cleannames <- function(player_name, lowercase = FALSE) {
90+
checkmate::assert_logical(lowercase)
91+
checkmate::assert_character(player_name)
92+
93+
n <- stringr::str_remove_all(player_name, "( Jr\\.$)|( Sr\\.$)|( III$)|( II$)|( IV$)|( V$)|(\\')|(\\.)")
94+
95+
if (lowercase) n <- tolower(n)
96+
97+
n <- stringr::str_squish(n)
98+
99+
return(n)
53100
}

README.Rmd

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,40 @@ knitr::opts_chunk$set(
1212
out.width = "100%"
1313
)
1414
15-
options(tibble.print_min = 5)
16-
15+
options(tibble.print_min = 5, pillar.bold = TRUE, pillar.min_chars = 25, pillar.min_title_chars = 25)
16+
httptest::.mockPaths("tests/testthat")
17+
httptest::use_mock_api()
1718
```
1819
# ffscrapr <a href='#'><img src='man/figures/logo.png' align="right" height="200" /></a>
1920
*An R Client for Fantasy Football League APIs*
2021

2122
<!-- badges: start -->
2223

23-
[![CRAN status](https://img.shields.io/cran/v/ffscrapr?style=flat-square)](https://CRAN.R-project.org/package=ffscrapr)
24-
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg?style=flat-square)](https://www.tidyverse.org/lifecycle/#maturing)
25-
[![Codecov test coverage](https://img.shields.io/codecov/c/github/dynastyprocess/ffscrapr?label=test%20coverage&style=flat-square)](https://codecov.io/gh/DynastyProcess/ffscrapr?branch=main)
26-
[![R build status](https://img.shields.io/github/workflow/status/dynastyprocess/ffscrapr/R-CMD-check?label=R-CMD-check&style=flat-square)](https://github.com/DynastyProcess/ffscrapr/actions)
24+
[![CRAN
25+
status](https://img.shields.io/cran/v/ffscrapr?style=flat-square&logo=R&label=CRAN)](https://CRAN.R-project.org/package=ffscrapr)
26+
[![Dev status](https://img.shields.io/github/r-package/v/dynastyprocess/ffscrapr/dev?label=dev&style=flat-square&logo=github)](https://ffscrapr.dynastyprocess.com/dev/)
27+
[![Lifecycle:
28+
maturing](https://img.shields.io/badge/lifecycle-stable-green.svg?style=flat-square)](https://lifecycle.r-lib.org/articles/stages.html)
29+
[![Codecov test
30+
coverage](https://img.shields.io/codecov/c/github/dynastyprocess/ffscrapr?label=codecov&style=flat-square&logo=codecov)](https://codecov.io/gh/DynastyProcess/ffscrapr?branch=main)
31+
[![R build
32+
status](https://img.shields.io/github/workflow/status/dynastyprocess/ffscrapr/R-CMD-check?label=R%20check&style=flat-square&logo=github)](https://github.com/DynastyProcess/ffscrapr/actions)
33+
[![API
34+
status](https://img.shields.io/github/workflow/status/dynastyprocess/ffscrapr/Test%20APIs?label=API%20check&style=flat-square&logo=github)](https://github.com/DynastyProcess/ffscrapr/actions)
2735

2836
<!-- badges: end -->
2937

3038
Helps access various Fantasy Football APIs (currently MFL, Sleeper, Fleaflicker, and eventually ESPN, Yahoo, potentially others) by handling authentication/rate-limiting/caching, forming appropriate calls, and returning tidy dataframes which can be easily connected to other data sources.
3139

3240
### Installation
3341

34-
Version 1.2.1 is now on CRAN 🎉 and can be installed with:
42+
Version 1.2.2 is now on CRAN 🎉 and can be installed with:
3543

3644
```{r eval = FALSE}
3745
install.packages("ffscrapr")
38-
# or from GitHub release with the remotes package # install.packages("remotes")
39-
remotes::install_github("dynastyprocess/ffscrapr",ref = "v1.2.1")
46+
# or from GitHub release with the remotes package via:
47+
# install.packages("remotes")
48+
remotes::install_github("dynastyprocess/ffscrapr", ref = "v1.2.2")
4049
```
4150

4251
Install the development version from GitHub with:
@@ -63,10 +72,15 @@ ff_rosters(ssb)
6372
6473
# Get transactions
6574
ff_transactions(ssb)
66-
6775
```
6876

69-
For a more detailed usage example, including a template dynasty league analysis script, please check out the reference articles and/or vignettes!
77+
Platform-specific guides on getting started with ffscrapr are here:
78+
79+
- [MyFantasyLeague](https://ffscrapr.dynastyprocess.com/articles/mfl_basics.html)
80+
- [Sleeper](https://ffscrapr.dynastyprocess.com/articles/sleeper_basics.html)
81+
- [Fleaflicker](https://ffscrapr.dynastyprocess.com/articles/fleaflicker_basics.html)
82+
83+
There are also some more advanced guides for custom API calls in the [Articles section](https://ffscrapr.dynastyprocess.com/articles/), as well as some guides on [optimizing ffscrapr's performance](https://ffscrapr.dynastyprocess.com/articles/ffscrapr_caching.html).
7084

7185
### Contributing
7286

@@ -82,4 +96,8 @@ Many hands make light work! Here are some ways you can contribute to this projec
8296

8397
The R code for this package is released as open source under the [MIT license](https://ffscrapr.dynastyprocess.com/LICENSE.html).
8498

85-
The APIs and data accessed by this package belong to their respective owners, and are governed by their terms of use.
99+
The APIs and data accessed by this package belong to their respective owners, and are governed by their terms of use.
100+
101+
```{r include = FALSE}
102+
httptest::stop_mocking()
103+
```

README.md

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
<!-- badges: start -->
99

1010
[![CRAN
11-
status](https://img.shields.io/cran/v/ffscrapr?style=flat-square&logo=R&label=CRAN)](https://CRAN.R-project.org/package=ffscrapr)
12-
[![Dev status](https://img.shields.io/github/r-package/v/dynastyprocess/ffscrapr/dev?label=dev&style=flat-square&logo=github)](https://ffscrapr.dynastyprocess.com/dev)
11+
status](https://img.shields.io/cran/v/ffscrapr?style=flat-square&logo=R&label=CRAN)](https://CRAN.R-project.org/package=ffscrapr)
12+
[![Dev
13+
status](https://img.shields.io/github/r-package/v/dynastyprocess/ffscrapr/dev?label=dev&style=flat-square&logo=github)](https://ffscrapr.dynastyprocess.com/dev/)
1314
[![Lifecycle:
14-
maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg?style=flat-square)](https://www.tidyverse.org/lifecycle/#maturing)
15+
maturing](https://img.shields.io/badge/lifecycle-stable-green.svg?style=flat-square)](https://lifecycle.r-lib.org/articles/stages.html)
1516
[![Codecov test
16-
coverage](https://img.shields.io/codecov/c/github/dynastyprocess/ffscrapr?label=codecov&style=flat-square&logo=codecov)](https://codecov.io/gh/DynastyProcess/ffscrapr?branch=main)
17+
coverage](https://img.shields.io/codecov/c/github/dynastyprocess/ffscrapr?label=codecov&style=flat-square&logo=codecov)](https://codecov.io/gh/DynastyProcess/ffscrapr?branch=main)
1718
[![R build
18-
status](https://img.shields.io/github/workflow/status/dynastyprocess/ffscrapr/R-CMD-check?label=R%20check&style=flat-square&logo=github)](https://github.com/DynastyProcess/ffscrapr/actions)
19+
status](https://img.shields.io/github/workflow/status/dynastyprocess/ffscrapr/R-CMD-check?label=R%20check&style=flat-square&logo=github)](https://github.com/DynastyProcess/ffscrapr/actions)
1920
[![API
20-
status](https://img.shields.io/github/workflow/status/dynastyprocess/ffscrapr/Test%20APIs?label=API%20check&style=flat-square&logo=github)](https://github.com/DynastyProcess/ffscrapr/actions)
21+
status](https://img.shields.io/github/workflow/status/dynastyprocess/ffscrapr/Test%20APIs?label=API%20check&style=flat-square&logo=github)](https://github.com/DynastyProcess/ffscrapr/actions)
2122

2223
<!-- badges: end -->
2324

@@ -29,12 +30,13 @@ sources.
2930

3031
### Installation
3132

32-
Version 1.2.1 is now on CRAN 🎉 and can be installed with:
33+
Version 1.2.2 is now on CRAN 🎉 and can be installed with:
3334

3435
``` r
3536
install.packages("ffscrapr")
36-
# or from GitHub release with the remotes package # install.packages("remotes")
37-
remotes::install_github("dynastyprocess/ffscrapr",ref = "v1.2.1")
37+
# or from GitHub release with the remotes package via:
38+
# install.packages("remotes")
39+
remotes::install_github("dynastyprocess/ffscrapr", ref = "v1.2.2")
3840
```
3941

4042
Install the development version from GitHub with:
@@ -59,14 +61,15 @@ ssb <- ff_connect(platform = "mfl", league_id = "54040", season = 2020)
5961

6062
# Get a summary of league settings
6163
ff_league(ssb) %>% str()
64+
#> Using request.R from "ffscrapr"
6265
#> tibble [1 x 13] (S3: tbl_df/tbl/data.frame)
6366
#> $ league_id : chr "54040"
6467
#> $ league_name : chr "The Super Smash Bros Dynasty League"
6568
#> $ franchise_count: num 14
6669
#> $ qb_type : chr "1QB"
6770
#> $ idp : logi FALSE
6871
#> $ scoring_flags : chr "0.5_ppr, TEPrem, PP1D"
69-
#> $ best_ball : logi FALSE
72+
#> $ best_ball : logi TRUE
7073
#> $ salary_cap : logi FALSE
7174
#> $ player_copies : num 1
7275
#> $ years_active : chr "2018-2020"
@@ -76,48 +79,56 @@ ff_league(ssb) %>% str()
7679

7780
# Get rosters
7881
ff_rosters(ssb)
79-
#> # A tibble: 438 x 11
80-
#> franchise_id franchise_name player_id player_name pos team age
81-
#> <chr> <chr> <chr> <chr> <chr> <chr> <dbl>
82-
#> 1 0001 Team Pikachu 13189 Engram, Ev~ TE NYG 26.3
83-
#> 2 0001 Team Pikachu 11680 Landry, Ja~ WR CLE 28
84-
#> 3 0001 Team Pikachu 13645 Smith, Tre~ WR NOS 24.9
85-
#> 4 0001 Team Pikachu 12110 Brate, Cam~ TE TBB 29.5
86-
#> 5 0001 Team Pikachu 13168 Reynolds, ~ WR LAR 25.8
87-
#> # ... with 433 more rows, and 4 more variables: roster_status <chr>,
82+
#> # A tibble: 443 x 11
83+
#> franchise_id franchise_name player_id player_name pos team age
84+
#> <chr> <chr> <chr> <chr> <chr> <chr> <dbl>
85+
#> 1 0001 Team Pikachu 13189 Engram, Evan TE NYG 26.4
86+
#> 2 0001 Team Pikachu 11680 Landry, Jarvis WR CLE 28.2
87+
#> 3 0001 Team Pikachu 13645 Smith, Tre'Quan WR NOS 25.1
88+
#> 4 0001 Team Pikachu 12110 Brate, Cameron TE TBB 29.6
89+
#> 5 0001 Team Pikachu 13168 Reynolds, Josh WR LAR 26
90+
#> # ... with 438 more rows, and 4 more variables: roster_status <chr>,
8891
#> # drafted <chr>, draft_year <chr>, draft_round <chr>
8992

9093
# Get transactions
9194
ff_transactions(ssb)
92-
#> # A tibble: 1,026 x 12
93-
#> timestamp type type_desc franchise_id franchise_name player_id
94-
#> <dttm> <chr> <chr> <chr> <chr> <chr>
95-
#> 1 2020-12-15 19:56:03 FREE~ dropped 0013 Team Ness 14331
96-
#> 2 2020-12-15 19:56:03 IR activated 0013 Team Ness 13620
97-
#> 3 2020-12-11 18:40:22 IR activated 0012 Team Mewtwo 13963
98-
#> 4 2020-12-11 18:40:22 IR activated 0012 Team Mewtwo 14871
99-
#> 5 2020-12-11 18:39:43 FREE~ dropped 0012 Team Mewtwo 14793
100-
#> # ... with 1,021 more rows, and 6 more variables: player_name <chr>, pos <chr>,
101-
#> # team <chr>, bbid_spent <dbl>, trade_partner <chr>, comments <chr>
95+
#> # A tibble: 152 x 12
96+
#> timestamp type type_desc franchise_id franchise_name
97+
#> <dttm> <chr> <chr> <chr> <chr>
98+
#> 1 2020-07-09 17:25:20 FREE_AGENT dropped 0004 Team Ice Climbers
99+
#> 2 2020-07-09 17:25:20 FREE_AGENT dropped 0004 Team Ice Climbers
100+
#> 3 2020-06-16 01:56:49 TAXI promoted 0014 Team Luigi
101+
#> 4 2020-06-16 01:56:49 TAXI demoted 0014 Team Luigi
102+
#> 5 2020-06-12 23:51:44 FREE_AGENT dropped 0010 Team Yoshi
103+
#> # ... with 147 more rows, and 7 more variables: player_id <chr>,
104+
#> # player_name <chr>, pos <chr>, team <chr>, bbid_spent <dbl>,
105+
#> # trade_partner <chr>, comments <chr>
102106
```
103107

104-
For a more detailed usage example, including a template dynasty league
105-
analysis script, please check out the reference articles and/or
106-
vignettes\!
108+
Platform-specific guides on getting started with ffscrapr are here:
109+
110+
- [MyFantasyLeague](https://ffscrapr.dynastyprocess.com/articles/mfl_basics.html)
111+
- [Sleeper](https://ffscrapr.dynastyprocess.com/articles/sleeper_basics.html)
112+
- [Fleaflicker](https://ffscrapr.dynastyprocess.com/articles/fleaflicker_basics.html)
113+
114+
There are also some more advanced guides for custom API calls in the
115+
[Articles section](https://ffscrapr.dynastyprocess.com/articles/), as
116+
well as some guides on [optimizing ffscrapr’s
117+
performance](https://ffscrapr.dynastyprocess.com/articles/ffscrapr_caching.html).
107118

108119
### Contributing
109120

110-
Many hands make light work\! Here are some ways you can contribute to
121+
Many hands make light work! Here are some ways you can contribute to
111122
this project:
112123

113-
- You can [open an
124+
- You can [open an
114125
issue](https://github.com/DynastyProcess/ffscrapr/issues/new/choose)
115126
if you’d like to request specific data or report a bug/error.
116127

117-
- You can [sponsor this project with
118-
donations](https://github.com/sponsors/tanho63)\!
128+
- You can [sponsor this project with
129+
donations](https://github.com/sponsors/tanho63)!
119130

120-
- If you’d like to contribute code, please check out [the contribution
131+
- If you’d like to contribute code, please check out [the contribution
121132
guidelines](https://ffscrapr.dynastyprocess.com/CONTRIBUTING.html).
122133

123134
### Terms of Use

cran-comments.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## RESUBMISSION
2+
Fix URL redirects.
3+
4+
## Original Submission
5+
This release corrects the issues found by CRAN check so that it is robust against internet resource availibility.
6+
17
## Test environments
28
* local (Windows) R installation, R 4.0.2
39
* ubuntu 16.04 (on GitHub Actions), R 4.0.2

inst/httptest/redact.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
httptest::set_redactor(
2+
function(response){
3+
httptest::gsub_response(response,"https\\://fantasy.espn.com/apis/v3/games/ffl/","espn/") %>%
4+
httptest::gsub_response("https\\://api.myfantasyleague.com/","mfl/") %>%
5+
httptest::gsub_response("https\\://api.sleeper.app/","sleeper/") %>%
6+
httptest::gsub_response("https\\://www.fleaflicker.com/","flea/") %>%
7+
httptest::gsub_response("https\\://github.com/DynastyProcess/data/raw/master/files/","gh_dynastyprocess/")
8+
}
9+
)

inst/httptest/request.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
httptest::set_requester(
2+
function(request){
3+
httptest::gsub_request(request,"https\\://fantasy.espn.com/apis/v3/games/ffl/","espn/") %>%
4+
httptest::gsub_request("https\\://api.myfantasyleague.com/","mfl/") %>%
5+
httptest::gsub_request("https\\://api.sleeper.app/","sleeper/") %>%
6+
httptest::gsub_request("https\\://www.fleaflicker.com/","flea/") %>%
7+
httptest::gsub_request("https\\://github.com/DynastyProcess/data/raw/master/files/","gh_dynastyprocess/")
8+
}
9+
)

0 commit comments

Comments
 (0)