This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol OfflineController { | |
func cache(request: OfflineRequestConvertible, forId id: String?, encryptionKey: String?, data: Data, keepAliveUntil keepAlive: Date?, completion: @escaping OfflineControllerCompletionHandler) | |
func get(request: OfflineRequestConvertible, forId id: String?, encryptionKey: String?, ifBefore before: Date?, completion: @escaping OfflineControllerCompletionHandler) | |
func delete(request: OfflineRequestConvertible, forId id: String?, encryptionKey: String?, completion: @escaping OfflineControllerCompletionHandler) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OfflineActionBuilder | |
.toCache("https://www.medium.com") | |
.data(data) | |
.forId("id1") | |
.keepingAliveUntil(Date()) | |
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OfflineActionBuilder | |
.toCache("https://www.medium.com") | |
.ifBefore(Date()) | |
.keepingAliveUntil(Date()) | |
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct OfflineAction { | |
enum `Type` { | |
case cache, get, delete | |
} | |
fileprivate(set) var type: Type? | |
fileprivate(set) var request: OfflineRequestConvertible? | |
fileprivate(set) var data: Data? | |
fileprivate(set) var id: String? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol BuildStep { | |
func build() -> OfflineAction | |
} | |
protocol RequestStep { | |
func toCache(_ request: OfflineRequestConvertible) -> DataStep | |
func toGet(_ request: OfflineRequestConvertible) -> GetCommonsStep | |
func toDelete(_ request: OfflineRequestConvertible) -> CommonsStep | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension OfflineActionBuilder: RequestStep, DataStep, CommonsStep, CacheCommonsStep, GetCommonsStep { | |
func toCache(_ request: OfflineRequestConvertible) -> DataStep { | |
action.type = .cache | |
action.request = request | |
return self as DataStep | |
} | |
func toGet(_ request: OfflineRequestConvertible) -> GetCommonsStep { | |
action.type = .get |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cache = OfflineActionBuilder.builder | |
.toCache("https://www.medium.com") | |
.data(Data()) | |
.forId("id") | |
.keepingAliveUntil(Date()) | |
.build() | |
let get = OfflineActionBuilder.builder | |
.toGet("https://www.medium.com") | |
.withEncryptionKey("encryptionKey") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol OfflineController { | |
func execute(action: OfflineAction, completion: @escaping OfflineControllerCompletionHandler) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OfflineActionBuilder { | |
fileprivate var action: OfflineAction! | |
init() { | |
fatalError("This type cannot be constructed directly, use static var 'builder' instead.") | |
} | |
private init(_ action: OfflineAction) { | |
self.action = action |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
protocol OfflineRequestConvertible {} | |
extension String: OfflineRequestConvertible {} | |
struct OfflineAction { | |
enum `Type` { |