Skip to content

Commit 9b2dc07

Browse files
committed
Adapt boxscore URL
1 parent 8c73f61 commit 9b2dc07

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/main/java/fr/hippo/nbastats/infrastructure/secondary/api/ApiScoreboards.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ class ApiScoreboards {
1919
ApiScoreboard forDate(LocalDate date) {
2020
String url = "https://stats.nba.com/stats/scoreboardv3?LeagueID=00&GameDate=" + date;
2121

22-
HttpHeaders headers = new HttpHeaders();
23-
headers.set("Referer", "https://www.nba.com/");
24-
headers.set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64)");
25-
26-
HttpEntity<Void> entity = new HttpEntity<>(headers);
27-
28-
return rest.exchange(url, HttpMethod.GET, entity, ApiScoreboardWrapper.class).getBody().getScoreboard();
22+
return rest.exchange(url, HttpMethod.GET, entityWithNbaHeaders(), ApiScoreboardWrapper.class).getBody().getScoreboard();
2923
}
3024

3125
public ApiBoxscoreGame boxscoreForGame(String gameId) {
3226
String url = "https://cdn.nba.com/static/json/liveData/boxscore/boxscore_" + gameId + ".json";
3327

34-
return rest.getForObject(url, ApiBoxscore.class).getGame();
28+
return rest.exchange(url, HttpMethod.GET, entityWithNbaHeaders(), ApiBoxscore.class).getBody().getGame();
29+
}
30+
31+
private static HttpEntity<Void> entityWithNbaHeaders() {
32+
HttpHeaders headers = new HttpHeaders();
33+
headers.set("Origin", "https://www.nba.com/");
34+
headers.set("Referer", "https://www.nba.com/");
35+
headers.set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64)");
36+
37+
return new HttpEntity<>(headers);
3538
}
3639
}

0 commit comments

Comments
 (0)