From 27ffad346f1dce46e0736780fd93fb458da4804a Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Mon, 21 Oct 2019 22:36:48 -0400 Subject: [PATCH] use api to retrieve all items from library --- .../AudibleApiLibationClient.cs | 38 +++++++++++++++---- AudibleApiDomainService/Settings.cs | 2 +- LibationWinForm/UNTESTED/Form1.cs | 2 +- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/AudibleApiDomainService/AudibleApiLibationClient.cs b/AudibleApiDomainService/AudibleApiLibationClient.cs index 56bafb47..a7ff8a73 100644 --- a/AudibleApiDomainService/AudibleApiLibationClient.cs +++ b/AudibleApiDomainService/AudibleApiLibationClient.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net.Http; using System.Threading.Tasks; using AudibleApi; @@ -85,14 +87,6 @@ namespace AudibleApiDomainService } #endregion - public async Task TestGetLibraryAsync() - { - var x = await _api.GetLibraryAsync(); -var str = x.ToString(); - - return x; - } - //public async Task DownloadBookAsync(string asinToDownload) //{ // // console example @@ -117,8 +111,36 @@ var str = x.ToString(); public async Task ImportLibraryAsync() { // json = api.GetLibrary + var jObjects = await GetLibraryItemsAsync(); // json => DTOs // indexer.update(DTOs) } + + private async Task> GetLibraryItemsAsync() + { + var allJsonResults = new List(); + var pageNum = 1; + + while (true) + { + var page = await _api.GetLibraryAsync(new LibraryOptions + { + NumberOfResultPerPage = 1000, + PageNumber = pageNum + }); + + var debugStr = page.ToString(); + + var items = page["items"].Cast(); + allJsonResults.AddRange(items); + + if (!items.Any()) + break; + + pageNum++; + } + + return allJsonResults; + } } } diff --git a/AudibleApiDomainService/Settings.cs b/AudibleApiDomainService/Settings.cs index 0febe54d..681adc8e 100644 --- a/AudibleApiDomainService/Settings.cs +++ b/AudibleApiDomainService/Settings.cs @@ -10,7 +10,7 @@ namespace AudibleApiDomainService public Settings(Configuration config) { - IdentityFilePath = Path.Combine(config.LibationFiles, "identityTokens.json"); + IdentityFilePath = Path.Combine(config.LibationFiles, "IdentityTokens.json"); LocaleCountryCode = config.LocaleCountryCode; } } diff --git a/LibationWinForm/UNTESTED/Form1.cs b/LibationWinForm/UNTESTED/Form1.cs index c3235bec..132803ad 100644 --- a/LibationWinForm/UNTESTED/Form1.cs +++ b/LibationWinForm/UNTESTED/Form1.cs @@ -361,7 +361,7 @@ namespace LibationWinForm var settings = new AudibleApiDomainService.Settings(config); var responder = new Login.WinformResponder(); var client = await AudibleApiDomainService.AudibleApiLibationClient.CreateClientAsync(settings, responder); -var testResult = await client.TestGetLibraryAsync(); + await client.ImportLibraryAsync(); // scrape