Skip to content

Commit d49d20f

Browse files
author
Daniel Browne
committed
Move model objects to their own source files
1 parent 874e401 commit d49d20f

15 files changed

+132
-124
lines changed

Sources/Helpers/PusherEventFactory.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,3 @@ struct PusherConcreteEventFactory: PusherEventFactory {
4545
// MARK: - Types
4646

4747
typealias PusherEventPayload = [String: Any]
48-
49-
// MARK: - Error handling
50-
51-
enum PusherEventError: Error {
52-
53-
case invalidFormat
54-
case invalidDecryptionKey
55-
case invalidEncryptedData
56-
}

Sources/Models/AuthMethod.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Foundation
2+
3+
public enum AuthMethod {
4+
case endpoint(authEndpoint: String)
5+
case authRequestBuilder(authRequestBuilder: AuthRequestBuilderProtocol)
6+
case authorizer(authorizer: Authorizer)
7+
case inline(secret: String)
8+
case noMethod
9+
}

Sources/Models/ConnectionState.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Foundation
2+
3+
@objc public enum ConnectionState: Int {
4+
case connecting
5+
case connected
6+
case disconnecting
7+
case disconnected
8+
case reconnecting
9+
10+
static let connectionStates = [
11+
connecting: "connecting",
12+
connected: "connected",
13+
disconnecting: "disconnecting",
14+
disconnected: "disconnected",
15+
reconnecting: "reconnecting"
16+
]
17+
18+
public func stringValue() -> String {
19+
return ConnectionState.connectionStates[self]!
20+
}
21+
}

Sources/Models/EventHandler.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Foundation
2+
3+
public struct EventHandler {
4+
let id: String
5+
let callback: (PusherEvent) -> Void
6+
}

Sources/Models/PusherAuth.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Foundation
2+
3+
@objc public class PusherAuth: NSObject {
4+
public let auth: String
5+
public let channelData: String?
6+
public let sharedSecret: String?
7+
8+
public init(auth: String, channelData: String? = nil, sharedSecret: String? = nil) {
9+
self.auth = auth
10+
self.channelData = channelData
11+
self.sharedSecret = sharedSecret
12+
}
13+
}

Sources/Models/PusherAuthError.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Foundation
2+
3+
struct PusherAuthError: Error {
4+
enum Kind {
5+
case notConnected
6+
case noMethod
7+
case couldNotBuildRequest
8+
case invalidAuthResponse
9+
case requestFailure
10+
}
11+
12+
let kind: Kind
13+
14+
var message: String?
15+
16+
var response: URLResponse?
17+
var data: String?
18+
var error: NSError?
19+
}

Sources/Models/PusherChannel.swift

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
import Foundation
22

3-
public enum PusherChannelType {
4-
case `private`
5-
case presence
6-
case normal
7-
8-
public init(name: String) {
9-
self = Self.type(forName: name)
10-
}
11-
12-
public static func type(forName name: String) -> PusherChannelType {
13-
if name.components(separatedBy: "-")[0] == Constants.ChannelTypes.presence {
14-
return .presence
15-
} else if name.components(separatedBy: "-")[0] == Constants.ChannelTypes.private {
16-
return .private
17-
} else {
18-
return .normal
19-
}
20-
}
21-
22-
public static func isPresenceChannel(name: String) -> Bool {
23-
return PusherChannelType(name: name) == .presence
24-
}
25-
}
26-
273
@objcMembers
284
open class PusherChannel: NSObject {
295
// Access via queue for thread safety if user binds/unbinds events to a channel off the main queue
@@ -202,13 +178,3 @@ open class PusherChannel: NSObject {
202178
}
203179
}
204180
}
205-
206-
public struct EventHandler {
207-
let id: String
208-
let callback: (PusherEvent) -> Void
209-
}
210-
211-
public struct QueuedClientEvent {
212-
public let name: String
213-
public let data: Any
214-
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Foundation
2+
3+
public enum PusherChannelType {
4+
case `private`
5+
case presence
6+
case normal
7+
8+
public init(name: String) {
9+
self = Self.type(forName: name)
10+
}
11+
12+
public static func type(forName name: String) -> PusherChannelType {
13+
if name.components(separatedBy: "-")[0] == Constants.ChannelTypes.presence {
14+
return .presence
15+
} else if name.components(separatedBy: "-")[0] == Constants.ChannelTypes.private {
16+
return .private
17+
} else {
18+
return .normal
19+
}
20+
}
21+
22+
public static func isPresenceChannel(name: String) -> Bool {
23+
return PusherChannelType(name: name) == .presence
24+
}
25+
}

Sources/Models/PusherClientOptions.swift

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
import Foundation
22

3-
public enum PusherHost {
4-
case host(String)
5-
case cluster(String)
6-
7-
public var stringValue: String {
8-
switch self {
9-
case .host(let host): return host
10-
case .cluster(let cluster): return "ws-\(cluster).pusher.com"
11-
}
12-
}
13-
}
14-
15-
public enum AuthMethod {
16-
case endpoint(authEndpoint: String)
17-
case authRequestBuilder(authRequestBuilder: AuthRequestBuilderProtocol)
18-
case authorizer(authorizer: Authorizer)
19-
case inline(secret: String)
20-
case noMethod
21-
}
22-
233
@objcMembers
244
@objc public class PusherClientOptions: NSObject {
255
public var authMethod: AuthMethod

Sources/Models/PusherEventError.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Foundation
2+
3+
enum PusherEventError: Error {
4+
5+
case invalidFormat
6+
case invalidDecryptionKey
7+
case invalidEncryptedData
8+
}

0 commit comments

Comments
 (0)