This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from BlossomiShymae/issue-21-meraki-interface
Add Meraki support
- Loading branch information
Showing
31 changed files
with
938 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using BlossomiShymae.RiotBlossom.Dto.MerakiAnalytics.Champion; | ||
using BlossomiShymae.RiotBlossom.Dto.MerakiAnalytics.Item; | ||
using BlossomiShymae.RiotBlossom.Http; | ||
using System.Collections.Immutable; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Api | ||
{ | ||
public interface IMerakiAnalyticsApi | ||
{ | ||
/// <summary> | ||
/// Get a League champion by their string key e.g. "MonkeyKing", "Kogmaw", "AurelionSol". | ||
/// </summary> | ||
/// <param name="key"></param> | ||
/// <returns></returns> | ||
Task<Champion> GetChampionByKeyAsync(string key); | ||
/// <summary> | ||
/// Get a dictionary of League champions by string key pairs e.g. "MonkeyKing", "Kogmaw", "AurelionSol". | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<ImmutableDictionary<string, Champion>> GetChampionDictionaryAsync(); | ||
/// <summary> | ||
/// Get a League shop item by ID. | ||
/// </summary> | ||
/// <param name="id"></param> | ||
/// <returns></returns> | ||
Task<Item> GetItemByIdAsync(int id); | ||
/// <summary> | ||
/// Get a dictionary of League shop items by ID pairs. | ||
/// </summary> | ||
/// <returns></returns> | ||
Task<ImmutableDictionary<int, Item>> GetItemDictionaryAsync(); | ||
} | ||
|
||
internal class MerakiAnalyticsApi : IMerakiAnalyticsApi | ||
{ | ||
private static readonly string s_itemByIdUri = "/items/{0}.json"; | ||
private static readonly string s_championByKeyUri = "/champions/{0}.json"; | ||
private static readonly string s_itemsDictionaryUri = "/items.json"; | ||
private static readonly string s_championsDictionaryUri = "/champions.json"; | ||
private readonly ComposableApi<Dictionary<int, Item>> _itemDictionaryApi; | ||
private readonly ComposableApi<Dictionary<string, Champion>> _championDictionaryApi; | ||
private readonly ComposableApi<Item> _itemApi; | ||
private readonly ComposableApi<Champion> _championApi; | ||
|
||
public MerakiAnalyticsApi(MerakiAnalyticsHttpClient merakiAnalyticsHttpClient) | ||
{ | ||
_itemDictionaryApi = new(merakiAnalyticsHttpClient); | ||
_championDictionaryApi = new(merakiAnalyticsHttpClient); | ||
_itemApi = new(merakiAnalyticsHttpClient); | ||
_championApi = new(merakiAnalyticsHttpClient); | ||
} | ||
|
||
public async Task<Champion> GetChampionByKeyAsync(string key) | ||
=> await _championApi.GetValueAsync(string.Format(s_championByKeyUri, key)); | ||
|
||
public async Task<ImmutableDictionary<string, Champion>> GetChampionDictionaryAsync() | ||
{ | ||
Dictionary<string, Champion> champions = await _championDictionaryApi.GetValueAsync(s_championsDictionaryUri); | ||
return champions.ToImmutableDictionary(); | ||
} | ||
|
||
public async Task<Item> GetItemByIdAsync(int id) | ||
=> await _itemApi.GetValueAsync(string.Format(s_itemByIdUri, id)); | ||
|
||
public async Task<ImmutableDictionary<int, Item>> GetItemDictionaryAsync() | ||
{ | ||
Dictionary<int, Item> items = await _itemDictionaryApi.GetValueAsync(s_itemsDictionaryUri); | ||
return items.ToImmutableDictionary(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Core | ||
{ | ||
internal class DoubleJsonConverter : JsonConverter<double> | ||
{ | ||
public override double Read(ref Utf8JsonReader reader, System.Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
double value = 0; | ||
try | ||
{ | ||
value = reader.GetDouble(); | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
value = double.Parse(reader.GetString() ?? throw new InvalidOperationException("Could not get value as a double.")); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, double value, JsonSerializerOptions options) | ||
=> writer.WriteNumberValue(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Core | ||
{ | ||
internal class StringJsonConverter : JsonConverter<string> | ||
{ | ||
public override string? Read(ref Utf8JsonReader reader, System.Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
string? value; | ||
try | ||
{ | ||
value = reader.GetString(); | ||
} | ||
catch (InvalidOperationException) | ||
{ | ||
value = $"{reader.GetInt32()}"; | ||
} | ||
|
||
return value; | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) | ||
=> writer.WriteStringValue(value); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
BlossomiShymae.RiotBlossom/Dto/MerakiAnalytics/Champion/Ability.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using BlossomiShymae.RiotBlossom.Core; | ||
using System.Collections.Immutable; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Dto.MerakiAnalytics.Champion | ||
{ | ||
/// <summary> | ||
/// UNDOCUMENTED | ||
/// </summary> | ||
public record Ability | ||
{ | ||
public string? Name { get; init; } | ||
public string? Icon { get; init; } | ||
public ImmutableList<Effect> Effects { get; init; } = ImmutableList<Effect>.Empty; | ||
public Cost Cost { get; init; } = new(); | ||
public Cooldown Cooldown { get; init; } = new(); | ||
public string? Targeting { get; init; } | ||
public string? Affects { get; init; } | ||
public string? Spellshieldable { get; init; } | ||
public string? Resource { get; init; } | ||
public string? DamageType { get; init; } | ||
public string? SpellEffects { get; init; } | ||
public string? Projectile { get; init; } | ||
public string? OnHitEffects { get; init; } | ||
public string? Occurrence { get; init; } | ||
public string? Notes { get; init; } | ||
public string? Blurb { get; init; } | ||
public string? MissileSpeed { get; init; } | ||
public ImmutableList<double> RechargeRate { get; init; } = ImmutableList<double>.Empty; | ||
public string? CollisionRadius { get; init; } | ||
public string? TetherRadius { get; init; } | ||
public string? OnTargetCdStatic { get; init; } | ||
public string? InnerRadius { get; init; } | ||
public string? Speed { get; init; } | ||
public string? Width { get; init; } | ||
public string? Angle { get; init; } | ||
public string? CastTime { get; init; } | ||
public string? EffectRadius { get; init; } | ||
public string? TargetRange { get; init; } | ||
|
||
public override string ToString() | ||
{ | ||
return PrettyPrinter.GetString(this); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
BlossomiShymae.RiotBlossom/Dto/MerakiAnalytics/Champion/AttributeRatings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using BlossomiShymae.RiotBlossom.Core; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Dto.MerakiAnalytics.Champion | ||
{ | ||
/// <summary> | ||
/// UNDOCUMENTED | ||
/// </summary> | ||
public record AttributeRatings | ||
{ | ||
public int Damage { get; init; } | ||
public int Toughness { get; init; } | ||
public int Control { get; init; } | ||
public int Mobility { get; init; } | ||
public int Utility { get; init; } | ||
public int AbilityReliance { get; init; } | ||
public int Attack { get; init; } | ||
public int Defense { get; init; } | ||
public int Magic { get; init; } | ||
public int Difficulty { get; init; } | ||
|
||
public override string ToString() | ||
{ | ||
return PrettyPrinter.GetString(this); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
BlossomiShymae.RiotBlossom/Dto/MerakiAnalytics/Champion/Champion.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using BlossomiShymae.RiotBlossom.Core; | ||
using System.Collections.Immutable; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Dto.MerakiAnalytics.Champion | ||
{ | ||
/// <summary> | ||
/// UNDOCUMENTED | ||
/// </summary> | ||
public record Champion | ||
{ | ||
public int Id { get; init; } | ||
public string? Key { get; init; } | ||
public string? Name { get; init; } | ||
public string? Title { get; init; } | ||
public string? FullName { get; init; } | ||
public string? Icon { get; init; } | ||
public string? Resource { get; init; } | ||
public string? AttackType { get; init; } | ||
public string? DamageType { get; init; } | ||
public Stats Stats { get; init; } = new(); | ||
public ImmutableList<string> Roles { get; init; } = ImmutableList<string>.Empty; | ||
public AttributeRatings AttributeRatings { get; init; } = new(); | ||
public ImmutableDictionary<string, ImmutableList<Ability>> Abilities { get; init; } = ImmutableDictionary<string, ImmutableList<Ability>>.Empty; | ||
public string? ReleaseDate { get; init; } | ||
public string? ReleasePatch { get; init; } | ||
public string? PatchLastChanged { get; init; } | ||
public Price Price { get; init; } = new(); | ||
public string? Lore { get; init; } | ||
public string? Faction { get; init; } | ||
public ImmutableList<Skin> Skins { get; init; } = ImmutableList<Skin>.Empty; | ||
|
||
public override string ToString() | ||
{ | ||
return PrettyPrinter.GetString(this); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
BlossomiShymae.RiotBlossom/Dto/MerakiAnalytics/Champion/Chroma.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using BlossomiShymae.RiotBlossom.Core; | ||
using System.Collections.Immutable; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Dto.MerakiAnalytics.Champion | ||
{ | ||
/// <summary> | ||
/// UNDOCUMENTED | ||
/// </summary> | ||
public record Chroma | ||
{ | ||
public string? Name { get; init; } | ||
public long Id { get; init; } | ||
public string? ChromaPath { get; init; } | ||
public ImmutableList<string> Colors { get; init; } = ImmutableList<string>.Empty; | ||
public ImmutableList<DescriptionDto> Descriptions { get; init; } = ImmutableList<DescriptionDto>.Empty; | ||
public ImmutableList<Rarities> Rarities { get; init; } = ImmutableList<Rarities>.Empty; | ||
|
||
public override string ToString() | ||
{ | ||
return PrettyPrinter.GetString(this); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
BlossomiShymae.RiotBlossom/Dto/MerakiAnalytics/Champion/Cooldown.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using BlossomiShymae.RiotBlossom.Core; | ||
using System.Collections.Immutable; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Dto.MerakiAnalytics.Champion | ||
{ | ||
/// <summary> | ||
/// UNDOCUMENTED | ||
/// </summary> | ||
public record Cooldown | ||
{ | ||
public ImmutableList<Modifier> Modifiers { get; init; } = ImmutableList<Modifier>.Empty; | ||
public bool AffectedByCdr { get; init; } | ||
|
||
public override string ToString() | ||
{ | ||
return PrettyPrinter.GetString(this); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
BlossomiShymae.RiotBlossom/Dto/MerakiAnalytics/Champion/Cost.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using BlossomiShymae.RiotBlossom.Core; | ||
using System.Collections.Immutable; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Dto.MerakiAnalytics.Champion | ||
{ | ||
/// <summary> | ||
/// UNDOCUMENTED | ||
/// </summary> | ||
public record Cost | ||
{ | ||
public ImmutableList<Modifier> Modifiers { get; init; } = ImmutableList<Modifier>.Empty; | ||
|
||
public override string ToString() | ||
{ | ||
return PrettyPrinter.GetString(this); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
BlossomiShymae.RiotBlossom/Dto/MerakiAnalytics/Champion/DescriptionDto.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using BlossomiShymae.RiotBlossom.Core; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Dto.MerakiAnalytics.Champion | ||
{ | ||
/// <summary> | ||
/// UNDOCUMENTED | ||
/// </summary> | ||
public record DescriptionDto | ||
{ | ||
public string? Description { get; init; } | ||
public string? Region { get; init; } | ||
|
||
public override string ToString() | ||
{ | ||
return PrettyPrinter.GetString(this); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
BlossomiShymae.RiotBlossom/Dto/MerakiAnalytics/Champion/Effect.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using BlossomiShymae.RiotBlossom.Core; | ||
using System.Collections.Immutable; | ||
|
||
namespace BlossomiShymae.RiotBlossom.Dto.MerakiAnalytics.Champion | ||
{ | ||
/// <summary> | ||
/// UNDOCUMENTED | ||
/// </summary> | ||
public record Effect | ||
{ | ||
public string? Description { get; init; } | ||
public ImmutableList<Leveling> Leveling { get; init; } = ImmutableList<Leveling>.Empty; | ||
|
||
public override string ToString() | ||
{ | ||
return PrettyPrinter.GetString(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.