diff --git a/AppScaffolding/AppScaffolding.csproj b/AppScaffolding/AppScaffolding.csproj index 278c50b0..4afd6076 100644 --- a/AppScaffolding/AppScaffolding.csproj +++ b/AppScaffolding/AppScaffolding.csproj @@ -3,7 +3,7 @@ net5.0 - 6.0.0.1 + 6.0.0.2 diff --git a/InternalUtilities/ImportItem.cs b/DtoImporterService/ImportItem.cs similarity index 87% rename from InternalUtilities/ImportItem.cs rename to DtoImporterService/ImportItem.cs index a9acaec4..990ee48f 100644 --- a/InternalUtilities/ImportItem.cs +++ b/DtoImporterService/ImportItem.cs @@ -1,7 +1,7 @@ using System; using AudibleApi.Common; -namespace InternalUtilities +namespace DtoImporterService { public class ImportItem { diff --git a/FileLiberator/DownloadDecryptBook.cs b/FileLiberator/DownloadDecryptBook.cs index 61c813f1..98d87b2a 100644 --- a/FileLiberator/DownloadDecryptBook.cs +++ b/FileLiberator/DownloadDecryptBook.cs @@ -84,9 +84,8 @@ namespace FileLiberator { validate(libraryBook); - var apiExtended = await InternalUtilities.ApiExtended.CreateAsync(libraryBook.Account, libraryBook.Book.Locale); - - var contentLic = await apiExtended.Api.GetDownloadLicenseAsync(libraryBook.Book.AudibleProductId); + var api = await libraryBook.GetApiAsync(); + var contentLic = await api.GetDownloadLicenseAsync(libraryBook.Book.AudibleProductId); var aaxcDecryptDlLic = new DownloadLicense ( diff --git a/FileLiberator/DownloadPdf.cs b/FileLiberator/DownloadPdf.cs index 6b37278e..74e4a66d 100644 --- a/FileLiberator/DownloadPdf.cs +++ b/FileLiberator/DownloadPdf.cs @@ -59,8 +59,8 @@ namespace FileLiberator private async Task downloadPdfAsync(LibraryBook libraryBook, string proposedDownloadFilePath) { - var apiExtended = await GetApiExtendedAsync(libraryBook); - var downloadUrl = await apiExtended.Api.GetPdfDownloadLinkAsync(libraryBook.Book.AudibleProductId); + var api = await libraryBook.GetApiAsync(); + var downloadUrl = await api.GetPdfDownloadLinkAsync(libraryBook.Book.AudibleProductId); var client = new HttpClient(); var actualDownloadedFilePath = await PerformDownloadAsync( diff --git a/FileLiberator/DownloadableBase.cs b/FileLiberator/DownloadableBase.cs index 84351627..5ac6652e 100644 --- a/FileLiberator/DownloadableBase.cs +++ b/FileLiberator/DownloadableBase.cs @@ -40,9 +40,6 @@ namespace FileLiberator } } - protected static Task GetApiExtendedAsync(LibraryBook libraryBook) - => InternalUtilities.ApiExtended.CreateAsync(libraryBook.Account, libraryBook.Book.Locale); - protected async Task PerformDownloadAsync(string proposedDownloadFilePath, Func, Task> func) { var progress = new Progress(); diff --git a/FileLiberator/LoggerUtilities.cs b/FileLiberator/UtilityExtensions.cs similarity index 62% rename from FileLiberator/LoggerUtilities.cs rename to FileLiberator/UtilityExtensions.cs index 38d05c34..df4d6834 100644 --- a/FileLiberator/LoggerUtilities.cs +++ b/FileLiberator/UtilityExtensions.cs @@ -1,16 +1,13 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; using System.Threading.Tasks; using DataLayer; using Dinah.Core; -using Dinah.Core.ErrorHandling; namespace FileLiberator { - public static class LoggerUtilities + public static class UtilityExtensions { public static (string id, string title, string locale, string account) LogFriendly(this LibraryBook libraryBook) => ( @@ -19,5 +16,11 @@ namespace FileLiberator locale: libraryBook.Book.Locale, account: libraryBook.Account.ToMask() ); + + public static async Task GetApiAsync(this LibraryBook libraryBook) + { + var apiExtended = await InternalUtilities.ApiExtended.CreateAsync(libraryBook.Account, libraryBook.Book.Locale); + return apiExtended.Api; + } } } diff --git a/InternalUtilities/ApiExtended.cs b/InternalUtilities/ApiExtended.cs index 5252e74f..66d4d7ce 100644 --- a/InternalUtilities/ApiExtended.cs +++ b/InternalUtilities/ApiExtended.cs @@ -17,6 +17,57 @@ namespace InternalUtilities private ApiExtended(Api api) => Api = api; + public static async Task CreateAsync(ILoginChoice loginChoice, Account account) + { + Serilog.Log.Logger.Information("GetApiAsync. {@DebugInfo}", new + { + LoginType = nameof(ILoginChoice), + Account = account?.MaskedLogEntry ?? "[null]", + LocaleName = account?.Locale?.Name + }); + + var api = await EzApiCreator.GetApiAsync( + account.Locale, + AudibleApiStorage.AccountsSettingsFile, + loginChoice, + account.GetIdentityTokensJsonPath()); + return new ApiExtended(api); + } + + public static async Task CreateAsync(ILoginCallback loginCallback, Account account) + { + Serilog.Log.Logger.Information("GetApiAsync ILoginCallback. {@DebugInfo}", new + { + LoginType = nameof(ILoginCallback), + Account = account?.MaskedLogEntry ?? "[null]", + LocaleName = account?.Locale?.Name + }); + + var api = await EzApiCreator.GetApiAsync( + account.Locale, + AudibleApiStorage.AccountsSettingsFile, + loginCallback, + account.GetIdentityTokensJsonPath()); + return new ApiExtended(api); + } + + public static async Task CreateAsync(ILoginExternal loginExternal, Account account) + { + Serilog.Log.Logger.Information("GetApiAsync ILoginExternal. {@DebugInfo}", new + { + LoginType = nameof(ILoginExternal), + Account = account?.MaskedLogEntry ?? "[null]", + LocaleName = account?.Locale?.Name + }); + + var api = await EzApiCreator.GetApiAsync( + account.Locale, + AudibleApiStorage.AccountsSettingsFile, + loginExternal, + account.GetIdentityTokensJsonPath()); + return new ApiExtended(api); + } + public static async Task CreateAsync(string username, string localeName) { Serilog.Log.Logger.Information("GetApiAsync. {@DebugInfo}", new @@ -32,22 +83,6 @@ namespace InternalUtilities return new ApiExtended(api); } - public static async Task CreateAsync(ILoginCallback loginCallback, Account account) - { - Serilog.Log.Logger.Information("GetApiAsync. {@DebugInfo}", new - { - Account = account?.MaskedLogEntry ?? "[null]", - LocaleName = account?.Locale?.Name - }); - - var api = await EzApiCreator.GetApiAsync( - account.Locale, - AudibleApiStorage.AccountsSettingsFile, - loginCallback, - account.GetIdentityTokensJsonPath()); - return new ApiExtended(api); - } - private static AsyncRetryPolicy policy { get; } = Policy.Handle() // 2 retries == 3 total diff --git a/InternalUtilities/AudibleApiValidators.cs b/InternalUtilities/AudibleApiValidators.cs index 5af37a07..63192376 100644 --- a/InternalUtilities/AudibleApiValidators.cs +++ b/InternalUtilities/AudibleApiValidators.cs @@ -76,9 +76,9 @@ namespace InternalUtilities var distinct = items.GetSeriesDistinct(); if (distinct.Any(s => s.SeriesId is null)) - exceptions.Add(new ArgumentException($"Collection contains {nameof(Item.Series)} with null {nameof(AudibleApi.Common.Series.SeriesId)}", nameof(items))); + exceptions.Add(new ArgumentException($"Collection contains {nameof(Item.Series)} with null {nameof(Series.SeriesId)}", nameof(items))); if (distinct.Any(s => s.SeriesName is null)) - exceptions.Add(new ArgumentException($"Collection contains {nameof(Item.Series)} with null {nameof(AudibleApi.Common.Series.SeriesName)}", nameof(items))); + exceptions.Add(new ArgumentException($"Collection contains {nameof(Item.Series)} with null {nameof(Series.SeriesName)}", nameof(items))); return exceptions; }