Skip to content

Commit

Permalink
Refactor PatreonIncludeDataJsonConverter to throw AggregateException …
Browse files Browse the repository at this point in the history
…on IterativeParse

Added new models
  • Loading branch information
illja96 committed May 5, 2024
1 parent d22e8a2 commit eb537dd
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
20 changes: 12 additions & 8 deletions IVAXOR.PatreonNET/Converters/PatreonIncludeDataJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ protected object IterativeParse(JsonElement attributeJsonElement, IEnumerable<Ty
{
if (attributeTypes.Count() == 1) return attributeJsonElement.Deserialize(attributeTypes.Single(), options);

var attributeType = attributeTypes.First();
try
var exceptions = new List<JsonException>();
foreach (var attributeType in attributeTypes)
{
return attributeJsonElement.Deserialize(attributeType, options);
}
catch (JsonException)
{
attributeTypes = attributeTypes.Where(_ => _ != attributeType);
return IterativeParse(attributeJsonElement, attributeTypes, options);
try
{
return attributeJsonElement.Deserialize(attributeType, options);
}
catch (JsonException exception)
{
exceptions.Add(exception);
}
}

throw new AggregateException(exceptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public class PatreonCampaignV1Attributes : IPatreonAttributes
[JsonPropertyName("is_monthly")]
public bool? IsMonthly { get; set; }

[JsonPropertyName("is_new_fandom")]
public bool? IsNewFandom { get; set; }

/// <summary>
/// true if the creator has marked the campaign as containing nsfw content.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace IVAXOR.PatreonNET.Models.Resources.PostsV1;

public class PatreonPostV1AverageColorsOfCorners
{
[JsonPropertyName("bottom_left")]
public string? BottomLeft { get; set; }

[JsonPropertyName("bottom_right")]
public string? BottomRight { get; set; }

[JsonPropertyName("top_left")]
public string? TopLeft { get; set; }

[JsonPropertyName("top_right")]
public string? TopRight { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public class PatreonPostV1File
[JsonPropertyName("height")]
public int? Height { get; set; }

[JsonPropertyName("image_colors")]
public PatreonPostV1ImageColors? ImageColors { get; set; }

[JsonPropertyName("media_id")]
public int? MediaId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Text.Json.Serialization;

namespace IVAXOR.PatreonNET.Models.Resources.PostsV1;

public class PatreonPostV1ImageColors
{
[JsonPropertyName("average_colors_of_corners")]
public PatreonPostV1AverageColorsOfCorners? AverageColorsOfCorners { get; set; }

[JsonPropertyName("dominant_color")]
public string? DominantColor { get; set; }

[JsonPropertyName("palette")]
public string[]? Palette { get; set; }

[JsonPropertyName("text_color")]
public string? TextColor { get; set; }
}

0 comments on commit eb537dd

Please sign in to comment.