@@ -8,12 +8,8 @@ get_entity <- function(type, self) {
8
8
url <- glue :: glue(" {self$BASE_URL}{league}/{type}s" )
9
9
}
10
10
11
- r <- httpcache :: GET(url )
12
- httr :: stop_for_status(r )
13
- response <- r %> %
14
- httr :: content(as = " text" , encoding = " UTF-8" ) %> %
15
- jsonlite :: fromJSON() %> %
16
- dplyr :: mutate(competition = league )
11
+ response <- .execute_query(url )
12
+ response <- response %> % dplyr :: mutate(competition = league )
17
13
18
14
entity_all <- entity_all %> % dplyr :: bind_rows(response )
19
15
}
@@ -73,11 +69,7 @@ get_games <- function(self, leagues, game_ids, team_ids, team_names, seasons, st
73
69
for (league in leagues ) {
74
70
url <- glue :: glue(" {self$BASE_URL}{league}/games" )
75
71
76
- r <- httpcache :: GET(url , query = query )
77
- httr :: stop_for_status(r )
78
- response <- r %> %
79
- httr :: content(as = " text" , encoding = " UTF-8" ) %> %
80
- jsonlite :: fromJSON()
72
+ response <- .execute_query(url , query )
81
73
82
74
games <- games %> %
83
75
dplyr :: bind_rows(response ) %> %
@@ -136,3 +128,13 @@ get_games <- function(self, leagues, game_ids, team_ids, team_names, seasons, st
136
128
names <- tolower(names )
137
129
return (names )
138
130
}
131
+
132
+ .execute_query <- function (url , query = list ()) {
133
+ r <- httpcache :: GET(url , query = query )
134
+ httr :: stop_for_status(r )
135
+ response <- r %> %
136
+ httr :: content(as = " text" , encoding = " UTF-8" ) %> %
137
+ jsonlite :: fromJSON()
138
+
139
+ return (response )
140
+ }
0 commit comments