* include new external login interfaces in ApiExtended

* new ext method to simplify api access in file liberator
This commit is contained in:
Robert McRackan 2021-09-17 16:09:49 -04:00
parent 51020ef99e
commit 926a7a1148
8 changed files with 66 additions and 32 deletions

View file

@ -17,6 +17,57 @@ namespace InternalUtilities
private ApiExtended(Api api) => Api = api;
public static async Task<ApiExtended> 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<ApiExtended> 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<ApiExtended> 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<ApiExtended> 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<ApiExtended> 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<Exception>()
// 2 retries == 3 total