Skip to content

Commit

Permalink
Cherrypick dp changes and httptest changes (#191)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tanho63 authored Feb 8, 2021
1 parent 6d51060 commit 6f87be5
Show file tree
Hide file tree
Showing 191 changed files with 4,586 additions and 575 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.2.1
Version: 1.2.2
Authors@R:
person(given = "Tan",
family = "Ho",
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# ffscrapr 1.2.2
Minor patches to dp_import functions to address issues discovered by CRAN checks.

Also adds minor helper function, `dp_cleannames`, which is a utility function for cleaning player names that removes common suffixes, preiods, and apostrophes.

### Minor patches
- Refactored `dp_values()` and `dp_playerids()` functions to use httr backend for compat with httptest, preventing CRAN errors.
- Added inst-level redactor for httptest.

# ffscrapr 1.2.1

### Minor patches
Expand Down
65 changes: 56 additions & 9 deletions R/dp_import.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
dp_values <- function(file = c("values.csv", "values-players.csv", "values-picks.csv")) {
file_name <- match.arg(file)

utils::read.csv(
glue::glue("https://github.com/DynastyProcess/data/raw/master/files/{file_name}"),
stringsAsFactors = FALSE
) %>%
dplyr::mutate(scrape_date = lubridate::as_date(.data$scrape_date)) %>%
url_query <- glue::glue("https://github.com/DynastyProcess/data/raw/master/files/{file_name}")

response <- httr::RETRY("GET", url_query, httr::accept("text/csv"))

if (httr::http_error(response)) {
stop(glue::glue("GitHub request failed with error: <{httr::status_code(response)}> \n
while calling <{url_query}>"), call. = FALSE)
}

content <- response %>%
httr::content() %>%
utils::read.csv(text = ., stringsAsFactors = FALSE) %>%
dplyr::mutate_at(dplyr::vars(dplyr::ends_with("id")), as.character) %>%
tibble::tibble()
}
Expand All @@ -44,10 +51,50 @@ dp_values <- function(file = c("values.csv", "values-players.csv", "values-picks
#'
#' @export
dp_playerids <- function() {
utils::read.csv(
glue::glue("https://github.com/DynastyProcess/data/raw/master/files/db_playerids.csv"),
stringsAsFactors = FALSE
) %>%
url_query <- "https://github.com/DynastyProcess/data/raw/master/files/db_playerids.csv"

response <- httr::RETRY("GET", url_query, httr::accept("text/csv"))

if (httr::http_error(response)) {
stop(glue::glue("GitHub request failed with error: <{httr::status_code(response)}> \n
while calling <{url_query}>"), call. = FALSE)
}

content <- response %>%
httr::content() %>%
utils::read.csv(text = ., stringsAsFactors = FALSE) %>%
dplyr::mutate_at(dplyr::vars(dplyr::ends_with("id")), as.character) %>%
tibble::tibble()

return(content)
}

#' Clean Names
#'
#' Applies some name-cleaning heuristics to facilitate joins.
#' May eventually refer to a name-cleaning database, for now will just include basic regex.
#'
#' @param player_name a character (or character vector)
#' @param lowercase defaults to FALSE - if TRUE, converts to lowercase
#'
#' @examples
#' \donttest{
#' dp_cleannames(c("A.J. Green", "Odell Beckham Jr.", "Le'Veon Bell Sr."))
#' }
#'
#' @return a character vector of cleaned names
#'
#' @export

dp_cleannames <- function(player_name, lowercase = FALSE) {
checkmate::assert_logical(lowercase)
checkmate::assert_character(player_name)

n <- stringr::str_remove_all(player_name, "( Jr\\.$)|( Sr\\.$)|( III$)|( II$)|( IV$)|( V$)|(\\')|(\\.)")

if (lowercase) n <- tolower(n)

n <- stringr::str_squish(n)

return(n)
}
42 changes: 30 additions & 12 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,40 @@ knitr::opts_chunk$set(
out.width = "100%"
)
options(tibble.print_min = 5)
options(tibble.print_min = 5, pillar.bold = TRUE, pillar.min_chars = 25, pillar.min_title_chars = 25)
httptest::.mockPaths("tests/testthat")
httptest::use_mock_api()
```
# ffscrapr <a href='#'><img src='man/figures/logo.png' align="right" height="200" /></a>
*An R Client for Fantasy Football League APIs*

<!-- badges: start -->

[![CRAN status](https://img.shields.io/cran/v/ffscrapr?style=flat-square)](https://CRAN.R-project.org/package=ffscrapr)
[![Lifecycle: maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg?style=flat-square)](https://www.tidyverse.org/lifecycle/#maturing)
[![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)
[![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)
[![CRAN
status](https://img.shields.io/cran/v/ffscrapr?style=flat-square&logo=R&label=CRAN)](https://CRAN.R-project.org/package=ffscrapr)
[![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/)
[![Lifecycle:
maturing](https://img.shields.io/badge/lifecycle-stable-green.svg?style=flat-square)](https://lifecycle.r-lib.org/articles/stages.html)
[![Codecov test
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)
[![R build
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)
[![API
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)

<!-- badges: end -->

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.

### Installation

Version 1.2.1 is now on CRAN 🎉 and can be installed with:
Version 1.2.2 is now on CRAN 🎉 and can be installed with:

```{r eval = FALSE}
install.packages("ffscrapr")
# or from GitHub release with the remotes package # install.packages("remotes")
remotes::install_github("dynastyprocess/ffscrapr",ref = "v1.2.1")
# or from GitHub release with the remotes package via:
# install.packages("remotes")
remotes::install_github("dynastyprocess/ffscrapr", ref = "v1.2.2")
```

Install the development version from GitHub with:
Expand All @@ -63,10 +72,15 @@ ff_rosters(ssb)
# Get transactions
ff_transactions(ssb)
```

For a more detailed usage example, including a template dynasty league analysis script, please check out the reference articles and/or vignettes!
Platform-specific guides on getting started with ffscrapr are here:

- [MyFantasyLeague](https://ffscrapr.dynastyprocess.com/articles/mfl_basics.html)
- [Sleeper](https://ffscrapr.dynastyprocess.com/articles/sleeper_basics.html)
- [Fleaflicker](https://ffscrapr.dynastyprocess.com/articles/fleaflicker_basics.html)

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).

### Contributing

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

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

The APIs and data accessed by this package belong to their respective owners, and are governed by their terms of use.
The APIs and data accessed by this package belong to their respective owners, and are governed by their terms of use.

```{r include = FALSE}
httptest::stop_mocking()
```
85 changes: 48 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
<!-- badges: start -->

[![CRAN
status](https://img.shields.io/cran/v/ffscrapr?style=flat-square&logo=R&label=CRAN)](https://CRAN.R-project.org/package=ffscrapr)
[![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)
status](https://img.shields.io/cran/v/ffscrapr?style=flat-square&logo=R&label=CRAN)](https://CRAN.R-project.org/package=ffscrapr)
[![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/)
[![Lifecycle:
maturing](https://img.shields.io/badge/lifecycle-maturing-blue.svg?style=flat-square)](https://www.tidyverse.org/lifecycle/#maturing)
maturing](https://img.shields.io/badge/lifecycle-stable-green.svg?style=flat-square)](https://lifecycle.r-lib.org/articles/stages.html)
[![Codecov test
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)
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)
[![R build
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)
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)
[![API
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)
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)

<!-- badges: end -->

Expand All @@ -29,12 +30,13 @@ sources.

### Installation

Version 1.2.1 is now on CRAN 🎉 and can be installed with:
Version 1.2.2 is now on CRAN 🎉 and can be installed with:

``` r
install.packages("ffscrapr")
# or from GitHub release with the remotes package # install.packages("remotes")
remotes::install_github("dynastyprocess/ffscrapr",ref = "v1.2.1")
# or from GitHub release with the remotes package via:
# install.packages("remotes")
remotes::install_github("dynastyprocess/ffscrapr", ref = "v1.2.2")
```

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

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

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

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

For a more detailed usage example, including a template dynasty league
analysis script, please check out the reference articles and/or
vignettes\!
Platform-specific guides on getting started with ffscrapr are here:

- [MyFantasyLeague](https://ffscrapr.dynastyprocess.com/articles/mfl_basics.html)
- [Sleeper](https://ffscrapr.dynastyprocess.com/articles/sleeper_basics.html)
- [Fleaflicker](https://ffscrapr.dynastyprocess.com/articles/fleaflicker_basics.html)

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).

### Contributing

Many hands make light work\! Here are some ways you can contribute to
Many hands make light work! Here are some ways you can contribute to
this project:

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

- You can [sponsor this project with
donations](https://github.com/sponsors/tanho63)\!
- You can [sponsor this project with
donations](https://github.com/sponsors/tanho63)!

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

### Terms of Use
Expand Down
6 changes: 6 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## RESUBMISSION
Fix URL redirects.

## Original Submission
This release corrects the issues found by CRAN check so that it is robust against internet resource availibility.

## Test environments
* local (Windows) R installation, R 4.0.2
* ubuntu 16.04 (on GitHub Actions), R 4.0.2
Expand Down
9 changes: 9 additions & 0 deletions inst/httptest/redact.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
httptest::set_redactor(
function(response){
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/") %>%
httptest::gsub_response("https\\://github.com/DynastyProcess/data/raw/master/files/","gh_dynastyprocess/")
}
)
9 changes: 9 additions & 0 deletions inst/httptest/request.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
httptest::set_requester(
function(request){
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/") %>%
httptest::gsub_request("https\\://github.com/DynastyProcess/data/raw/master/files/","gh_dynastyprocess/")
}
)
Loading

0 comments on commit 6f87be5

Please sign in to comment.