change func signitures to use Credentials protocol from RSWeb instead of username/password
This commit is contained in:
parent
38202ece8d
commit
595db517a7
@ -241,17 +241,17 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||||||
|
|
||||||
// MARK: - API
|
// MARK: - API
|
||||||
|
|
||||||
public func storeCredentials(username: String, password: String) {
|
public func storeCredentials(_ credentials: Credentials) {
|
||||||
self.username = username
|
self.username = credentials.username
|
||||||
// self.password = password
|
// self.password = password
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func validateCredentials(transport: Transport = URLSession.webserviceTransport(), type: AccountType, username: String, password: String, completionHandler handler: @escaping (Result<Bool, Error>) -> Void) {
|
public static func validateCredentials(transport: Transport = URLSession.webserviceTransport(), type: AccountType, credentials: Credentials, completionHandler handler: @escaping (Result<Bool, Error>) -> Void) {
|
||||||
switch type {
|
switch type {
|
||||||
case .onMyMac:
|
case .onMyMac:
|
||||||
LocalAccountDelegate.validateCredentials(transport: transport, username: username, password: password, completionHandler: handler)
|
LocalAccountDelegate.validateCredentials(transport: transport, credentials: credentials, completionHandler: handler)
|
||||||
case .feedbin:
|
case .feedbin:
|
||||||
FeedbinAccountDelegate.validateCredentials(transport: transport, username: username, password: password, completionHandler: handler)
|
FeedbinAccountDelegate.validateCredentials(transport: transport, credentials: credentials, completionHandler: handler)
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,9 @@
|
|||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
|
5107A099227DE42E00C7C3C5 /* AccountCredentialsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5107A098227DE42E00C7C3C5 /* AccountCredentialsTest.swift */; };
|
||||||
|
5107A09B227DE49500C7C3C5 /* TestAccountManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5107A09A227DE49500C7C3C5 /* TestAccountManager.swift */; };
|
||||||
|
5107A09D227DE77700C7C3C5 /* NilTransport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5107A09C227DE77700C7C3C5 /* NilTransport.swift */; };
|
||||||
5144EA49227B497600D19003 /* FeedbinAPICaller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA48227B497600D19003 /* FeedbinAPICaller.swift */; };
|
5144EA49227B497600D19003 /* FeedbinAPICaller.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA48227B497600D19003 /* FeedbinAPICaller.swift */; };
|
||||||
5144EA4E227B829A00D19003 /* FeedbinAccountDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA4D227B829A00D19003 /* FeedbinAccountDelegate.swift */; };
|
5144EA4E227B829A00D19003 /* FeedbinAccountDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5144EA4D227B829A00D19003 /* FeedbinAccountDelegate.swift */; };
|
||||||
841973FE1F6DD1BC006346C4 /* RSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 841973EF1F6DD19E006346C4 /* RSCore.framework */; };
|
841973FE1F6DD1BC006346C4 /* RSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 841973EF1F6DD19E006346C4 /* RSCore.framework */; };
|
||||||
@ -85,6 +88,9 @@
|
|||||||
/* End PBXContainerItemProxy section */
|
/* End PBXContainerItemProxy section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
5107A098227DE42E00C7C3C5 /* AccountCredentialsTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountCredentialsTest.swift; sourceTree = "<group>"; };
|
||||||
|
5107A09A227DE49500C7C3C5 /* TestAccountManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestAccountManager.swift; sourceTree = "<group>"; };
|
||||||
|
5107A09C227DE77700C7C3C5 /* NilTransport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NilTransport.swift; sourceTree = "<group>"; };
|
||||||
5144EA48227B497600D19003 /* FeedbinAPICaller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbinAPICaller.swift; sourceTree = "<group>"; };
|
5144EA48227B497600D19003 /* FeedbinAPICaller.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbinAPICaller.swift; sourceTree = "<group>"; };
|
||||||
5144EA4D227B829A00D19003 /* FeedbinAccountDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbinAccountDelegate.swift; sourceTree = "<group>"; };
|
5144EA4D227B829A00D19003 /* FeedbinAccountDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedbinAccountDelegate.swift; sourceTree = "<group>"; };
|
||||||
841973E81F6DD19E006346C4 /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = ../RSCore/RSCore.xcodeproj; sourceTree = "<group>"; };
|
841973E81F6DD19E006346C4 /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = ../RSCore/RSCore.xcodeproj; sourceTree = "<group>"; };
|
||||||
@ -244,8 +250,11 @@
|
|||||||
848935031F62484F00CEBD24 /* AccountTests */ = {
|
848935031F62484F00CEBD24 /* AccountTests */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
5107A09A227DE49500C7C3C5 /* TestAccountManager.swift */,
|
||||||
848935041F62485000CEBD24 /* AccountTests.swift */,
|
848935041F62485000CEBD24 /* AccountTests.swift */,
|
||||||
|
5107A098227DE42E00C7C3C5 /* AccountCredentialsTest.swift */,
|
||||||
848935061F62485000CEBD24 /* Info.plist */,
|
848935061F62485000CEBD24 /* Info.plist */,
|
||||||
|
5107A09C227DE77700C7C3C5 /* NilTransport.swift */,
|
||||||
);
|
);
|
||||||
path = AccountTests;
|
path = AccountTests;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -449,6 +458,9 @@
|
|||||||
isa = PBXSourcesBuildPhase;
|
isa = PBXSourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
5107A09B227DE49500C7C3C5 /* TestAccountManager.swift in Sources */,
|
||||||
|
5107A09D227DE77700C7C3C5 /* NilTransport.swift in Sources */,
|
||||||
|
5107A099227DE42E00C7C3C5 /* AccountCredentialsTest.swift in Sources */,
|
||||||
848935051F62485000CEBD24 /* AccountTests.swift in Sources */,
|
848935051F62485000CEBD24 /* AccountTests.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
|
@ -13,11 +13,12 @@ public protocol AccountDelegate {
|
|||||||
|
|
||||||
// Local account does not; some synced accounts might.
|
// Local account does not; some synced accounts might.
|
||||||
var supportsSubFolders: Bool { get }
|
var supportsSubFolders: Bool { get }
|
||||||
|
var server: String? { get }
|
||||||
|
|
||||||
|
static func validateCredentials(transport: Transport, credentials: Credentials, completionHandler handler: @escaping (Result<Bool, Error>) -> Void)
|
||||||
|
|
||||||
var refreshProgress: DownloadProgress { get }
|
var refreshProgress: DownloadProgress { get }
|
||||||
|
|
||||||
static func validateCredentials(transport: Transport, username: String, password: String, completionHandler handler: @escaping (Result<Bool, Error>) -> Void)
|
|
||||||
|
|
||||||
func refreshAll(for: Account)
|
func refreshAll(for: Account)
|
||||||
|
|
||||||
// Called at the end of account’s init method.
|
// Called at the end of account’s init method.
|
||||||
|
28
Frameworks/Account/AccountTests/AccountCredentialsTest.swift
Normal file
28
Frameworks/Account/AccountTests/AccountCredentialsTest.swift
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
//
|
||||||
|
// AccountCredentialsTest.swift
|
||||||
|
// AccountTests
|
||||||
|
//
|
||||||
|
// Created by Maurice Parker on 5/4/19.
|
||||||
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import XCTest
|
||||||
|
@testable import Account
|
||||||
|
|
||||||
|
class AccountCredentialsTest: XCTestCase {
|
||||||
|
|
||||||
|
private var account: Account!
|
||||||
|
|
||||||
|
override func setUp() {
|
||||||
|
account = TestAccountManager.shared.createAccount(type: .feedbin, transport: NilTransport())
|
||||||
|
}
|
||||||
|
|
||||||
|
override func tearDown() {
|
||||||
|
TestAccountManager.shared.deleteAccount(account)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testExample() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
Frameworks/Account/AccountTests/NilTransport.swift
Normal file
18
Frameworks/Account/AccountTests/NilTransport.swift
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
//
|
||||||
|
// NilTransport.swift
|
||||||
|
// AccountTests
|
||||||
|
//
|
||||||
|
// Created by Maurice Parker on 5/4/19.
|
||||||
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import RSWeb
|
||||||
|
|
||||||
|
struct NilTransport: Transport {
|
||||||
|
|
||||||
|
func send(request: URLRequest, completion: @escaping (Result<Data, Error>) -> Void) {
|
||||||
|
completion(.success(Data()))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
53
Frameworks/Account/AccountTests/TestAccountManager.swift
Normal file
53
Frameworks/Account/AccountTests/TestAccountManager.swift
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
//
|
||||||
|
// TestAccountManager.swift
|
||||||
|
// AccountTests
|
||||||
|
//
|
||||||
|
// Created by Maurice Parker on 5/4/19.
|
||||||
|
// Copyright © 2019 Ranchero Software, LLC. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import RSWeb
|
||||||
|
|
||||||
|
@testable import Account
|
||||||
|
|
||||||
|
class TestAccountManager {
|
||||||
|
|
||||||
|
static let shared = TestAccountManager()
|
||||||
|
|
||||||
|
var accountsFolder: URL {
|
||||||
|
return FileManager.default.temporaryDirectory
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func createAccount(type: AccountType, username: String? = nil, password: String? = nil, transport: Transport) -> Account {
|
||||||
|
|
||||||
|
let accountID = UUID().uuidString
|
||||||
|
let accountFolder = accountsFolder.appendingPathComponent("\(type.rawValue)_\(accountID)").absoluteString
|
||||||
|
|
||||||
|
do {
|
||||||
|
try FileManager.default.createDirectory(atPath: accountFolder, withIntermediateDirectories: true, attributes: nil)
|
||||||
|
} catch {
|
||||||
|
assertionFailure("Could not create folder for \(accountID) account.")
|
||||||
|
abort()
|
||||||
|
}
|
||||||
|
|
||||||
|
let account = Account(dataFolder: accountFolder, type: type, accountID: accountID, transport: transport)!
|
||||||
|
|
||||||
|
return account
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteAccount(_ account: Account) {
|
||||||
|
|
||||||
|
do {
|
||||||
|
try FileManager.default.removeItem(atPath: account.dataFolder)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
assertionFailure("Could not create folder for OnMyMac account.")
|
||||||
|
abort()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -19,10 +19,10 @@ final class FeedbinAPICaller: NSObject {
|
|||||||
self.transport = transport
|
self.transport = transport
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateCredentials(username: String, password: String, completionHandler handler: @escaping (Result<Bool, Error>) -> Void) {
|
func validateCredentials(credentials: Credentials, completionHandler handler: @escaping (Result<Bool, Error>) -> Void) {
|
||||||
|
|
||||||
let callURL = feedbinBaseURL.appendingPathComponent("authentication.json")
|
let callURL = feedbinBaseURL.appendingPathComponent("authentication.json")
|
||||||
let request = URLRequest(url: callURL, username: username, password: password)
|
let request = URLRequest(url: callURL, credentials: credentials)
|
||||||
|
|
||||||
transport.send(request: request) { result in
|
transport.send(request: request) { result in
|
||||||
switch result {
|
switch result {
|
||||||
|
@ -12,6 +12,7 @@ import RSWeb
|
|||||||
final class FeedbinAccountDelegate: AccountDelegate {
|
final class FeedbinAccountDelegate: AccountDelegate {
|
||||||
|
|
||||||
let supportsSubFolders = false
|
let supportsSubFolders = false
|
||||||
|
let server: String? = "api.feedbin.com"
|
||||||
|
|
||||||
private let caller: FeedbinAPICaller
|
private let caller: FeedbinAPICaller
|
||||||
|
|
||||||
@ -21,10 +22,10 @@ final class FeedbinAccountDelegate: AccountDelegate {
|
|||||||
|
|
||||||
var refreshProgress = DownloadProgress(numberOfTasks: 0)
|
var refreshProgress = DownloadProgress(numberOfTasks: 0)
|
||||||
|
|
||||||
static func validateCredentials(transport: Transport, username: String, password: String, completionHandler handler: @escaping (Result<Bool, Error>) -> Void) {
|
static func validateCredentials(transport: Transport, credentials: Credentials, completionHandler handler: @escaping (Result<Bool, Error>) -> Void) {
|
||||||
|
|
||||||
let caller = FeedbinAPICaller(transport: transport)
|
let caller = FeedbinAPICaller(transport: transport)
|
||||||
caller.validateCredentials(username: username, password: password) { result in
|
caller.validateCredentials(credentials: credentials) { result in
|
||||||
handler(result)
|
handler(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,13 +12,15 @@ import RSWeb
|
|||||||
final class LocalAccountDelegate: AccountDelegate {
|
final class LocalAccountDelegate: AccountDelegate {
|
||||||
|
|
||||||
let supportsSubFolders = false
|
let supportsSubFolders = false
|
||||||
|
let server: String? = nil
|
||||||
|
|
||||||
private let refresher = LocalAccountRefresher()
|
private let refresher = LocalAccountRefresher()
|
||||||
|
|
||||||
var refreshProgress: DownloadProgress {
|
var refreshProgress: DownloadProgress {
|
||||||
return refresher.progress
|
return refresher.progress
|
||||||
}
|
}
|
||||||
|
|
||||||
static func validateCredentials(transport: Transport, username: String, password: String, completionHandler handler: (Result<Bool, Error>) -> Void) {
|
static func validateCredentials(transport: Transport, credentials: Credentials, completionHandler handler: (Result<Bool, Error>) -> Void) {
|
||||||
return handler(.success(false))
|
return handler(.success(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import AppKit
|
import AppKit
|
||||||
import Account
|
import Account
|
||||||
|
import RSWeb
|
||||||
|
|
||||||
class AccountsAddFeedbinWindowController: NSWindowController, NSTextFieldDelegate {
|
class AccountsAddFeedbinWindowController: NSWindowController, NSTextFieldDelegate {
|
||||||
|
|
||||||
@ -52,7 +53,8 @@ class AccountsAddFeedbinWindowController: NSWindowController, NSTextFieldDelegat
|
|||||||
progressIndicator.isHidden = false
|
progressIndicator.isHidden = false
|
||||||
progressIndicator.startAnimation(self)
|
progressIndicator.startAnimation(self)
|
||||||
|
|
||||||
Account.validateCredentials(type: .feedbin, username: usernameTextField.stringValue, password: passwordTextField.stringValue) { [weak self] result in
|
let credentials = BasicCredentials(username: usernameTextField.stringValue, password: passwordTextField.stringValue)
|
||||||
|
Account.validateCredentials(type: .feedbin, credentials: credentials) { [weak self] result in
|
||||||
|
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
|
||||||
@ -65,7 +67,7 @@ class AccountsAddFeedbinWindowController: NSWindowController, NSTextFieldDelegat
|
|||||||
|
|
||||||
if authenticated {
|
if authenticated {
|
||||||
let account = AccountManager.shared.createAccount(type: .feedbin)
|
let account = AccountManager.shared.createAccount(type: .feedbin)
|
||||||
account.storeCredentials(username: self.usernameTextField.stringValue, password: self.passwordTextField.stringValue)
|
account.storeCredentials(credentials)
|
||||||
|
|
||||||
self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK)
|
self.hostWindow?.endSheet(self.window!, returnCode: NSApplication.ModalResponse.OK)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 6c9cab0e15bc4299e84866783fd59268e72d1771
|
Subproject commit 4ea1f13bbdea2c07d52a7b66909f1e6ae5ba13bf
|
@ -1 +1 @@
|
|||||||
Subproject commit 039427d62d8efdfc43d541518afbd46d0147967d
|
Subproject commit eae66d829ff8beaf4ce0694d768bd5cb242fbacd
|
Loading…
x
Reference in New Issue
Block a user