omnivore/apple/OmnivoreKit/Sources/Models/DeepLinkDecoder.swift

46 lines
1,000 B
Swift
Raw Normal View History

2022-02-11 17:24:33 +00:00
import Foundation
2022-05-18 18:38:10 +00:00
public struct LinkRequest: Identifiable, Hashable {
public let id: UUID
public let serverID: String
public init(id: UUID, serverID: String) {
self.id = id
self.serverID = serverID
}
}
2022-02-11 17:24:33 +00:00
public enum DeepLink {
case webAppLinkRequest(requestID: String)
}
public extension DeepLink {
var linkRequestID: String? {
if case let DeepLink.webAppLinkRequest(requestID) = self {
return requestID
}
return nil
}
static func make(from url: URL) -> DeepLink? {
if url.scheme == "omnivore" {
return deepLinkFromOmnivoreScheme(url: url)
}
return nil
}
private static func deepLinkFromOmnivoreScheme(url: URL) -> DeepLink? {
switch url.host {
case "shareExtensionRequestID":
let requestID = url.path.replacingOccurrences(of: "/", with: "")
return .webAppLinkRequest(requestID: requestID)
default:
return nil
}
}
}
// Example deep links
// "omnivore://shareExtensionRequestID/sampleRequestID"