Skip to content

Commit

Permalink
Merge pull request #15 from AdrianJSClark/2-league-get
Browse files Browse the repository at this point in the history
Implement "league/get" Endpoint
  • Loading branch information
AdrianJSClark authored Mar 5, 2022
2 parents 8060cff + a4bb33b commit 3325162
Show file tree
Hide file tree
Showing 33 changed files with 501 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,36 @@ public async Task GetMemberRecentRacesSucceedsAsync()
Assert.That(memberStats.TotalRateLimit, Is.EqualTo(100));
Assert.That(memberStats.RateLimitReset, Is.EqualTo(new DateTimeOffset(2022, 2, 10, 0, 0, 0, TimeSpan.Zero)));
}

[Test(TestOf = typeof(iRacingDataClient))]
public async Task GetLeagueWithLicensesSucceedsAsync()
{
await MessageHandler.QueueResponsesAsync(nameof(GetLeagueWithLicensesSucceedsAsync)).ConfigureAwait(false);
await sut.LoginAsync("[email protected]", "SuperSecretPassword", CancellationToken.None).ConfigureAwait(false);

var memberStats = await sut.GetLeagueAsync(123, true).ConfigureAwait(false);

Assert.That(memberStats, Is.Not.Null);
Assert.That(memberStats!.Data, Is.Not.Null);

Assert.That(memberStats.RateLimitRemaining, Is.EqualTo(99));
Assert.That(memberStats.TotalRateLimit, Is.EqualTo(100));
Assert.That(memberStats.RateLimitReset, Is.EqualTo(new DateTimeOffset(2022, 2, 10, 0, 0, 0, TimeSpan.Zero)));
}

