2020-04-16 22:06:56 +02:00
|
|
|
//
|
|
|
|
// FeedProviderManager.swift
|
|
|
|
// Account
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 4/16/20.
|
|
|
|
// Copyright © 2020 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
public protocol FeedProviderManagerDelegate: class {
|
|
|
|
var activeFeedProviders: [FeedProvider] { get }
|
|
|
|
}
|
|
|
|
|
|
|
|
public final class FeedProviderManager {
|
|
|
|
|
|
|
|
public static let shared = FeedProviderManager()
|
|
|
|
public weak var delegate: FeedProviderManagerDelegate?
|
|
|
|
|
2020-04-24 20:33:43 +02:00
|
|
|
public func best(for offered: URLComponents) -> FeedProvider? {
|
|
|
|
if let owner = feedProviderMatching(offered, ability: .owner) {
|
2020-04-16 22:06:56 +02:00
|
|
|
return owner
|
|
|
|
}
|
2020-04-24 20:33:43 +02:00
|
|
|
return feedProviderMatching(offered, ability: .available)
|
2020-04-16 22:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private extension FeedProviderManager {
|
|
|
|
|
2020-04-24 20:33:43 +02:00
|
|
|
func feedProviderMatching(_ offered: URLComponents, ability: FeedProviderAbility) -> FeedProvider? {
|
2020-04-16 22:06:56 +02:00
|
|
|
if let delegate = delegate {
|
|
|
|
for feedProvider in delegate.activeFeedProviders {
|
2020-04-24 20:33:43 +02:00
|
|
|
if feedProvider.ability(offered) == ability {
|
2020-04-16 22:06:56 +02:00
|
|
|
return feedProvider
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|