// // XCBManager.swift // Tusker // // Created by Shadowfacts on 9/23/18. // Copyright © 2018 Shadowfacts. All rights reserved. // import UIKit class XCBManager { static var specs: [XCallbackURLSpec] = [ // Statuses XCallbackURLSpec(type: .postStatus, arguments: ["mentioning": true, "text": true], canRunSilently: true, action: XCBActions.postStatus), // Accounts XCallbackURLSpec(type: .getCurrentUser, arguments: [:], canRunSilently: false, action: XCBActions.getCurrentUser) ] static var currentSession: XCBSession? static func handle(url: URL) -> Bool { guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else { return false } if let spec = specs.first(where: { $0.matches(components) }) { let xcbURL = XCallbackURL(spec: spec, components: components) return spec.handle(url: xcbURL) } return false } static func createSession(type: XCBActionType, url: XCallbackURL) -> XCBSession { let session = XCBSession(type: type, success: url.success, error: url.error, cancel: url.cancel) currentSession = session return session } }