Compare commits

...

6 Commits

Author SHA1 Message Date
Peter Zignego c2f3731a69 Swift 4 2018-02-18 22:46:32 -05:00
Peter Zignego 48f80cc13d Merge pull request #121 from emorydunn/multispace
Multiple Workspace Support
2018-01-23 18:10:17 -05:00
Emory Dunn 0396d9c6d5 Add ClientConnection to Xcode 2018-01-22 14:44:46 -08:00
Emory Dunn 3514b637c8 Preserve compatibility with previous version
Add computed properties for `rtm` and `webAPI` that return the first client’s connections.
2017-12-28 22:45:10 -08:00
Emory Dunn 78ce839cc1 Move ClientConnection class to its own file 2017-12-28 22:36:38 -08:00
Emory Dunn 831bb20ff7 Add multiple client support
Add a new `ClientConnection` class to hold each client’s `Client`, RTM, and WebAPI connections.
2017-12-28 22:20:37 -08:00
12 changed files with 147 additions and 77 deletions
+1 -1
View File
@@ -1 +1 @@
3.1.1
4.0
+4 -4
View File
@@ -1,4 +1,4 @@
github "SlackKit/SKCore" >= 4.0.0
github "SlackKit/SKClient" >= 4.0.0
github "SlackKit/SKRTMAPI" >= 4.0.0
github "SlackKit/SKServer" >= 4.0.0
github "SlackKit/SKCore" >= 4.1.0
github "SlackKit/SKClient" >= 4.1.0
github "SlackKit/SKRTMAPI" >= 4.1.0
github "SlackKit/SKServer" >= 4.1.0
+12 -6
View File
@@ -1,14 +1,20 @@
// swift-tools-version:4.0
import PackageDescription
let package = Package(
name: "SlackKit",
targets: [
Target(name: "SlackKit")
products: [
.library(name: "SlackKit", targets: ["SlackKit"])
],
dependencies: [
.Package(url: "https://github.com/SlackKit/SKCore", majorVersion: 4),
.Package(url: "https://github.com/SlackKit/SKClient", majorVersion: 4),
.Package(url: "https://github.com/SlackKit/SKRTMAPI", majorVersion: 4),
.Package(url: "https://github.com/SlackKit/SKServer", majorVersion: 4)
.package(url: "https://github.com/SlackKit/SKCore", .upToNextMinor(from: "4.1.0")),
.package(url: "https://github.com/SlackKit/SKClient", .upToNextMinor(from: "4.1.0")),
.package(url: "https://github.com/SlackKit/SKRTMAPI", .upToNextMinor(from: "4.1.0")),
.package(url: "https://github.com/SlackKit/SKServer", .upToNextMinor(from: "4.1.0"))
],
targets: [
.target(name: "SlackKit",
dependencies: ["SKCore", "SKClient", "SKRTMAPI", "SKServer"],
path: "Sources")
]
)
+15 -15
View File
@@ -2,27 +2,27 @@ use_frameworks!
target 'SlackKit macOS' do
platform :osx, '10.11'
pod 'SKCore'
pod 'SKClient'
pod 'SKWebAPI'
pod 'SKRTMAPI'
pod 'SKServer'
pod 'SKCore', '~> 4.1.0'
pod 'SKClient', '~> 4.1.0'
pod 'SKWebAPI', '~> 4.1.0'
pod 'SKRTMAPI', '~> 4.1.0'
pod 'SKServer', '~> 4.1.0'
end
target 'SlackKit iOS' do
platform :ios, '9.0'
pod 'SKCore'
pod 'SKClient'
pod 'SKWebAPI'
pod 'SKRTMAPI'
pod 'SKServer'
pod 'SKCore', '~> 4.1.0'
pod 'SKClient', '~> 4.1.0'
pod 'SKWebAPI', '~> 4.1.0'
pod 'SKRTMAPI', '~> 4.1.0'
pod 'SKServer', '~> 4.1.0'
end
target 'SlackKit tvOS' do
platform :tvos, '9.0'
pod 'SKCore'
pod 'SKClient'
pod 'SKWebAPI'
pod 'SKRTMAPI'
pod 'SKServer'
pod 'SKCore', '~> 4.1.0'
pod 'SKClient', '~> 4.1.0'
pod 'SKWebAPI', '~> 4.1.0'
pod 'SKRTMAPI', '~> 4.1.0'
pod 'SKServer', '~> 4.1.0'
end
+3 -2
View File
@@ -1,6 +1,6 @@
<p align="center"><img src="https://cloud.githubusercontent.com/assets/8311605/24083714/e921a0d4-0cb2-11e7-8384-d42113ef5056.png" alt="SlackKit" width="500"/></p>
![Swift Version](https://img.shields.io/badge/Swift-3.1.1-orange.svg)
![Swift Version](https://img.shields.io/badge/Swift-4.0.3-orange.svg)
![Plaforms](https://img.shields.io/badge/Platforms-macOS,iOS,tvOS,Linux-lightgrey.svg)
![License MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg)
[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)
@@ -25,10 +25,11 @@ import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/SlackKit/SlackKit.git", majorVersion: 4)
.package(url: "https://github.com/SlackKit/SlackKit.git", .upToNextMinor(from: "4.1.0"))
]
)
```
#### Carthage
Add `SlackKit` to your `Cartfile`:
+18 -18
View File
@@ -1,20 +1,20 @@
Pod::Spec.new do |s|
s.name = "SlackKit"
s.version = "4.0.0"
s.summary = "Write Slack apps in Swift"
s.homepage = "https://github.com/pvzig/SlackKit"
s.license = 'MIT'
s.author = { "Peter Zignego" => "peter@launchsoft.co" }
s.source = { :git => "https://github.com/SlackKit/SlackKit.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/pvzig'
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.11'
s.tvos.deployment_target = '9.0'
s.requires_arc = true
s.source_files = 'Sources/*.swift'
s.frameworks = 'Foundation'
s.dependency 'SKCore'
s.dependency 'SKClient'
s.dependency 'SKRTMAPI'
s.dependency 'SKServer'
s.name = "SlackKit"
s.version = "4.1.0"
s.summary = "Write Slack apps in Swift"
s.homepage = "https://github.com/pvzig/SlackKit"
s.license = 'MIT'
s.author = { "Peter Zignego" => "peter@launchsoft.co" }
s.source = { :git => "https://github.com/SlackKit/SlackKit.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/pvzig'
s.ios.deployment_target = '9.0'
s.osx.deployment_target = '10.11'
s.tvos.deployment_target = '9.0'
s.requires_arc = true
s.source_files = 'Sources/*.swift'
s.frameworks = 'Foundation'
s.dependency 'SKCore'
s.dependency 'SKClient'
s.dependency 'SKRTMAPI'
s.dependency 'SKServer'
end
+29 -7
View File
@@ -31,6 +31,9 @@
26D1C51E1EE476DD00C95954 /* SKWebAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26D1C5171EE476DD00C95954 /* SKWebAPI.framework */; };
26D1C51F1EE476DD00C95954 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26D1C5181EE476DD00C95954 /* Starscream.framework */; };
26D1C5201EE476DD00C95954 /* Swifter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26D1C5191EE476DD00C95954 /* Swifter.framework */; };
627B38152016A0B50029FDC1 /* ClientConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 627B38142016A0B50029FDC1 /* ClientConnection.swift */; };
627B38162016A0B50029FDC1 /* ClientConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 627B38142016A0B50029FDC1 /* ClientConnection.swift */; };
627B38172016A0B50029FDC1 /* ClientConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 627B38142016A0B50029FDC1 /* ClientConnection.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -60,6 +63,7 @@
26D1C5171EE476DD00C95954 /* SKWebAPI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SKWebAPI.framework; path = Carthage/Build/tvOS/SKWebAPI.framework; sourceTree = "<group>"; };
26D1C5181EE476DD00C95954 /* Starscream.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Starscream.framework; path = Carthage/Build/tvOS/Starscream.framework; sourceTree = "<group>"; };
26D1C5191EE476DD00C95954 /* Swifter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Swifter.framework; path = Carthage/Build/tvOS/Swifter.framework; sourceTree = "<group>"; };
627B38142016A0B50029FDC1 /* ClientConnection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClientConnection.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -112,6 +116,7 @@
isa = PBXGroup;
children = (
266687041E95CB9F00777D94 /* SlackKit.swift */,
627B38142016A0B50029FDC1 /* ClientConnection.swift */,
);
path = Sources;
sourceTree = SOURCE_ROOT;
@@ -271,7 +276,7 @@
2684F1741E95AA6900536DCC /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0830;
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = "Peter Zignego";
TargetAttributes = {
2684F17C1E95AA6900536DCC = {
@@ -379,6 +384,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
627B38152016A0B50029FDC1 /* ClientConnection.swift in Sources */,
266687051E95CB9F00777D94 /* SlackKit.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -387,6 +393,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
627B38162016A0B50029FDC1 /* ClientConnection.swift in Sources */,
266687061E95CB9F00777D94 /* SlackKit.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -395,6 +402,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
627B38172016A0B50029FDC1 /* ClientConnection.swift in Sources */,
266687071E95CB9F00777D94 /* SlackKit.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -412,7 +420,9 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
@@ -420,7 +430,11 @@
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -450,6 +464,7 @@
SDKROOT = macosx;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
@@ -465,7 +480,9 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
@@ -473,7 +490,11 @@
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -495,6 +516,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
@@ -523,7 +545,7 @@
PRODUCT_NAME = SlackKit;
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
@@ -550,7 +572,7 @@
PRODUCT_NAME = SlackKit;
PROVISIONING_PROFILE_SPECIFIER = "";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
@@ -577,7 +599,7 @@
PRODUCT_NAME = SlackKit;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
@@ -604,7 +626,7 @@
PRODUCT_NAME = SlackKit;
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
@@ -630,7 +652,7 @@
PRODUCT_NAME = SlackKit;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Debug;
@@ -657,7 +679,7 @@
PRODUCT_NAME = SlackKit;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Release;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
@@ -36,6 +37,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
@@ -36,6 +37,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0830"
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
@@ -36,6 +37,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
+20
View File
@@ -0,0 +1,20 @@
//
// ClientConnection.swift
// SlackKit
//
// Created by Emory Dunn on 12/28/17.
//
import Foundation
public class ClientConnection {
public var client: Client?
public var rtm: SKRTMAPI?
public var webAPI: WebAPI?
public init(client: Client?, rtm: SKRTMAPI?, webAPI: WebAPI?) {
self.client = client
self.rtm = rtm
self.webAPI = webAPI
}
}
+36 -21
View File
@@ -30,18 +30,30 @@ import Foundation
public final class SlackKit: RTMAdapter {
public typealias EventClosure = (Event, Client?) -> Void
public typealias EventClosure = (Event, ClientConnection?) -> Void
internal typealias TypedEvent = (EventType, EventClosure)
internal var callbacks = [TypedEvent]()
internal(set) public var rtm: SKRTMAPI?
internal(set) public var server: SKServer?
internal(set) public var webAPI: WebAPI?
internal(set) public var clients: [String: Client] = [:]
internal(set) public var clients: [String: ClientConnection] = [:]
/// Return the `SKRTMAPI` instance of the first client
public var rtm: SKRTMAPI? {
return clients.values.first?.rtm
}
/// Return the `WebAPI` instance of the first client
public var webAPI: WebAPI? {
return clients.values.first?.webAPI
}
public init() {}
public func addWebAPIAccessWithToken(_ token: String) {
self.webAPI = WebAPI(token: token)
let webAPI = WebAPI(token: token)
if let clientConnection = clients[token] {
clientConnection.webAPI = webAPI
} else {
clients[token] = ClientConnection(client: nil, rtm: nil, webAPI: webAPI)
}
}
public func addRTMBotWithAPIToken(
@@ -50,10 +62,15 @@ public final class SlackKit: RTMAdapter {
options: RTMOptions = RTMOptions(),
rtm: RTMWebSocket? = nil
) {
self.rtm = SKRTMAPI(withAPIToken: token, options: options, rtm: rtm)
self.rtm?.adapter = self
clients[token] = client
self.rtm?.connect()
let rtm = SKRTMAPI(withAPIToken: token, options: options, rtm: rtm)
rtm.adapter = self
if let clientConnection = clients[token] {
clientConnection.rtm = rtm
} else {
clients[token] = ClientConnection(client: client, rtm: rtm, webAPI: nil)
}
clients[token]?.rtm?.connect()
}
public func addServer(_ server: SlackKitServer? = nil, responder: SlackKitResponder? = nil, oauth: OAuthConfig? = nil) {
@@ -69,15 +86,11 @@ public final class SlackKit: RTMAdapter {
let oauth = OAuthMiddleware(config: config) { authorization in
// User
if let token = authorization.accessToken {
self.webAPI = WebAPI(token: token)
self.addWebAPIAccessWithToken(token)
}
// Bot User
if let token = authorization.bot?.botToken {
self.webAPI = WebAPI(token: token)
self.rtm = SKRTMAPI(withAPIToken: token, options: RTMOptions(), rtm: nil)
self.rtm?.adapter = self
self.clients[token] = Client()
self.rtm?.connect()
self.addRTMBotWithAPIToken(token)
}
}
return RequestRoute(path: "/oauth", middleware: oauth)
@@ -85,24 +98,26 @@ public final class SlackKit: RTMAdapter {
// MARK: - RTM Adapter
public func initialSetup(json: [String: Any], instance: SKRTMAPI) {
clients[instance.token]?.initialSetup(JSON: json)
clients[instance.token]?.client?.initialSetup(JSON: json)
}
public func notificationForEvent(_ event: Event, type: EventType, instance: SKRTMAPI) {
let client = clients[instance.token]
client?.notificationForEvent(event, type: type)
executeCallbackForEvent(event, type: type, client: client)
let clientConnection = clients[instance.token]
clientConnection?.client?.notificationForEvent(event, type: type)
executeCallbackForEvent(event, type: type, clientConnection: clientConnection)
}
public func connectionClosed(with error: Error, instance: SKRTMAPI) {}
// MARK: - Callbacks
public func notificationForEvent(_ type: EventType, event: @escaping EventClosure) {
callbacks.append((type, event))
}
private func executeCallbackForEvent(_ event: Event, type: EventType, client: Client?) {
private func executeCallbackForEvent(_ event: Event, type: EventType, clientConnection: ClientConnection?) {
let cbs = callbacks.filter {$0.0 == type}
for callback in cbs {
callback.1(event, client)
callback.1(event, clientConnection)
}
}
}