Reduce footprint of Account credentials API

This commit is contained in:
Maurice Parker 2019-06-20 11:19:15 -05:00
parent 2756e8f204
commit 1ac1144b2d
5 changed files with 37 additions and 33 deletions

View File

@ -295,34 +295,40 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
}
public func retrieveBasicCredentials() throws -> Credentials? {
public func retrieveCredentials() throws -> Credentials? {
switch type {
case .feedbin:
guard let username = self.username, let server = delegate.server else {
return nil
}
return try CredentialsManager.retrieveBasicCredentials(server: server, username: username)
case .freshRSS:
guard let username = self.username, let server = delegate.server else {
return nil
}
return try CredentialsManager.retrieveReaderAPIAuthCredentials(server: server, username: username)
default:
return nil
}
}
public func removeBasicCredentials() throws {
public func removeCredentials() throws {
switch type {
case .feedbin:
guard let username = self.username, let server = delegate.server else {
return
}
try CredentialsManager.removeBasicCredentials(server: server, username: username)
self.username = nil
}
public func retrieveReaderAPIAuthCredentials() throws -> Credentials? {
guard let username = self.username, let server = delegate.server else {
return nil
}
return try CredentialsManager.retrieveReaderAPIAuthCredentials(server: server, username: username)
}
public func removeReaderAPIAuthCredentials() throws {
case .freshRSS:
guard let username = self.username, let server = delegate.server else {
return
}
try CredentialsManager.removeReaderAPIAuthCredentials(server: server, username: username)
self.username = nil
default:
break
}
}
public static func validateCredentials(transport: Transport = URLSession.webserviceTransport(), type: AccountType, credentials: Credentials, endpoint: URL? = nil, completion: @escaping (Result<Credentials?, Error>) -> Void) {

View File

@ -510,7 +510,7 @@ final class FeedbinAccountDelegate: AccountDelegate {
}
func accountDidInitialize(_ account: Account) {
credentials = try? account.retrieveBasicCredentials()
credentials = try? account.retrieveCredentials()
accountMetadata = account.metadata
}

View File

@ -411,7 +411,7 @@ final class ReaderAPIAccountDelegate: AccountDelegate {
func accountDidInitialize(_ account: Account) {
accountMetadata = account.metadata
credentials = try? account.retrieveReaderAPIAuthCredentials()
credentials = try? account.retrieveCredentials()
}
static func validateCredentials(transport: Transport, credentials: Credentials, endpoint: URL?, completion: @escaping (Result<Credentials?, Error>) -> Void) {

View File

@ -27,10 +27,9 @@ class AccountsFeedbinWindowController: NSWindowController {
}
override func windowDidLoad() {
if let account = account, let credentials = try? account.retrieveBasicCredentials() {
if case .basic(let username, let password) = credentials {
if let account = account, let credentials = try? account.retrieveCredentials() {
if case .basic(let username, _) = credentials {
usernameTextField.stringValue = username
passwordTextField.stringValue = password
}
actionButton.title = NSLocalizedString("Update", comment: "Update")
} else {
@ -87,7 +86,7 @@ class AccountsFeedbinWindowController: NSWindowController {
}
do {
try self.account?.removeBasicCredentials()
try self.account?.removeCredentials()
try self.account?.storeCredentials(validatedCredentials)
if newAccount {
self.account?.refreshAll() { result in

View File

@ -42,10 +42,9 @@ class AccountsReaderAPIWindowController: NSWindowController {
}
}
if let account = account, let credentials = try? account.retrieveBasicCredentials() {
if case .basic(let username, let password) = credentials {
if let account = account, let credentials = try? account.retrieveCredentials() {
if case .basic(let username, _) = credentials {
usernameTextField.stringValue = username
passwordTextField.stringValue = password
}
actionButton.title = NSLocalizedString("Update", comment: "Update")
} else {
@ -110,7 +109,7 @@ class AccountsReaderAPIWindowController: NSWindowController {
do {
self.account?.endpointURL = apiURL
try self.account?.removeReaderAPIAuthCredentials()
try self.account?.removeCredentials()
try self.account?.storeCredentials(validatedCredentials)
if newAccount {