Skip to content

Commit

Permalink
Add outs in the LineScore model, already supported by the linescore dto
Browse files Browse the repository at this point in the history
  • Loading branch information
brfaskow committed Apr 21, 2024
1 parent 7bb7598 commit 345f914
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/MLBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class MLBClient : IMLBClient
{
private static HttpClient _httpClient = new HttpClient();
private static readonly string _baseUrl = "https://statsapi.mlb.com/api/v1";
private static readonly short _outsInCompletedInning = 3;

private async Task<string> GetResponseAsync(string endpoint)
{
Expand Down Expand Up @@ -197,6 +198,10 @@ public async Task<IEnumerable<Linescore>> GetLineScoreAsync(int gameId)
{
CurrentInning = lineScoresJson?.currentInning,
InningHalf = lineScoresJson?.inningHalf,
// If it's the last inning, use outs from the dto. Otherwise, use the number
// of outs in an inning. In the v1 api, "outs" at the root is the current number
// of outs in the current inning; it should not be extrapolated to all innings.
Outs = inning?.num == lineScoresJson?.currentInning ? lineScoresJson?.outs : _outsInCompletedInning,
ScheduledInnings = lineScoresJson?.scheduledInnings,
HometeamRuns = lineScoresJson?.teams?.home?.runs,
HometeamHits = lineScoresJson?.teams?.home?.hits,
Expand Down
7 changes: 6 additions & 1 deletion src/Models/Linescore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ public class Linescore
public string? InningHalf { get; set; }

/// <summary>
/// The number of innings scheduled for the game..
/// The number of outs in this half of the inning.
/// </summary>
public int? Outs { get; set; }

/// <summary>
/// The number of innings scheduled for the game.
/// </summary>
public int? ScheduledInnings { get; set; }

Expand Down

0 comments on commit 345f914

Please sign in to comment.