Skip to content

Commit

Permalink
Adapt boxscore URL
Browse files Browse the repository at this point in the history
  • Loading branch information
hdurix committed Oct 28, 2024
1 parent 8c73f61 commit 2a0f253
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
22 changes: 22 additions & 0 deletions .run/NbaStatsApplicationServiceIntTest.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="NbaStatsApplicationServiceIntTest" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
<module name="nba-stats" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="fr.hippo.nbastats.application.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="fr.hippo.nbastats.application" />
<option name="MAIN_CLASS_NAME" value="fr.hippo.nbastats.application.NbaStatsApplicationServiceIntTest" />
<option name="METHOD_NAME" value="" />
<option name="TEST_OBJECT" value="class" />
<envs>
<env name="TELEGRAM_BOT_ID" value="869341585:AAH6glk8rmhQQD5wygeoVDDoMFytJzhq7OQ" />
<env name="TELEGRAM_CHAT_ID" value="-1001227736349" />
</envs>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ class ApiScoreboards {
ApiScoreboard forDate(LocalDate date) {
String url = "https://stats.nba.com/stats/scoreboardv3?LeagueID=00&GameDate=" + date;

HttpHeaders headers = new HttpHeaders();
headers.set("Referer", "https://www.nba.com/");
headers.set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64)");

HttpEntity<Void> entity = new HttpEntity<>(headers);

return rest.exchange(url, HttpMethod.GET, entity, ApiScoreboardWrapper.class).getBody().getScoreboard();
return rest.exchange(url, HttpMethod.GET, entityWithNbaHeaders(), ApiScoreboardWrapper.class).getBody().getScoreboard();
}

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

return rest.getForObject(url, ApiBoxscore.class).getGame();
return rest.exchange(url, HttpMethod.GET, entityWithNbaHeaders(), ApiBoxscore.class).getBody().getGame();
}

private static HttpEntity<Void> entityWithNbaHeaders() {
HttpHeaders headers = new HttpHeaders();
headers.set("Origin", "https://www.nba.com/");
headers.set("Referer", "https://www.nba.com/");
headers.set("User-Agent", "Mozilla/5.0 (X11; Linux x86_64)");

return new HttpEntity<>(headers);
}
}

0 comments on commit 2a0f253

Please sign in to comment.