-
Notifications
You must be signed in to change notification settings - Fork 40
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 #14 from Sidekick-Poe/features/fixedKoreanTradeInt…
…erface Fixed the trade screen for languages other than english
- Loading branch information
Showing
40 changed files
with
416 additions
and
504 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,13 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Sidekick.Apis.PoeNinja.Api.Models; | ||
using Sidekick.Apis.PoeNinja.Models; | ||
|
||
namespace Sidekick.Apis.PoeNinja.Api | ||
{ | ||
public interface IPoeNinjaApiClient | ||
{ | ||
Task<List<NinjaPrice>> FetchItems(ItemType itemType); | ||
Task<List<NinjaPrice>> FetchCurrencies(CurrencyType currencyType); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...kick.Apis.PoeNinja/Models/CurrencyType.cs → ....Apis.PoeNinja/Api/Models/CurrencyType.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
2 changes: 1 addition & 1 deletion
2
...Sidekick.Apis.PoeNinja/Models/ItemType.cs → ...kick.Apis.PoeNinja/Api/Models/ItemType.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Sidekick.Apis.PoeNinja.Models | ||
namespace Sidekick.Apis.PoeNinja.Api.Models | ||
{ | ||
public enum ItemType | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
...Sidekick.Apis.PoeNinja/Models/Modifier.cs → ...kick.Apis.PoeNinja/Api/Models/Modifier.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Sidekick.Apis.PoeNinja.Models | ||
namespace Sidekick.Apis.PoeNinja.Api.Models | ||
{ | ||
public class Modifier | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
...Apis.PoeNinja/Models/PoeNinjaCacheItem.cs → ....PoeNinja/Api/Models/PoeNinjaCacheItem.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
2 changes: 1 addition & 1 deletion
2
....Apis.PoeNinja/Models/PoeNinjaCurrency.cs → ...s.PoeNinja/Api/Models/PoeNinjaCurrency.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
2 changes: 1 addition & 1 deletion
2
....Apis.PoeNinja/Models/PoeNinjaExchange.cs → ...s.PoeNinja/Api/Models/PoeNinjaExchange.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
2 changes: 1 addition & 1 deletion
2
...kick.Apis.PoeNinja/Models/PoeNinjaItem.cs → ....Apis.PoeNinja/Api/Models/PoeNinjaItem.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
2 changes: 1 addition & 1 deletion
2
...is.PoeNinja/Models/PoeNinjaQueryResult.cs → ...oeNinja/Api/Models/PoeNinjaQueryResult.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
2 changes: 1 addition & 1 deletion
2
...nja/Models/PoeNinjaQueryResultLanguage.cs → ...Api/Models/PoeNinjaQueryResultLanguage.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
2 changes: 1 addition & 1 deletion
2
...idekick.Apis.PoeNinja/Models/Sparkline.cs → ...ick.Apis.PoeNinja/Api/Models/Sparkline.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Sidekick.Apis.PoeNinja.Models | ||
namespace Sidekick.Apis.PoeNinja.Api.Models | ||
{ | ||
public class SparkLine | ||
{ | ||
|
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,161 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using Sidekick.Apis.PoeNinja.Api.Models; | ||
using Sidekick.Apis.PoeNinja.Models; | ||
using Sidekick.Apis.PoeNinja.Repository; | ||
using Sidekick.Common.Game.Languages; | ||
using Sidekick.Common.Settings; | ||
|
||
namespace Sidekick.Apis.PoeNinja.Api | ||
{ | ||
/// <summary> | ||
/// https://poe.ninja/swagger | ||
/// </summary> | ||
public class PoeNinjaApiClient : IPoeNinjaApiClient | ||
{ | ||
private readonly static Uri POE_NINJA_API_BASE_URL = new("https://poe.ninja/api/data/"); | ||
/// <summary> | ||
/// Poe.ninja uses its own language codes. | ||
/// </summary> | ||
internal readonly static Dictionary<string, string> POE_NINJA_LANGUAGE_CODES = new() | ||
{ | ||
{ "de", "ge" }, // German. | ||
{ "en", "en" }, // English. | ||
{ "es", "es" }, // Spanish. | ||
{ "fr", "fr" }, // French. | ||
{ "kr", "ko" }, // Korean. | ||
{ "pt", "pt" }, // Portuguese. | ||
{ "ru", "ru" }, // Russian. | ||
{ "th", "th" }, // Thai. | ||
}; | ||
private readonly HttpClient client; | ||
private readonly ILogger logger; | ||
private readonly IGameLanguageProvider gameLanguageProvider; | ||
private readonly ISettings settings; | ||
private readonly IPoeNinjaRepository poeNinjaRepository; | ||
private readonly JsonSerializerOptions options; | ||
|
||
private string LanguageCode | ||
{ | ||
get | ||
{ | ||
if (POE_NINJA_LANGUAGE_CODES.TryGetValue(gameLanguageProvider.Language.LanguageCode, out var languageCode)) | ||
{ | ||
return languageCode; | ||
} | ||
return string.Empty; | ||
} | ||
} | ||
|
||
public PoeNinjaApiClient( | ||
IHttpClientFactory httpClientFactory, | ||
ILogger<PoeNinjaClient> logger, | ||
IGameLanguageProvider gameLanguageProvider, | ||
ISettings settings, | ||
IPoeNinjaRepository poeNinjaRepository) | ||
{ | ||
this.logger = logger; | ||
this.gameLanguageProvider = gameLanguageProvider; | ||
this.settings = settings; | ||
this.poeNinjaRepository = poeNinjaRepository; | ||
options = new JsonSerializerOptions() | ||
{ | ||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | ||
IgnoreNullValues = true, | ||
}; | ||
options.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); | ||
|
||
client = httpClientFactory.CreateClient(); | ||
client.DefaultRequestHeaders.TryAddWithoutValidation("X-Powered-By", "Sidekick"); | ||
client.DefaultRequestHeaders.UserAgent.TryParseAdd("Sidekick"); | ||
} | ||
|
||
public async Task<List<NinjaPrice>> FetchItems(ItemType itemType) | ||
{ | ||
var url = new Uri($"{POE_NINJA_API_BASE_URL}itemoverview?league={settings.LeagueId}&type={itemType}&language={LanguageCode}"); | ||
|
||
try | ||
{ | ||
var response = await client.GetAsync(url); | ||
var responseStream = await response.Content.ReadAsStreamAsync(); | ||
var result = await JsonSerializer.DeserializeAsync<PoeNinjaQueryResult<PoeNinjaItem>>(responseStream, options); | ||
var items = result.Lines | ||
.Select(x => new NinjaPrice() | ||
{ | ||
Corrupted = x.Corrupted, | ||
Price = x.ChaosValue, | ||
LastUpdated = DateTimeOffset.Now, | ||
Name = x.Name, | ||
MapTier = x.MapTier, | ||
GemLevel = x.GemLevel, | ||
}) | ||
.ToList(); | ||
|
||
await poeNinjaRepository.SavePrices(itemType, items); | ||
await poeNinjaRepository.SaveTranslations(itemType, result.Language.Translations | ||
.Where(y => !y.Value.Contains(".")) | ||
.Distinct() | ||
.Select(x => new NinjaTranslation() | ||
{ | ||
English = x.Key, | ||
Translation = x.Value, | ||
}) | ||
.ToList()); | ||
|
||
return items; | ||
} | ||
catch (Exception) | ||
{ | ||
logger.LogInformation("Could not fetch {itemType} from poe.ninja", itemType); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public async Task<List<NinjaPrice>> FetchCurrencies(CurrencyType currencyType) | ||
{ | ||
var url = new Uri($"{POE_NINJA_API_BASE_URL}currencyoverview?league={settings.LeagueId}&type={currencyType}&language={LanguageCode}"); | ||
|
||
try | ||
{ | ||
var response = await client.GetAsync(url); | ||
var responseStream = await response.Content.ReadAsStreamAsync(); | ||
var result = await JsonSerializer.DeserializeAsync<PoeNinjaQueryResult<PoeNinjaCurrency>>(responseStream, options); | ||
var items = result.Lines | ||
.Select(x => new NinjaPrice() | ||
{ | ||
Corrupted = false, | ||
Price = x.Receive.Value, | ||
LastUpdated = DateTimeOffset.Now, | ||
Name = x.CurrencyTypeName, | ||
}) | ||
.ToList(); | ||
|
||
await poeNinjaRepository.SavePrices(currencyType, items); | ||
await poeNinjaRepository.SaveTranslations(currencyType, result.Language.Translations | ||
.Where(y => !y.Value.Contains(".")) | ||
.Distinct() | ||
.Select(x => new NinjaTranslation() | ||
{ | ||
English = x.Key, | ||
Translation = x.Value, | ||
}) | ||
.ToList()); | ||
|
||
return items; | ||
} | ||
catch | ||
{ | ||
logger.LogInformation("Could not fetch {currency} from poe.ninja", currencyType); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
using System.Threading.Tasks; | ||
using Sidekick.Apis.PoeNinja.Repository.Models; | ||
using Sidekick.Apis.PoeNinja.Models; | ||
using Sidekick.Common.Game.Items; | ||
|
||
namespace Sidekick.Apis.PoeNinja | ||
{ | ||
public interface IPoeNinjaClient | ||
{ | ||
bool IsSupportingCurrentLanguage { get; } | ||
|
||
Task Initialize(); | ||
Task<NinjaPrice> GetPriceInfo(Item item); | ||
} | ||
} |
61 changes: 0 additions & 61 deletions
61
src/Sidekick.Apis.PoeNinja/Migrations/20210829020611_PoeNinjaRepository.Designer.cs
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
src/Sidekick.Apis.PoeNinja/Migrations/20210829020611_PoeNinjaRepository.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.