use api to retrieve all items from library

This commit is contained in:
Robert McRackan 2019-10-21 22:36:48 -04:00
parent b0fd0ee26a
commit 27ffad346f
3 changed files with 32 additions and 10 deletions

View File

@ -1,5 +1,7 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using AudibleApi; using AudibleApi;
@ -85,14 +87,6 @@ namespace AudibleApiDomainService
} }
#endregion #endregion
public async Task<JObject> TestGetLibraryAsync()
{
var x = await _api.GetLibraryAsync();
var str = x.ToString();
return x;
}
//public async Task DownloadBookAsync(string asinToDownload) //public async Task DownloadBookAsync(string asinToDownload)
//{ //{
// // console example // // console example
@ -117,8 +111,36 @@ var str = x.ToString();
public async Task ImportLibraryAsync() public async Task ImportLibraryAsync()
{ {
// json = api.GetLibrary // json = api.GetLibrary
var jObjects = await GetLibraryItemsAsync();
// json => DTOs // json => DTOs
// indexer.update(DTOs) // indexer.update(DTOs)
} }
private async Task<List<JObject>> GetLibraryItemsAsync()
{
var allJsonResults = new List<JObject>();
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<JObject>();
allJsonResults.AddRange(items);
if (!items.Any())
break;
pageNum++;
}
return allJsonResults;
}
} }
} }

View File

@ -10,7 +10,7 @@ namespace AudibleApiDomainService
public Settings(Configuration config) public Settings(Configuration config)
{ {
IdentityFilePath = Path.Combine(config.LibationFiles, "identityTokens.json"); IdentityFilePath = Path.Combine(config.LibationFiles, "IdentityTokens.json");
LocaleCountryCode = config.LocaleCountryCode; LocaleCountryCode = config.LocaleCountryCode;
} }
} }

View File

@ -361,7 +361,7 @@ namespace LibationWinForm
var settings = new AudibleApiDomainService.Settings(config); var settings = new AudibleApiDomainService.Settings(config);
var responder = new Login.WinformResponder(); var responder = new Login.WinformResponder();
var client = await AudibleApiDomainService.AudibleApiLibationClient.CreateClientAsync(settings, responder); var client = await AudibleApiDomainService.AudibleApiLibationClient.CreateClientAsync(settings, responder);
var testResult = await client.TestGetLibraryAsync();
await client.ImportLibraryAsync(); await client.ImportLibraryAsync();
// scrape // scrape