diff --git a/ApplicationServices/UNTESTED/LibraryCommands.cs b/ApplicationServices/UNTESTED/LibraryCommands.cs index 186fd6c1..c7306c9a 100644 --- a/ApplicationServices/UNTESTED/LibraryCommands.cs +++ b/ApplicationServices/UNTESTED/LibraryCommands.cs @@ -13,8 +13,7 @@ namespace ApplicationServices { try { - var audibleApiActions = new AudibleApiActions(); - var items = await audibleApiActions.GetAllLibraryItemsAsync(callback); + var items = await AudibleApiActions.GetAllLibraryItemsAsync(callback); var totalCount = items.Count; Serilog.Log.Logger.Information($"GetAllLibraryItems: Total count {totalCount}"); diff --git a/FileLiberator/UNTESTED/DownloadBook.cs b/FileLiberator/UNTESTED/DownloadBook.cs index 066c9a7f..e571ac97 100644 --- a/FileLiberator/UNTESTED/DownloadBook.cs +++ b/FileLiberator/UNTESTED/DownloadBook.cs @@ -5,6 +5,7 @@ using DataLayer; using Dinah.Core; using Dinah.Core.ErrorHandling; using FileManager; +using InternalUtilities; namespace FileLiberator { @@ -41,7 +42,7 @@ namespace FileLiberator private async Task downloadBookAsync(LibraryBook libraryBook, string tempAaxFilename) { - var api = await AudibleApi.EzApiCreator.GetApiAsync(AudibleApiStorage.AccountsSettingsFile, null, Configuration.Instance.LocaleCountryCode); + var api = await AudibleApiActions.GetApiAsync(); var actualFilePath = await PerformDownloadAsync( tempAaxFilename, diff --git a/InternalUtilities/UNTESTED/AudibleApiActions.cs b/InternalUtilities/UNTESTED/AudibleApiActions.cs index b967ec46..2b743a4a 100644 --- a/InternalUtilities/UNTESTED/AudibleApiActions.cs +++ b/InternalUtilities/UNTESTED/AudibleApiActions.cs @@ -10,26 +10,37 @@ using Polly.Retry; namespace InternalUtilities { - public class AudibleApiActions + public static class AudibleApiActions { - private AsyncRetryPolicy policy { get; } + /// USE THIS from within Libation. It wraps the call with correct JSONPath + public static async Task GetApiAsync(ILoginCallback loginCallback = null) + { + var identityFilePath = AudibleApiStorage.AccountsSettingsFile; + + // TODO: get jsonpath from ... somewhere + string jsonPath = null; + Localization.SetLocale(Configuration.Instance.LocaleCountryCode); + + return await EzApiCreator.GetApiAsync(identityFilePath, loginCallback, jsonPath); + } + + private static AsyncRetryPolicy policy { get; } = Policy.Handle() // 2 retries == 3 total .RetryAsync(2); - public async Task> GetAllLibraryItemsAsync(ILoginCallback callback) + public static Task> GetAllLibraryItemsAsync(ILoginCallback callback) { // bug on audible's side. the 1st time after a long absence, a query to get library will return without titles or authors. a subsequent identical query will be successful. this is true whether or tokens are refreshed // worse, this 1st dummy call doesn't seem to help: // var page = await api.GetLibraryAsync(new AudibleApi.LibraryOptions { NumberOfResultPerPage = 1, PageNumber = 1, PurchasedAfter = DateTime.Now.AddYears(-20), ResponseGroups = AudibleApi.LibraryOptions.ResponseGroupOptions.ALL_OPTIONS }); // i don't want to incur the cost of making a full dummy call every time because it fails sometimes - return await policy.ExecuteAsync(() => getItemsAsync(callback)); + return policy.ExecuteAsync(() => getItemsAsync(callback)); } - - private async Task> getItemsAsync(ILoginCallback callback) + private static async Task> getItemsAsync(ILoginCallback callback) { - var api = await EzApiCreator.GetApiAsync(AudibleApiStorage.AccountsSettingsFile, callback, Configuration.Instance.LocaleCountryCode); - var items = await AudibleApiExtensions.GetAllLibraryItemsAsync(api); + var api = await GetApiAsync(callback); + var items = await api.GetAllLibraryItemsAsync(); // remove episode parents items.RemoveAll(i => i.IsEpisodes); diff --git a/Libation.sln b/Libation.sln index 10d0253d..13b6c4e3 100644 --- a/Libation.sln +++ b/Libation.sln @@ -10,13 +10,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_Solution Items", "_Solutio REFERENCE.txt = REFERENCE.txt EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3.2 Domain Utilities (database aware)", "3.2 Domain Utilities (database aware)", "{41CDCC73-9B81-49DD-9570-C54406E852AF}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "5 Domain Utilities (db aware)", "5 Domain Utilities (db aware)", "{41CDCC73-9B81-49DD-9570-C54406E852AF}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4 Application", "4 Application", "{8679CAC8-9164-4007-BDD2-F004810EDA14}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "6 Application", "6 Application", "{8679CAC8-9164-4007-BDD2-F004810EDA14}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1 Core Libraries", "1 Core Libraries", "{43E3ACB3-E0BC-4370-8DBB-E3720C8C8FD1}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3 Domain", "3 Domain", "{751093DD-5DBA-463E-ADBE-E05FAFB6983E}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4 Domain (db)", "4 Domain (db)", "{751093DD-5DBA-463E-ADBE-E05FAFB6983E}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2 Utilities (domain ignorant)", "2 Utilities (domain ignorant)", "{7FBBB086-0807-4998-85BF-6D1A49C8AD05}" EndProject @@ -30,7 +30,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileLiberator", "FileLibera EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InternalUtilities", "InternalUtilities\InternalUtilities.csproj", "{06882742-27A6-4347-97D9-56162CEC9C11}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3.1 Domain Internal Utilities (db ignorant)", "3.1 Domain Internal Utilities (db ignorant)", "{F0CBB7A7-D3FB-41FF-8F47-CF3F6A592249}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "3 Domain Internal Utilities (db ignorant)", "3 Domain Internal Utilities (db ignorant)", "{F0CBB7A7-D3FB-41FF-8F47-CF3F6A592249}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibationSearchEngine", "LibationSearchEngine\LibationSearchEngine.csproj", "{2E1F5DB4-40CC-4804-A893-5DCE0193E598}" EndProject @@ -80,7 +80,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dinah.Core.WindowsDesktop", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WindowsDesktopUtilities", "WindowsDesktopUtilities\WindowsDesktopUtilities.csproj", "{E7EFD64D-6630-4426-B09C-B6862A92E3FD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibationLauncher", "LibationLauncher\LibationLauncher.csproj", "{F3B04A3A-20C8-4582-A54A-715AF6A5D859}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibationLauncher", "LibationLauncher\LibationLauncher.csproj", "{F3B04A3A-20C8-4582-A54A-715AF6A5D859}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/LibationLauncher/LibationLauncher.csproj b/LibationLauncher/LibationLauncher.csproj index 6d6c73a5..dda944db 100644 --- a/LibationLauncher/LibationLauncher.csproj +++ b/LibationLauncher/LibationLauncher.csproj @@ -13,7 +13,7 @@ win-x64 - 3.1.12.27 + 3.1.12.54