Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/Knock.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "KnockTests"
BuildableName = "KnockTests"
BlueprintName = "KnockTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand Down
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ let package = Package(
.target(
name: "Knock",
dependencies: ["SwiftPhoenixClient"],
path: "Sources"
),
path: "Sources"),

.testTarget(
name: "KnockTests",
dependencies: ["Knock"]),
]
)
8 changes: 0 additions & 8 deletions Sources/Helpers/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@ internal extension Knock {
}
return tokenParts.joined()
}

func performActionWithUserId<T>(_ action: @escaping (String, @escaping (Result<T, Error>) -> Void) -> Void, completionHandler: @escaping (Result<T, Error>) -> Void) {
guard let userId = self.userId else {
completionHandler(.failure(KnockError.userIdError))
return
}
action(userId, completionHandler)
}
}

struct DynamicCodingKey: CodingKey {
Expand Down
70 changes: 36 additions & 34 deletions Sources/Knock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,66 @@
//

import SwiftUI
import OSLog

// Knock client SDK.
public class Knock {
internal static let clientVersion = "1.0.0"
internal static let loggingSubsytem = "knock-swift"

internal var api: KnockAPI
public static var shared: Knock = Knock()

public var feedManager: FeedManager?

internal let environment = KnockEnvironment()
internal lazy var authenticationModule = AuthenticationModule()
internal lazy var userModule = UserModule()
internal lazy var preferenceModule = PreferenceModule()
internal lazy var messageModule = MessageModule()
internal lazy var channelModule = ChannelModule()
internal lazy var logger = KnockLogger()

public internal(set) var feedManager: FeedManager?
public internal(set) var userId: String?
public internal(set) var pushChannelId: String?
public internal(set) var userDeviceToken: String?

/**
Returns a new instance of the Knock Client

- Parameters:
- publishableKey: your public API key
- userId: the user-id that will be used in the subsequent method calls
- userToken: [optional] user token. Used in production when enhanced security is enabled
- options: [optional] Options for customizing the Knock instance.
*/
public init(publishableKey: String, options: KnockOptions? = nil) {
self.api = KnockAPI(publishableKey: publishableKey, hostname: options?.host)
public func setup(publishableKey: String, pushChannelId: String?, options: Knock.KnockStartupOptions? = nil) throws {
logger.loggingDebugOptions = options?.debuggingType ?? .errorsOnly
try environment.setPublishableKey(key: publishableKey)
environment.setBaseUrl(baseUrl: options?.hostname)
environment.pushChannelId = pushChannelId
}

internal func resetInstance() {
self.userId = nil
self.feedManager = nil
self.userDeviceToken = nil
self.pushChannelId = nil
self.api.userToken = nil
public func resetInstanceCompletely() {
Knock.shared = Knock()
}
}

public extension Knock {
// Configuration options for the Knock client SDK.
struct KnockOptions {
var host: String?

public init(host: String? = nil) {
self.host = host
struct KnockStartupOptions {
public init(hostname: String? = nil, debuggingType: DebugOptions = .errorsOnly) {
self.hostname = hostname
self.debuggingType = debuggingType
}
var hostname: String?
var debuggingType: DebugOptions
}

enum KnockError: Error {
case runtimeError(String)
case userIdError
enum DebugOptions {
case errorsOnly
case verbose
case none
}
}

extension Knock.KnockError: LocalizedError {
public var errorDescription: String? {
switch self {
case .runtimeError(let message):
return message
case .userIdError:
return "UserId not found. Please authenticate your userId with Knock.authenticate()."
}
public extension Knock {
var userId: String? {
get { return environment.userId }
}

var apnsDeviceToken: String? {
get { return environment.userId }
}
}
205 changes: 0 additions & 205 deletions Sources/KnockAPI.swift

This file was deleted.

Loading