Skip to content

Commit

Permalink
Add GetBoxscoreByGameIdAsync method and refactorings
Browse files Browse the repository at this point in the history
- Added `GetBoxscoreByGameIdAsync` method in NhlApi.cs with documentation.
- Added `GetBoxscoreByGameIdAsync` method to INhlGameApi interface.
- Implemented `GetBoxscoreByGameIdAsync` in NhlGameApi.cs.
- Added comment on manual boxscore assignment due to API changes.
  • Loading branch information
Afischbacher committed Sep 30, 2024
1 parent e9a494b commit dc14a3f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Nhl.Api/Src/Api/NhlApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,14 @@ public async Task<PlayerStatisticsFilterResult> GetPlayerStatisticsBySeasonAndFi
public async Task<GoalieStatisticsFilterResult> GetGoalieStatisticsBySeasonAndFilterExpressionAsync(string seasonYear, ExpressionGoalieFilter expressionGoalieFilter, GoalieStatisticsFilter goalieStatisticsFilterToSortBy = GoalieStatisticsFilter.Wins, int limit = -1, int offsetStart = 0, CancellationToken cancellationToken = default) =>
await _nhlStatisticsApi.GetGoalieStatisticsBySeasonAndFilterExpressionAsync(seasonYear, expressionGoalieFilter, goalieStatisticsFilterToSortBy, limit, offsetStart, cancellationToken);

/// <summary>
/// Returns the NHL game direct box score including information such as summaries, linescores, shots by period and more
/// </summary>
/// <param name="gameId">The NHL game identifier, Example: 2023020204 </param>
/// <param name="cancellationToken"> A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
/// <returns>Returns the NHL game direct box score including information such as summaries, linescores, shots by period and more</returns>
public async Task<Boxscore> GetBoxscoreByGameIdAsync(int gameId, CancellationToken cancellationToken = default) => await _nhlGameApi.GetBoxscoreByGameIdAsync(gameId, cancellationToken);

/// <summary>
/// Releases and disposes all unused or garbage collected resources for the Nhl.Api
/// </summary>
Expand Down
10 changes: 9 additions & 1 deletion Nhl.Api/Src/GameApi/INhlGameApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Nhl.Api;
namespace Nhl.Api;

/// <summary>
/// The official unofficial NHL Game API providing various NHL information game information, game schedules, live game feeds and more
Expand Down Expand Up @@ -132,4 +132,12 @@ public interface INhlGameApi
/// <param name="cancellationToken"> A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
/// <returns>Returns the NHL game meta data for the specified game id, including the teams, season states and more</returns>
public Task<GameMetadata> GetGameMetadataByGameIdAsync(int gameId, CancellationToken cancellationToken = default);

/// <summary>
/// Returns the NHL game meta data for the specified game id, including the teams, season states and more
/// </summary>
/// <param name="gameId">The NHL game identifier, Example: 2023020204 </param>
/// <param name="cancellationToken"> A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
/// <returns>Returns the NHL game meta data for the specified game id, including the teams, season states and more</returns>
public Task<Boxscore> GetBoxscoreByGameIdAsync(int gameId, CancellationToken cancellationToken = default);
}
10 changes: 10 additions & 0 deletions Nhl.Api/Src/GameApi/NhlGameApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,21 @@ public async Task<GameCenterBoxScore> GetGameCenterBoxScoreByGameIdAsync(int gam
await Task.WhenAll(gameCenterBoxScoreTask, boxScoreTask);

var gameCenterBoxScore = await gameCenterBoxScoreTask;

// We manually assign the boxscore to the object as the NHL API has moved the boxscore to a different endpoint
gameCenterBoxScore.Boxscore = await boxScoreTask;

return gameCenterBoxScore;
}

/// <summary>
/// Returns the NHL game direct box score including information such as summaries, linescores, shots by period and more
/// </summary>
/// <param name="gameId">The NHL game identifier, Example: 2023020204 </param>
/// <param name="cancellationToken"> A cancellation token that can be used by other objects or threads to receive notice of cancellation</param>
/// <returns>Returns the NHL game direct box score including information such as summaries, linescores, shots by period and more</returns>
public async Task<Boxscore> GetBoxscoreByGameIdAsync(int gameId, CancellationToken cancellationToken = default) => await _nhlApiWebHttpClient.GetAsync<Boxscore>($"/gamecenter/{gameId}/right-rail", cancellationToken);

/// <summary>
/// Returns the NHL game meta data for the specified game id, including the teams, season states and more
/// </summary>
Expand Down

0 comments on commit dc14a3f

Please sign in to comment.