Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add season param to fotmob_get_league_[matches|tables] #256

Merged
merged 9 commits into from
Feb 12, 2023

Conversation

tonyelhabr
Copy link
Collaborator

@tonyelhabr tonyelhabr commented Feb 12, 2023

Fixes #250. (fotmob_get_league_tables() has a similar backend to fotmob_get_league_matches(), so I addressed it at the same time.)

@codecov-commenter
Copy link

codecov-commenter commented Feb 12, 2023

Codecov Report

Merging #256 (5c0ba5f) into main (11eac0c) will increase coverage by 0.18%.
The diff coverage is 93.75%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main     #256      +/-   ##
==========================================
+ Coverage   67.31%   67.49%   +0.18%     
==========================================
  Files          49       49              
  Lines        4081     4113      +32     
==========================================
+ Hits         2747     2776      +29     
- Misses       1334     1337       +3     
Impacted Files Coverage Δ
R/fotmob_leagues.R 88.48% <93.75%> (+0.43%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment on lines +158 to +163
url <- httr::parse_url("https://www.fotmob.com/api/leagues")
url$query <- list(
"id" = league_id,
"season" = season
)
url <- httr::build_url(url)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

building the URL like this is advantageous since we may not have a value for season. build_url() knows to ignore a NULL

Comment on lines +251 to +252
# Need to coerce to `NA_character` since crossing doesn't like `NULL`
season <- ifelse(is.null(season), NA_character_, season)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i much prefer to use NULL for the absence of an optional argument, but because crossing() will drop NULLs, i temporarily change NULL to NA_character_

resp <- .fotmob_get_league_resp(league_id, page_url)
.fotmob_get_league_matches <- function(league_id, page_url, season = NULL) {
# And now coerce NA back to NULL
season <- switch(!is.na(season), season, NULL)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have to use switch() instead of if or ifelse() since those suck with handling NULLs

@JaseZiv
Copy link
Owner

JaseZiv commented Feb 12, 2023

Really nice - I'm getting a few learnings out of this PR which is an added bonus!

Thanks for this update.

@JaseZiv JaseZiv merged commit 79c2650 into main Feb 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fotmob_get_league_matches for previous seasons
3 participants