Downloading to use new instance locale and account

This commit is contained in:
Robert McRackan 2020-08-21 13:36:01 -04:00
parent 2e5360f0ba
commit 714bb2ba50
6 changed files with 23 additions and 16 deletions

View file

@ -13,12 +13,20 @@ namespace InternalUtilities
public static class AudibleApiActions
{
/// <summary>USE THIS from within Libation. It wraps the call with correct JSONPath</summary>
public static Task<Api> GetApiAsync(Locale locale, ILoginCallback loginCallback = null)
=> EzApiCreator.GetApiAsync(locale, AudibleApiStorage.AccountsSettingsFile, AudibleApiStorage.TEST_GetFirstIdentityTokensJsonPath(), loginCallback);
public static Task<Api> GetApiAsync(string username, string localeName, ILoginCallback loginCallback = null)
=> EzApiCreator.GetApiAsync(
Localization.Get(localeName),
AudibleApiStorage.AccountsSettingsFile,
AudibleApiStorage.GetIdentityTokensJsonPath(username, localeName),
loginCallback);
/// <summary>USE THIS from within Libation. It wraps the call with correct JSONPath</summary>
public static Task<Api> GetApiAsync(Account account, ILoginCallback loginCallback = null)
=> EzApiCreator.GetApiAsync(account.Locale, AudibleApiStorage.AccountsSettingsFile, account.GetIdentityTokensJsonPath(), loginCallback);
=> EzApiCreator.GetApiAsync(
account.Locale,
AudibleApiStorage.AccountsSettingsFile,
account.GetIdentityTokensJsonPath(),
loginCallback);
private static AsyncRetryPolicy policy { get; }
= Policy.Handle<Exception>()

View file

@ -43,9 +43,8 @@ namespace InternalUtilities
if (!libResult.Items.Any())
break;
else
Serilog.Log.Logger.Information($"Page {i}: {libResult.Items.Length} results");
Serilog.Log.Logger.Information($"Page {i}: {libResult.Items.Length} results");
allItems.AddRange(libResult.Items);
}

View file

@ -28,12 +28,12 @@ namespace InternalUtilities
public static string GetIdentityTokensJsonPath(this Account account)
=> GetIdentityTokensJsonPath(account.AccountId, account.Locale?.Name);
public static string GetIdentityTokensJsonPath(string username, string locale)
public static string GetIdentityTokensJsonPath(string username, string localeName)
{
var usernameSanitized = trimSurroundingQuotes(JsonConvert.ToString(username));
var localeSanitized = trimSurroundingQuotes(JsonConvert.ToString(locale));
var localeNameSanitized = trimSurroundingQuotes(JsonConvert.ToString(localeName));
return $"$.AccountsSettings[?(@.AccountId == '{usernameSanitized}' && @.IdentityTokens.LocaleName == '{localeSanitized}')].IdentityTokens";
return $"$.AccountsSettings[?(@.AccountId == '{usernameSanitized}' && @.IdentityTokens.LocaleName == '{localeNameSanitized}')].IdentityTokens";
}
// SubString algo is better than .Trim("\"")
// orig string "