35 lines
1.0 KiB
Swift
35 lines
1.0 KiB
Swift
//
|
|
// XCBManager.swift
|
|
// Tusker
|
|
//
|
|
// Created by Shadowfacts on 9/23/18.
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class XCBManager {
|
|
|
|
static var specs: [XCallbackURLSpec] = [
|
|
XCallbackURLSpec(path: "/postStatus", arguments: ["mentioning": true, "text": true, "silent": true], handle: XCBActions.postStatus)
|
|
]
|
|
|
|
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(xcbURL)
|
|
}
|
|
return false
|
|
}
|
|
|
|
static func createSession(type: XCBSessionType, url: XCallbackURL) -> XCBSession {
|
|
let session = XCBSession(type: type, success: url.success, error: url.error, cancel: url.cancel)
|
|
currentSession = session
|
|
return session
|
|
}
|
|
|
|
}
|