[Test(TestOf = typeof(iRacingDataClient))]
public async Task GetLeagueWithoutLicensesSucceedsAsync()
{
await MessageHandler.QueueResponsesAsync(nameof(GetLeagueWithoutLicensesSucceedsAsync)).ConfigureAwait(false);
await sut.LoginAsync("[email protected]", "SuperSecretPassword", CancellationToken.None).ConfigureAwait(false);

var memberStats = await sut.GetLeagueAsync(123, false).ConfigureAwait(false);

Assert.That(memberStats, Is.Not.Null);
Assert.That(memberStats!.Data, Is.Not.Null);

Assert.That(memberStats.RateLimitRemaining, Is.EqualTo(99));
Assert.That(memberStats.TotalRateLimit, Is.EqualTo(100));
Assert.That(memberStats.RateLimitReset, Is.EqualTo(new DateTimeOffset(2022, 2, 10, 0, 0, 0, TimeSpan.Zero)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"headers": {},
"content": {
"authcode": "51687dfd-1d8e-4faa-bf72-52cb36e4f762",
"autoLoginSeries": null,
"autoLoginToken": null,
"custId": 123456,
"email": "[email protected]",
"ssoCookieDomain": ".iracing.com",
"ssoCookieName": "irsso_membersv2",
"ssoCookiePath": "/",
"ssoCookieValue": "3883fc6a-890c-4c75-981c-84f2f9ebfb41"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"headers": {
"x-ratelimit-remaining": "99",
"x-ratelimit-limit": "100",
"x-ratelimit-reset": "1644451200"
},
"content": {
"link": "https://scorpio-assets.s3.amazonaws.com/production/data-server/cache/data-services/league/get/e0a56003-c609-4a0e-a1d2-8fc4dcab92a6?AWSAccessKeyId=AKIAUO6OO4A3357USLO7&Expires=1642767750&Signature=XpwNF2L921Ry%2Frr%2FbATcfi2TyHY%3D"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"headers": {},
"content": {
"league_id": 8234,
"owner_id": 341554,
"league_name": "Adrian's Test League",
"created": "2022-03-05T12:43:53Z",
"hidden": false,
"message": "https://iracing.adrianclark.dev",
"about": "Adrian's league for testing things.",
"url": "https://iracing.adrianclark.dev",
"recruiting": false,
"private_wall": false,
"private_roster": false,
"private_schedule": false,
"private_results": false,
"roster_count": 1,
"owner": {
"cust_id": 341554,
"display_name": "Adrian Clark",
"helmet": {
"pattern": 50,
"color1": "981F24",
"color2": "000000",
"color3": "ED2129",
"face_type": 0,
"helmet_type": 0
},
"car_number": null,
"nick_name": null
},
"image": {
"small_logo": null,
"large_logo": null
},
"tags": {
"categorized": [
{
"category_id": 1,
"name": "Culture",
"limit": 1,
"tags": [
{
"tag_id": 5,
"tag_name": "Professional"
}
]
},
{
"category_id": 2,
"name": "Type of Racing",
"limit": null,
"tags": [
{
"tag_id": 8,
"tag_name": "Road"
},
{
"tag_id": 10,
"tag_name": "Grand-Prix"
}
]
},
{
"category_id": 3,
"name": "Car Setup",
"limit": null,
"tags": [
{
"tag_id": 12,
"tag_name": "Open-Setup"
}
]
}
],
"not_categorized": []
},
"roster": [
{
"cust_id": 341554,
"display_name": "Adrian Clark",
"helmet": {
"pattern": 50,
"color1": "981F24",
"color2": "000000",
"color3": "ED2129",
"face_type": 0,
"helmet_type": 0
},
"owner": true,
"admin": true,
"league_mail_opt_out": false,
"league_pm_opt_out": false,
"league_member_since": "2022-03-05T12:43:53Z",
"car_number": null,
"nick_name": null
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"headers": {},
"content": {
"authcode": "51687dfd-1d8e-4faa-bf72-52cb36e4f762",
"autoLoginSeries": null,
"autoLoginToken": null,
"custId": 123456,
"email": "[email protected]",
"ssoCookieDomain": ".iracing.com",
"ssoCookieName": "irsso_membersv2",
"ssoCookiePath": "/",
"ssoCookieValue": "3883fc6a-890c-4c75-981c-84f2f9ebfb41"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"headers": {
"x-ratelimit-remaining": "99",
"x-ratelimit-limit": "100",
"x-ratelimit-reset": "1644451200"
},
"content": {
"link": "https://scorpio-assets.s3.amazonaws.com/production/data-server/cache/data-services/stats/member_recent_races/e0a56003-c609-4a0e-a1d2-8fc4dcab92a6?AWSAccessKeyId=AKIAUO6OO4A3357USLO7&Expires=1642767750&Signature=XpwNF2L921Ry%2Frr%2FbATcfi2TyHY%3D"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"headers": {},
"content": {
"league_id": 8234,
"owner_id": 341554,
"league_name": "Adrian's Test League",
"created": "2022-03-05T12:43:53Z",
"hidden": false,
"message": "https://iracing.adrianclark.dev",
"about": "Adrian's league for testing things.",
"url": "https://iracing.adrianclark.dev",
"recruiting": false,
"private_wall": false,
"private_roster": false,
"private_schedule": false,
"private_results": false,
"roster_count": 1,
"owner": {
"cust_id": 341554,
"display_name": "Adrian Clark",
"helmet": {
"pattern": 50,
"color1": "981F24",
"color2": "000000",
"color3": "ED2129",
"face_type": 0,
"helmet_type": 0
},
"car_number": null,
"nick_name": null
},
"image": {
"small_logo": null,
"large_logo": null
},
"tags": {
"categorized": [
{
"category_id": 1,
"name": "Culture",
"limit": 1,
"tags": [
{
"tag_id": 5,
"tag_name": "Professional"
}
]
},
{
"category_id": 2,
"name": "Type of Racing",
"limit": null,
"tags": [
{
"tag_id": 8,
"tag_name": "Road"
},
{
"tag_id": 10,
"tag_name": "Grand-Prix"
}
]
},
{
"category_id": 3,
"name": "Car Setup",
"limit": null,
"tags": [
{
"tag_id": 12,
"tag_name": "Open-Setup"
}
]
}
],
"not_categorized": []
},
"roster": [
{
"cust_id": 341554,
"display_name": "Adrian Clark",
"helmet": {
"pattern": 50,
"color1": "981F24",
"color2": "000000",
"color3": "ED2129",
"face_type": 0,
"helmet_type": 0
},
"owner": true,
"admin": true,
"league_mail_opt_out": false,
"league_pm_opt_out": false,
"league_member_since": "2022-03-05T12:43:53Z",
"car_number": null,
"nick_name": null
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

using System.Text.Json.Serialization;

namespace Aydsko.iRacingData.Stats;
namespace Aydsko.iRacingData.Common;

public class WinnerHelmet
public class Helmet
{
[JsonPropertyName("pattern")]
public int Pattern { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text.Json.Serialization;

namespace Aydsko.iRacingData.Member;
namespace Aydsko.iRacingData.Common;

public class Suit
{
Expand All @@ -16,5 +16,5 @@ public class Suit
[JsonPropertyName("color3")]
public string Color3 { get; set; } = default!;
[JsonPropertyName("body_type")]
public int BodyType { get; set; }
public int? BodyType { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text.Json.Serialization;

namespace Aydsko.iRacingData.Series;
namespace Aydsko.iRacingData.Common;

public class Track
{
Expand Down
1 change: 1 addition & 0 deletions src/Aydsko.iRacingData/Converters/DateTimeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public override DateTime Read(ref Utf8JsonReader reader,
return dateValue;
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "Check is being done, diagnostic requires an update.")]
public override void Write(Utf8JsonWriter writer!!,
DateTime value,
JsonSerializerOptions options)
Expand Down
11 changes: 0 additions & 11 deletions src/Aydsko.iRacingData/GlobalSuppressions.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Aydsko.iRacingData/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// This file is licensed to you under the MIT license.

global using Microsoft.Extensions.Logging;
global using Aydsko.iRacingData.Common;
23 changes: 22 additions & 1 deletion src/Aydsko.iRacingData/IRacingDataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Aydsko.iRacingData.CarClasses;
using Aydsko.iRacingData.Cars;
using Aydsko.iRacingData.Leagues;
using Aydsko.iRacingData.Lookups;
using Aydsko.iRacingData.Member;
using Aydsko.iRacingData.Results;
Expand Down Expand Up @@ -104,7 +105,27 @@ public async Task<DataResponse<CarClass[]>> GetCarClassesAsync(CancellationToken
return await CreateResponseViaInfoLinkAsync(carClassUrl, CarClassArrayContext.Default.CarClassArray, cancellationToken).ConfigureAwait(false);
}

// TODO - public async Task<DataResponse<League>> GetLeagueAsync(int leagueId, bool includeLicenses = false, CancellationToken cancellationToken = default)
/// <summary>Get information about a league.</summary>
/// <param name="leagueId">The unique identifier for the league.</param>
/// <param name="includeLicenses">Indicates if license information should be included. Either <see langword="true"/> or <see langword="false"/> to exclude for performance purposes.</param>
/// <param name="cancellationToken">A token to allow the operation to be cancelled.</param>
/// <returns>A <see cref="DataResponse{TData}"/> containing the season & optionally series detail in a <see cref="Tracks.Track"/> array.</returns>
/// <exception cref="InvalidOperationException">If the client is not currently authenticated.</exception>
/// <exception cref="iRacingDataClientException">If there's a problem processing the result.</exception>
public async Task<DataResponse<League>> GetLeagueAsync(int leagueId, bool includeLicenses = false, CancellationToken cancellationToken = default)
{
if (!IsLoggedIn)
{
throw new InvalidOperationException("Must be logged in before requesting data.");
}

var getTrackUrl = QueryHelpers.AddQueryString("https://members-ng.iracing.com/data/league/get", new Dictionary<string, string>
{
{ "league_id", leagueId.ToString(CultureInfo.InvariantCulture) },
{ "include_licenses", includeLicenses.ToString() }
});
return await CreateResponseViaInfoLinkAsync(new Uri(getTrackUrl), LeagueContext.Default.League, cancellationToken).ConfigureAwait(false);
}

/// <summary>Information about reference data defined by the system.</summary>
/// <param name="cancellationToken">A token to allow the operation to be cancelled.</param>
Expand Down
Loading

0 comments on commit 3325162

Please sign in to comment.