-
Notifications
You must be signed in to change notification settings - Fork 2
/
tfs_recruitment.R
50 lines (44 loc) · 1.22 KB
/
tfs_recruitment.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#' @title
#' **Get 247 Recruitment**
#' @param recruitment_id (\emph{Integer})
#' @return [tfs_recruitment()]
#' @keywords Recruiting
#' @importFrom jsonlite fromJSON
#' @importFrom httr GET
#' @importFrom utils URLencode
#' @importFrom glue glue
#' @importFrom janitor clean_names
#' @export
#' @examples
#' \donttest{
#' tfs_recruitment(recruitment_id = 130361)
#' }
#'
tfs_recruitment <- function(recruitment_id) {
base_url <- "https://247sports.com/Recruitment/"
full_url <- paste0(base_url,
recruitment_id,".json?")
# Create the GET request and set response as res
res <- httr::RETRY("GET", full_url)
# Check the result
check_status(res)
df <- data.frame()
tryCatch(
expr = {
# Get the content and return it as data.frame
df <- t(unlist(res %>%
httr::content(as = "text", encoding = "UTF-8") %>%
jsonlite::fromJSON(simplifyVector = F,flatten=TRUE))) %>%
as.data.frame() %>%
janitor::clean_names()
},
error = function(e) {
message(glue::glue("{Sys.time()}: Invalid arguments or no 247 recruiting rankings data available!"))
},
warning = function(w) {
},
finally = {
}
)
return(df)
}