Skip to content

Commit

Permalink
add player_id pull (#8)
Browse files Browse the repository at this point in the history
* v0.2.0: add player id

* redoc

* add envvars to gha script

* use bearer auth function

---------

Co-authored-by: Sebastian Carl <[email protected]>
  • Loading branch information
tanho63 and mrcaseb authored Jul 11, 2023
1 parent af189ce commit 5b1d936
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 6 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/update_otc_player_ids.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
on:
schedule:
# runs every day at 7:00 AM UTC = 3AM ET
- cron: '0 7 * * *'
workflow_dispatch:

name: update_otc

jobs:
update:
name: update data
runs-on: ubuntu-latest
timeout-minutes: 40
env:
GITHUB_PAT: ${{ secrets.NFLVERSE_GH_TOKEN }}
OTC_PLAYERID_ENDPOINT: ${{ secrets.OTC_PLAYERID_ENDPOINT }}
OTC_API_KEY: ${{ secrets.OTC_API_KEY }}
steps:
- uses: actions/checkout@v2
- uses: r-lib/actions/setup-r@v2
- uses: r-lib/actions/setup-r-dependencies@v2
with:
cache-version: 1
extra-packages: |
nflverse/nflverse-data
nflverse/nflreadr
ropensci/piggyback
local::.
any::arrow
any::qs
- name: Run otc update script
run: Rscript data-raw/release_otc_player_ids.R
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.Rdata
.httr-oauth
.DS_Store
.Renviron
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rotc
Title: Functions to Access OTC Data
Version: 0.0.0.9004
Version: 0.2.0
Authors@R:
person("Carl", "Sebastian", , "[email protected]", role = c("aut", "cre"))
Description: A set of functions to access over the cap data.
Expand All @@ -14,14 +14,16 @@ Imports:
dplyr (>= 1.0.8),
httr2 (>= 0.1.1),
janitor (>= 2.1.0),
jsonlite (>= 1.8.0),
magrittr,
purrr (>= 0.3.4),
readr (>= 2.1.2),
rlang (>= 1.0.2),
rvest (>= 1.0.2),
stringi (>= 1.7.6),
stringi (>= 1.7.6),
stringr (>= 1.4.0),
tidyr (>= 1.2.0),
xml2 (>= 1.3.3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.0
RoxygenNote: 7.2.3
4 changes: 3 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(otc_historical_contracts)
export(otc_historical_contracts_all)
export(otc_player_details)
import(dplyr)
export(otc_player_ids)
importFrom(magrittr,"%>%")
29 changes: 29 additions & 0 deletions R/otc_player_ids.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#' Retrieve player ID mappings
#'
#' @param endpoint endpoint (defaults to environment variable OTC_PLAYERID_ENDPOINT)
#' @param api_key api key (defaults to environment variable OTC_API_KEY)
#'
#' @export
otc_player_ids <- function(endpoint = Sys.getenv("OTC_PLAYERID_ENDPOINT"),
api_key = Sys.getenv("OTC_API_KEY")){
stopifnot(
length(endpoint) == 1 && nchar(endpoint) > 0,
length(api_key) == 1 && nchar(api_key) > 0
)

resp <- httr2::request(endpoint) %>%
httr2::req_auth_bearer_token(api_key) %>%
httr2::req_retry(max_tries = 3) %>%
httr2::req_perform()

player_ids <- resp %>%
httr2::resp_body_string() %>%
jsonlite::fromJSON() %>%
dplyr::mutate_all( ~replace(.x, .x %in% c("", 0), NA)) %>%
dplyr::rename(
gsis_it_id = gsis_id,
gsis_id = gsis_player_id
)

return(player_ids)
}
1 change: 0 additions & 1 deletion R/rotc-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"_PACKAGE"

## usethis namespace: start
#' @import dplyr
## usethis namespace: end
NULL
14 changes: 14 additions & 0 deletions R/utils-pipe.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
#' @param lhs A value or the magrittr placeholder.
#' @param rhs A function call using the magrittr semantics.
#' @return The result of calling `rhs(lhs)`.
NULL
9 changes: 9 additions & 0 deletions data-raw/release_otc_player_ids.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

player_ids <- rotc::otc_player_ids()

nflversedata::nflverse_save(
data_frame = player_ids,
file_name = "otc_players",
nflverse_type = "OverTheCap Player IDs",
release_tag = "players_components"
)
13 changes: 12 additions & 1 deletion man/otc_historical_contracts_all.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/otc_player_ids.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions man/pipe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions rotc.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace

UseNativePipeOperator: No

0 comments on commit 5b1d936

Please sign in to comment.