Compare commits

...

5 Commits

Author SHA1 Message Date
Peter Zignego 2e71ac6876 Bug fix 2016-07-23 11:12:14 -04:00
Peter Zignego c428cac537 Update readme 2016-07-20 21:44:30 -04:00
Peter Zignego 18c6516df9 Remove Cocoapods 2016-07-20 21:32:57 -04:00
Peter Zignego fe450a7db2 Set swift version 2016-07-20 21:32:41 -04:00
Peter Zignego bb57f59553 Swift 3 support 2016-07-20 18:31:03 -04:00
36 changed files with 394 additions and 449 deletions
+1 -1
View File
@@ -1 +1 @@
2.2
3.0
+2 -2
View File
@@ -1,2 +1,2 @@
github "daltoniam/Starscream" ~> 1.0
github "glock45/swifter" "d7c820bfc9260e469094b5f8d3d101b30c4a8fac"
github "https://github.com/pvzig/swifter.git" "master"
github "https://github.com/pvzig/Starscream.git" "swift3"
+2 -2
View File
@@ -1,2 +1,2 @@
github "daltoniam/Starscream" "1.1.3"
github "glock45/swifter" "d7c820bfc9260e469094b5f8d3d101b30c4a8fac"
github "pvzig/Starscream" "98d7ccea30621d51a93ee5c155b3f670e37e037b"
github "pvzig/swifter" "8adfae89a6d34cfea1c20d53d8112d1d69e01bd0"
+3 -3
View File
@@ -27,9 +27,9 @@ let package = Package(
name: "SlackKit",
targets: [],
dependencies: [
.Package(url: "https://github.com/daltoniam/Starscream",
majorVersion: 1),
.Package(url: "https://github.com/httpswift/swifter", majorVersion: 1)
.Package(url: "https://github.com/pvzig/swifter.git",
majorVersion: 1, minor: 3),
.Package(url: "https://github.com/pvzig/Starscream.git", majorVersion: 1, minor: 2)
],
exclude: ["Examples", "Carthage", "Pods"]
)
-18
View File
@@ -1,18 +0,0 @@
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'SlackKit OS X' do
pod 'Starscream'
pod 'Swifter'
end
target 'SlackKit iOS' do
pod 'Starscream'
pod 'Swifter'
end
target 'SlackKit tvOS' do
pod 'Starscream'
pod 'Swifter'
end
-15
View File
@@ -1,15 +0,0 @@
PODS:
- Starscream (1.1.3)
- Swifter (1.2.6)
DEPENDENCIES:
- Starscream
- Swifter
SPEC CHECKSUMS:
Starscream: d662732354b40dd19ed1ece3e3c44c80b536b83c
Swifter: c6f13d053398f1e2f209c7a394dfd5e863ae0157
PODFILE CHECKSUM: 372d57254c34897042ce228cf421d7c9cc5caf9f
COCOAPODS: 1.0.1
+7 -13
View File
@@ -1,29 +1,23 @@
![SlackKit](https://cloud.githubusercontent.com/assets/8311605/10260893/5ec60f96-694e-11e5-91fd-da6845942201.png)
## SlackKit: A Swift Slack Client Library
### Description
This is a Slack client library for OS X, iOS, and tvOS written in Swift. It's intended to expose all of the functionality of Slack's [Real Time Messaging API](https://api.slack.com/rtm) as well as the [web APIs](https://api.slack.com/web) that are accessible to [bot users](https://api.slack.com/bot-users). SlackKit also supports Slacks [OAuth 2.0](https://api.slack.com/docs/oauth) flow including the [Add to Slack](https://api.slack.com/docs/slack-button) and [Sign in with Slack](https://api.slack.com/docs/sign-in-with-slack) buttons, [incoming webhooks](https://api.slack.com/incoming-webhooks), [slash commands](https://api.slack.com/slash-commands), and [message buttons](https://api.slack.com/docs/message-buttons).
SlackKit also has alpha support for: [Swift 3](https://github.com/pvzig/SlackKit/tree/swift3), [Linux](https://github.com/pvzig/SlackKit/tree/linux)
This is the Swift 3 beta branch. It will continue to track the Xcode 8 beta releases until it is officially released, at which point Swift 3 will be merged down to the master branch.
SlackKit also supports: [Swift 2.2](https://github.com/pvzig/SlackKit/), [Linux](https://github.com/pvzig/SlackKit/tree/linux)
This is a Slack client library for OS X, iOS, and tvOS written in Swift. It's intended to expose all of the functionality of Slack's [Real Time Messaging API](https://api.slack.com/rtm) as well as the [web APIs](https://api.slack.com/web) that are accessible to [bot users](https://api.slack.com/bot-users). SlackKit also supports Slacks [OAuth 2.0](https://api.slack.com/docs/oauth) flow including the [Add to Slack](https://api.slack.com/docs/slack-button) and [Sign in with Slack](https://api.slack.com/docs/sign-in-with-slack) buttons, [incoming webhooks](https://api.slack.com/incoming-webhooks), [slash commands](https://api.slack.com/slash-commands), and [message buttons](https://api.slack.com/docs/message-buttons).
#### Building the SlackKit Framework
To build the SlackKit project directly, first build the dependencies using Carthage or CocoaPods. To use the framework in your application, install it in one of the following ways:
### Installation
#### CocoaPods
Add the pod to your podfile:
```
pod 'SlackKit'
```
and run
```
pod install
```
#### Carthage
Add SlackKit to your Cartfile:
```
github "pvzig/SlackKit" ~> 2.0
github "https://github.com/pvzig/slackkit.git" "swift3"
```
and run
```
@@ -42,7 +36,7 @@ import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/pvzig/SlackKit.git", majorVersion: 2)
.Package(url: "https://github.com/pvzig/SlackKit.git", majorVersion: 3)
]
)
```
-19
View File
@@ -1,19 +0,0 @@
Pod::Spec.new do |s|
s.name = "SlackKit"
s.version = "2.0.0"
s.summary = "a Slack client library for OS X, iOS, and tvOS written 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/pvzig/SlackKit.git", :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/pvzig'
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10'
s.tvos.deployment_target = '9.0'
s.requires_arc = true
s.source_files = 'SlackKit/Sources/*.swift'
s.frameworks = 'Foundation'
s.dependency 'Starscream', '~> 1.1.3'
s.dependency 'Swifter'
end
+15 -5
View File
@@ -74,12 +74,10 @@
269B47C81D3AE25B0042D137 /* MessageActionServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B30B8F1D298E08004D4AB5 /* MessageActionServer.swift */; };
269B47C91D3AE2620042D137 /* Server.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B30B911D298E12004D4AB5 /* Server.swift */; };
269B47CA1D3AE2670042D137 /* WebhookServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26EC15001D260B1000FD3A53 /* WebhookServer.swift */; };
269B47CC1D3AE5670042D137 /* Swifter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 269B47CB1D3AE5670042D137 /* Swifter.framework */; };
269B47CE1D3C22FC0042D137 /* ClientOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 269B47CD1D3C22FC0042D137 /* ClientOptions.swift */; };
269B47CF1D3C22FC0042D137 /* ClientOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 269B47CD1D3C22FC0042D137 /* ClientOptions.swift */; };
269B47D01D3C22FC0042D137 /* ClientOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 269B47CD1D3C22FC0042D137 /* ClientOptions.swift */; };
26B30B6C1D289FA0004D4AB5 /* Swifter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26B30B6B1D289FA0004D4AB5 /* Swifter.framework */; };
26B30B6F1D289FB2004D4AB5 /* Swifter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26B30B6E1D289FB2004D4AB5 /* Swifter.framework */; };
26B30B881D297A98004D4AB5 /* MessageActionRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B30B871D297A98004D4AB5 /* MessageActionRequest.swift */; };
26B30B901D298E08004D4AB5 /* MessageActionServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B30B8F1D298E08004D4AB5 /* MessageActionServer.swift */; };
26B30B921D298E12004D4AB5 /* Server.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26B30B911D298E12004D4AB5 /* Server.swift */; };
@@ -147,6 +145,8 @@
26EC14FB1D1F355A00FD3A53 /* Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26EC14F81D1F355A00FD3A53 /* Action.swift */; };
26EC15011D260B1000FD3A53 /* WebhookServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26EC15001D260B1000FD3A53 /* WebhookServer.swift */; };
26EC15021D260B1000FD3A53 /* WebhookServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26EC15001D260B1000FD3A53 /* WebhookServer.swift */; };
26F76EB21D40318F00C3A3DD /* Swifter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26B30B6E1D289FB2004D4AB5 /* Swifter.framework */; };
26F76EB31D40319700C3A3DD /* Swifter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 269B47CB1D3AE5670042D137 /* Swifter.framework */; };
4307A0801CC6D0910011D5DE /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4307A07F1CC6D0910011D5DE /* Starscream.framework */; };
C16C987A1CE7D3DD00692776 /* Client+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C16C98791CE7D3DD00692776 /* Client+Utilities.swift */; };
C1A85FF91CE3BCEF00756C40 /* Client+EventDispatching.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A85FF71CE3BCEF00756C40 /* Client+EventDispatching.swift */; };
@@ -227,7 +227,7 @@
buildActionMask = 2147483647;
files = (
263993AB1CE90EE0004A6E93 /* Starscream.framework in Frameworks */,
26B30B6F1D289FB2004D4AB5 /* Swifter.framework in Frameworks */,
26F76EB21D40318F00C3A3DD /* Swifter.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -236,7 +236,7 @@
buildActionMask = 2147483647;
files = (
263993CA1CE90EED004A6E93 /* Starscream.framework in Frameworks */,
269B47CC1D3AE5670042D137 /* Swifter.framework in Frameworks */,
26F76EB31D40319700C3A3DD /* Swifter.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -452,11 +452,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Launch Software LLC";
TargetAttributes = {
26072A331BB48B3A00CD650C = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
};
};
};
@@ -773,6 +774,7 @@
PRODUCT_NAME = SlackKit;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -798,6 +800,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.launchsoft.SlackKit;
PRODUCT_NAME = SlackKit;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -828,6 +832,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -857,6 +862,8 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -884,6 +891,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvsimulator appletvos";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Debug;
@@ -911,6 +919,8 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvsimulator appletvos";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Release;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
+2 -2
View File
@@ -31,7 +31,7 @@ internal struct AuthorizeRequest {
var parameters: [String: AnyObject] {
var json = [String : AnyObject]()
json["scope"] = scope.map({$0.rawValue}).joinWithSeparator(",")
json["scope"] = scope.map({$0.rawValue}).joined(separator: ",")
json["state"] = state
json["team"] = team
return json
@@ -45,4 +45,4 @@ internal struct AuthorizeRequest {
self.team = team
}
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ internal struct AuthorizeResponse {
let state: String
init?(queryParameters: [(String, String)]) {
guard let code = queryParameters.first?.1, state = queryParameters.last?.1 else {
guard let code = queryParameters.first?.1, let state = queryParameters.last?.1 else {
return nil
}
self.code = code
@@ -23,7 +23,7 @@
internal extension Client {
func dispatch(event: [String: AnyObject]) {
func dispatch(_ event: [String: AnyObject]) {
let event = Event(event: event)
guard let type = event.type else {
return
@@ -160,8 +160,8 @@ internal extension Client {
}
}
func messageDispatcher(event:Event) {
guard let value = event.subtype, subtype = MessageSubtype(rawValue:value) else {
func messageDispatcher(_ event:Event) {
guard let value = event.subtype, let subtype = MessageSubtype(rawValue:value) else {
return
}
switch subtype {
+102 -102
View File
@@ -26,13 +26,13 @@ import Foundation
internal extension Client {
//MARK: - Pong
func pong(event: Event) {
func pong(_ event: Event) {
pong = event.replyTo
}
//MARK: - Messages
func messageSent(event: Event) {
guard let reply = event.replyTo, message = sentMessages[NSNumber(double: reply).stringValue], channel = message.channel, ts = message.ts else {
func messageSent(_ event: Event) {
guard let reply = event.replyTo, let message = sentMessages[NSNumber(value: reply).stringValue], let channel = message.channel, let ts = message.ts else {
return
}
@@ -42,8 +42,8 @@ internal extension Client {
messageEventsDelegate?.messageSent(self, message: message)
}
func messageReceived(event: Event) {
guard let channel = event.channel, message = event.message, id = channel.id, ts = message.ts else {
func messageReceived(_ event: Event) {
guard let channel = event.channel, let message = event.message, let id = channel.id, let ts = message.ts else {
return
}
@@ -51,8 +51,8 @@ internal extension Client {
messageEventsDelegate?.messageReceived(self, message: message)
}
func messageChanged(event: Event) {
guard let id = event.channel?.id, nested = event.nestedMessage, ts = nested.ts else {
func messageChanged(_ event: Event) {
guard let id = event.channel?.id, let nested = event.nestedMessage, let ts = nested.ts else {
return
}
@@ -60,35 +60,35 @@ internal extension Client {
messageEventsDelegate?.messageChanged(self, message: nested)
}
func messageDeleted(event: Event) {
guard let id = event.channel?.id, key = event.message?.deletedTs, message = channels[id]?.messages[key] else {
func messageDeleted(_ event: Event) {
guard let id = event.channel?.id, let key = event.message?.deletedTs, let message = channels[id]?.messages[key] else {
return
}
channels[id]?.messages.removeValueForKey(key)
_ = channels[id]?.messages.removeValue(forKey: key)
messageEventsDelegate?.messageDeleted(self, message: message)
}
//MARK: - Channels
func userTyping(event: Event) {
guard let channel = event.channel, channelID = channel.id, user = event.user, userID = user.id where
channels.indexForKey(channelID) != nil && !channels[channelID]!.usersTyping.contains(userID) else {
func userTyping(_ event: Event) {
guard let channel = event.channel, let channelID = channel.id, let user = event.user, let userID = user.id ,
channels.index(forKey: channelID) != nil && !channels[channelID]!.usersTyping.contains(userID) else {
return
}
channels[channelID]?.usersTyping.append(userID)
channelEventsDelegate?.userTyping(self, channel: channel, user: user)
let timeout = dispatch_time(DISPATCH_TIME_NOW, Int64(5.0 * Double(NSEC_PER_SEC)))
dispatch_after(timeout, dispatch_get_main_queue()) {
if let index = self.channels[channelID]?.usersTyping.indexOf(userID) {
self.channels[channelID]?.usersTyping.removeAtIndex(index)
let timeout = DispatchTime.now() + Double(Int64(5.0 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
DispatchQueue.main.after(when: timeout) {
if let index = self.channels[channelID]?.usersTyping.index(of: userID) {
self.channels[channelID]?.usersTyping.remove(at: index)
}
}
}
func channelMarked(event: Event) {
guard let channel = event.channel, id = channel.id, timestamp = event.ts else {
func channelMarked(_ event: Event) {
guard let channel = event.channel, let id = channel.id, let timestamp = event.ts else {
return
}
@@ -96,8 +96,8 @@ internal extension Client {
channelEventsDelegate?.channelMarked(self, channel: channel, timestamp: timestamp)
}
func channelCreated(event: Event) {
guard let channel = event.channel, id = channel.id else {
func channelCreated(_ event: Event) {
guard let channel = event.channel, let id = channel.id else {
return
}
@@ -105,17 +105,17 @@ internal extension Client {
channelEventsDelegate?.channelCreated(self, channel: channel)
}
func channelDeleted(event: Event) {
guard let channel = event.channel, id = channel.id else {
func channelDeleted(_ event: Event) {
guard let channel = event.channel, let id = channel.id else {
return
}
channels.removeValueForKey(id)
channels.removeValue(forKey: id)
channelEventsDelegate?.channelDeleted(self, channel: channel)
}
func channelJoined(event: Event) {
guard let channel = event.channel, id = channel.id else {
func channelJoined(_ event: Event) {
guard let channel = event.channel, let id = channel.id else {
return
}
@@ -123,19 +123,19 @@ internal extension Client {
channelEventsDelegate?.channelJoined(self, channel: channel)
}
func channelLeft(event: Event) {
guard let channel = event.channel, id = channel.id else {
func channelLeft(_ event: Event) {
guard let channel = event.channel, let id = channel.id else {
return
}
if let userID = authenticatedUser?.id, index = channels[id]?.members?.indexOf(userID) {
channels[id]?.members?.removeAtIndex(index)
if let userID = authenticatedUser?.id, let index = channels[id]?.members?.index(of: userID) {
channels[id]?.members?.remove(at: index)
}
channelEventsDelegate?.channelLeft(self, channel: channel)
}
func channelRenamed(event: Event) {
guard let channel = event.channel, id = channel.id else {
func channelRenamed(_ event: Event) {
guard let channel = event.channel, let id = channel.id else {
return
}
@@ -143,8 +143,8 @@ internal extension Client {
channelEventsDelegate?.channelRenamed(self, channel: channel)
}
func channelArchived(event: Event, archived: Bool) {
guard let channel = event.channel, id = channel.id else {
func channelArchived(_ event: Event, archived: Bool) {
guard let channel = event.channel, let id = channel.id else {
return
}
@@ -152,7 +152,7 @@ internal extension Client {
channelEventsDelegate?.channelArchived(self, channel: channel)
}
func channelHistoryChanged(event: Event) {
func channelHistoryChanged(_ event: Event) {
guard let channel = event.channel else {
return
}
@@ -160,7 +160,7 @@ internal extension Client {
}
//MARK: - Do Not Disturb
func doNotDisturbUpdated(event: Event) {
func doNotDisturbUpdated(_ event: Event) {
guard let dndStatus = event.dndStatus else {
return
}
@@ -169,8 +169,8 @@ internal extension Client {
doNotDisturbEventsDelegate?.doNotDisturbUpdated(self, dndStatus: dndStatus)
}
func doNotDisturbUserUpdated(event: Event) {
guard let dndStatus = event.dndStatus, user = event.user, id = user.id else {
func doNotDisturbUserUpdated(_ event: Event) {
guard let dndStatus = event.dndStatus, let user = event.user, let id = user.id else {
return
}
@@ -179,8 +179,8 @@ internal extension Client {
}
//MARK: - IM & Group Open/Close
func open(event: Event, open: Bool) {
guard let channel = event.channel, id = channel.id else {
func open(_ event: Event, open: Bool) {
guard let channel = event.channel, let id = channel.id else {
return
}
@@ -189,11 +189,11 @@ internal extension Client {
}
//MARK: - Files
func processFile(event: Event) {
guard let file = event.file, id = file.id else {
func processFile(_ event: Event) {
guard let file = event.file, let id = file.id else {
return
}
if let comment = file.initialComment, commentID = comment.id {
if let comment = file.initialComment, let commentID = comment.id {
if files[id]?.comments[commentID] == nil {
files[id]?.comments[commentID] = comment
}
@@ -203,8 +203,8 @@ internal extension Client {
fileEventsDelegate?.fileProcessed(self, file: file)
}
func filePrivate(event: Event) {
guard let file = event.file, id = file.id else {
func filePrivate(_ event: Event) {
guard let file = event.file, let id = file.id else {
return
}
@@ -212,19 +212,19 @@ internal extension Client {
fileEventsDelegate?.fileMadePrivate(self, file: file)
}
func deleteFile(event: Event) {
guard let file = event.file, id = file.id else {
func deleteFile(_ event: Event) {
guard let file = event.file, let id = file.id else {
return
}
if files[id] != nil {
files.removeValueForKey(id)
files.removeValue(forKey: id)
}
fileEventsDelegate?.fileDeleted(self, file: file)
}
func fileCommentAdded(event: Event) {
guard let file = event.file, id = file.id, comment = event.comment, commentID = comment.id else {
func fileCommentAdded(_ event: Event) {
guard let file = event.file, let id = file.id, let comment = event.comment, let commentID = comment.id else {
return
}
@@ -232,8 +232,8 @@ internal extension Client {
fileEventsDelegate?.fileCommentAdded(self, file: file, comment: comment)
}
func fileCommentEdited(event: Event) {
guard let file = event.file, id = file.id, comment = event.comment, commentID = comment.id else {
func fileCommentEdited(_ event: Event) {
guard let file = event.file, let id = file.id, let comment = event.comment, let commentID = comment.id else {
return
}
@@ -241,18 +241,18 @@ internal extension Client {
fileEventsDelegate?.fileCommentEdited(self, file: file, comment: comment)
}
func fileCommentDeleted(event: Event) {
guard let file = event.file, id = file.id, comment = event.comment, commentID = comment.id else {
func fileCommentDeleted(_ event: Event) {
guard let file = event.file, let id = file.id, let comment = event.comment, let commentID = comment.id else {
return
}
files[id]?.comments.removeValueForKey(commentID)
_ = files[id]?.comments.removeValue(forKey: commentID)
fileEventsDelegate?.fileCommentDeleted(self, file: file, comment: comment)
}
//MARK: - Pins
func pinAdded(event: Event) {
guard let id = event.channelID, item = event.item else {
func pinAdded(_ event: Event) {
guard let id = event.channelID, let item = event.item else {
return
}
@@ -260,8 +260,8 @@ internal extension Client {
pinEventsDelegate?.itemPinned(self, item: item, channel: channels[id])
}
func pinRemoved(event: Event) {
guard let id = event.channelID, item = event.item else {
func pinRemoved(_ event: Event) {
guard let id = event.channelID, let item = event.item else {
return
}
@@ -272,8 +272,8 @@ internal extension Client {
}
//MARK: - Stars
func itemStarred(event: Event, star: Bool) {
guard let item = event.item, type = item.type else {
func itemStarred(_ event: Event, star: Bool) {
guard let item = event.item, let type = item.type else {
return
}
switch type {
@@ -290,15 +290,15 @@ internal extension Client {
starEventsDelegate?.itemStarred(self, item: item, star: star)
}
func starMessage(item: Item, star: Bool) {
guard let message = item.message, ts = message.ts, channel = item.channel where channels[channel]?.messages[ts] != nil else {
func starMessage(_ item: Item, star: Bool) {
guard let message = item.message, let ts = message.ts, let channel = item.channel , channels[channel]?.messages[ts] != nil else {
return
}
channels[channel]?.messages[ts]?.isStarred = star
}
func starFile(item: Item, star: Bool) {
guard let file = item.file, id = file.id else {
func starFile(_ item: Item, star: Bool) {
guard let file = item.file, let id = file.id else {
return
}
@@ -314,22 +314,22 @@ internal extension Client {
}
}
func starComment(item: Item) {
guard let file = item.file, id = file.id, comment = item.comment, commentID = comment.id else {
func starComment(_ item: Item) {
guard let file = item.file, let id = file.id, let comment = item.comment, let commentID = comment.id else {
return
}
files[id]?.comments[commentID] = comment
}
//MARK: - Reactions
func addedReaction(event: Event) {
guard let item = event.item, type = item.type, reaction = event.reaction, userID = event.user?.id, itemUser = event.itemUser else {
func addedReaction(_ event: Event) {
guard let item = event.item, let type = item.type, let reaction = event.reaction, let userID = event.user?.id, let itemUser = event.itemUser else {
return
}
switch type {
case "message":
guard let channel = item.channel, ts = item.ts, message = channels[channel]?.messages[ts] else {
guard let channel = item.channel, let ts = item.ts, let message = channels[channel]?.messages[ts] else {
return
}
message.reactions.append(Reaction(name: reaction, user: userID))
@@ -339,7 +339,7 @@ internal extension Client {
}
files[id]?.reactions.append(Reaction(name: reaction, user: userID))
case "file_comment":
guard let id = item.file?.id, commentID = item.fileCommentID else {
guard let id = item.file?.id, let commentID = item.fileCommentID else {
return
}
files[id]?.comments[commentID]?.reactions.append(Reaction(name: reaction, user: userID))
@@ -350,24 +350,24 @@ internal extension Client {
reactionEventsDelegate?.reactionAdded(self, reaction: reaction, item: item, itemUser: itemUser)
}
func removedReaction(event: Event) {
guard let item = event.item, type = item.type, key = event.reaction, userID = event.user?.id, itemUser = event.itemUser else {
func removedReaction(_ event: Event) {
guard let item = event.item, let type = item.type, let key = event.reaction, let userID = event.user?.id, let itemUser = event.itemUser else {
return
}
switch type {
case "message":
guard let channel = item.channel, ts = item.ts, message = channels[channel]?.messages[ts] else {
guard let channel = item.channel, let ts = item.ts, let message = channels[channel]?.messages[ts] else {
return
}
message.reactions = message.reactions.filter({$0.name != key && $0.user != userID})
case "file":
guard let itemFile = item.file, id = itemFile.id else {
guard let itemFile = item.file, let id = itemFile.id else {
return
}
files[id]?.reactions = files[id]!.reactions.filter({$0.name != key && $0.user != userID})
case "file_comment":
guard let id = item.file?.id, commentID = item.fileCommentID else {
guard let id = item.file?.id, let commentID = item.fileCommentID else {
return
}
files[id]?.comments[commentID]?.reactions = files[id]!.comments[commentID]!.reactions.filter({$0.name != key && $0.user != userID})
@@ -379,7 +379,7 @@ internal extension Client {
}
//MARK: - Preferences
func changePreference(event: Event) {
func changePreference(_ event: Event) {
guard let name = event.name else {
return
}
@@ -389,8 +389,8 @@ internal extension Client {
}
//Mark: - User Change
func userChange(event: Event) {
guard let user = event.user, id = user.id else {
func userChange(_ event: Event) {
guard let user = event.user, let id = user.id else {
return
}
@@ -401,8 +401,8 @@ internal extension Client {
}
//MARK: - User Presence
func presenceChange(event: Event) {
guard let user = event.user, id = user.id, presence = event.presence else {
func presenceChange(_ event: Event) {
guard let user = event.user, let id = user.id, let presence = event.presence else {
return
}
@@ -411,8 +411,8 @@ internal extension Client {
}
//MARK: - Team
func teamJoin(event: Event) {
guard let user = event.user, id = user.id else {
func teamJoin(_ event: Event) {
guard let user = event.user, let id = user.id else {
return
}
@@ -420,7 +420,7 @@ internal extension Client {
teamEventsDelegate?.teamJoined(self, user: user)
}
func teamPlanChange(event: Event) {
func teamPlanChange(_ event: Event) {
guard let plan = event.plan else {
return
}
@@ -429,7 +429,7 @@ internal extension Client {
teamEventsDelegate?.teamPlanChanged(self, plan: plan)
}
func teamPreferenceChange(event: Event) {
func teamPreferenceChange(_ event: Event) {
guard let name = event.name else {
return
}
@@ -438,7 +438,7 @@ internal extension Client {
teamEventsDelegate?.teamPreferencesChanged(self, preference: name, value: event.value)
}
func teamNameChange(event: Event) {
func teamNameChange(_ event: Event) {
guard let name = event.name else {
return
}
@@ -447,7 +447,7 @@ internal extension Client {
teamEventsDelegate?.teamNameChanged(self, name: name)
}
func teamDomainChange(event: Event) {
func teamDomainChange(_ event: Event) {
guard let domain = event.domain else {
return
}
@@ -456,7 +456,7 @@ internal extension Client {
teamEventsDelegate?.teamDomainChanged(self, domain: domain)
}
func emailDomainChange(event: Event) {
func emailDomainChange(_ event: Event) {
guard let domain = event.emailDomain else {
return
}
@@ -465,13 +465,13 @@ internal extension Client {
teamEventsDelegate?.teamEmailDomainChanged(self, domain: domain)
}
func emojiChanged(event: Event) {
func emojiChanged(_ event: Event) {
teamEventsDelegate?.teamEmojiChanged(self)
}
//MARK: - Bots
func bot(event: Event) {
guard let bot = event.bot, id = bot.id else {
func bot(_ event: Event) {
guard let bot = event.bot, let id = bot.id else {
return
}
@@ -480,8 +480,8 @@ internal extension Client {
}
//MARK: - Subteams
func subteam(event: Event) {
guard let subteam = event.subteam, id = subteam.id else {
func subteam(_ event: Event) {
guard let subteam = event.subteam, let id = subteam.id else {
return
}
@@ -489,8 +489,8 @@ internal extension Client {
subteamEventsDelegate?.subteamEvent(self, userGroup: subteam)
}
func subteamAddedSelf(event: Event) {
guard let subteamID = event.subteamID, _ = authenticatedUser?.userGroups else {
func subteamAddedSelf(_ event: Event) {
guard let subteamID = event.subteamID, let _ = authenticatedUser?.userGroups else {
return
}
@@ -498,17 +498,17 @@ internal extension Client {
subteamEventsDelegate?.subteamSelfAdded(self, subteamID: subteamID)
}
func subteamRemovedSelf(event: Event) {
func subteamRemovedSelf(_ event: Event) {
guard let subteamID = event.subteamID else {
return
}
authenticatedUser?.userGroups?.removeValueForKey(subteamID)
_ = authenticatedUser?.userGroups?.removeValue(forKey: subteamID)
subteamEventsDelegate?.subteamSelfRemoved(self, subteamID: subteamID)
}
//MARK: - Team Profiles
func teamProfileChange(event: Event) {
func teamProfileChange(_ event: Event) {
guard let profile = event.profile else {
return
}
@@ -522,7 +522,7 @@ internal extension Client {
teamProfileEventsDelegate?.teamProfileChanged(self, profile: profile)
}
func teamProfileDeleted(event: Event) {
func teamProfileDeleted(_ event: Event) {
guard let profile = event.profile else {
return
}
@@ -536,7 +536,7 @@ internal extension Client {
teamProfileEventsDelegate?.teamProfileDeleted(self, profile: profile)
}
func teamProfileReordered(event: Event) {
func teamProfileReordered(_ event: Event) {
guard let profile = event.profile else {
return
}
@@ -551,8 +551,8 @@ internal extension Client {
}
//MARK: - Authenticated User
func manualPresenceChange(event: Event) {
guard let presence = event.presence, user = authenticatedUser else {
func manualPresenceChange(_ event: Event) {
guard let presence = event.presence, let user = authenticatedUser else {
return
}
+10 -10
View File
@@ -21,29 +21,29 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
public enum ClientError: ErrorType {
case ChannelDoesNotExist
case UserDoesNotExist
public enum ClientError: ErrorProtocol {
case channelDoesNotExist
case userDoesNotExist
}
public extension Client {
//MARK: - User & Channel
public func getChannelIDByName(name: String) throws -> String {
public func getChannelIDByName(_ name: String) throws -> String {
guard let id = channels.filter({$0.1.name == stripString(name)}).first?.0 else {
throw ClientError.ChannelDoesNotExist
throw ClientError.channelDoesNotExist
}
return id
}
public func getUserIDByName(name: String) throws -> String {
public func getUserIDByName(_ name: String) throws -> String {
guard let id = users.filter({$0.1.name == stripString(name)}).first?.0 else {
throw ClientError.UserDoesNotExist
throw ClientError.userDoesNotExist
}
return id
}
public func getImIDForUserWithID(id: String, success: (imID: String?)->Void, failure: (error: SlackError)->Void) {
public func getImIDForUserWithID(_ id: String, success: (imID: String?)->Void, failure: (error: SlackError)->Void) {
let ims = channels.filter{$0.1.isIM == true}
let channel = ims.filter{$0.1.user == id}.first
if let channel = channel {
@@ -54,10 +54,10 @@ public extension Client {
}
//MARK: - Utilities
internal func stripString(string: String) -> String {
internal func stripString(_ string: String) -> String {
var strippedString = string
if string[string.startIndex] == "@" || string[string.startIndex] == "#" {
strippedString = string.substringFromIndex(string.startIndex.advancedBy(1))
strippedString = string.substring(from: string.characters.index(string.startIndex, offsetBy: 1))
}
return strippedString
}
+32 -34
View File
@@ -44,7 +44,7 @@ public final class Client: WebSocketDelegate {
}
internal var webSocket: WebSocket?
private let pingPongQueue = dispatch_queue_create("com.launchsoft.SlackKit", DISPATCH_QUEUE_SERIAL)
private let pingPongQueue = DispatchQueue(label: "com.launchsoft.SlackKit", attributes: DispatchQueueAttributes.serial)
internal var ping: Double?
internal var pong: Double?
internal var options: ClientOptions?
@@ -69,15 +69,15 @@ public final class Client: WebSocketDelegate {
self.token = apiToken
}
public func setAuthToken(token: String) {
public func setAuthToken(_ token: String) {
self.token = token
}
public func connect(options options: ClientOptions = ClientOptions()) {
public func connect(options: ClientOptions = ClientOptions()) {
self.options = options
webAPI.rtmStart(options.simpleLatest, noUnreads: options.noUnreads, mpimAware: options.mpimAware, success: {
(response) -> Void in
guard let socketURL = response["url"] as? String, url = NSURL(string: socketURL) else {
guard let socketURL = response["url"] as? String, let url = URL(string: socketURL) else {
return
}
self.initialSetup(response)
@@ -94,42 +94,41 @@ public final class Client: WebSocketDelegate {
}
//MARK: - RTM Message send
public func sendMessage(message: String, channelID: String) {
public func sendMessage(_ message: String, channelID: String) {
guard connected else { return }
if let data = try? formatMessageToSlackJsonString(msg: message, channel: channelID),
string = NSString(data: data, encoding: NSUTF8StringEncoding) as? String {
webSocket?.writeString(string)
if let data = try? formatMessageToSlackJsonString(msg: message, channel: channelID), let string = String(data: data, encoding: String.Encoding.utf8) {
webSocket?.write(string: string)
}
}
private func formatMessageToSlackJsonString(message: (msg: String, channel: String)) throws -> NSData {
private func formatMessageToSlackJsonString(_ message: (msg: String, channel: String)) throws -> Data {
let json: [String: AnyObject] = [
"id": NSDate().slackTimestamp(),
"id": Date().slackTimestamp(),
"type": "message",
"channel": message.channel,
"text": message.msg.slackFormatEscaping()
]
addSentMessage(json)
return try NSJSONSerialization.dataWithJSONObject(json, options: [])
return try JSONSerialization.data(withJSONObject: json, options: [])
}
private func addSentMessage(dictionary: [String: AnyObject]) {
private func addSentMessage(_ dictionary: [String: AnyObject]) {
var message = dictionary
guard let id = message["id"] as? NSNumber else {
return
}
let ts = String(id)
message.removeValueForKey("id")
message.removeValue(forKey: "id")
message["ts"] = ts
message["user"] = self.authenticatedUser?.id
sentMessages[ts] = Message(message: message)
}
//MARK: - RTM Ping
private func pingRTMServerAtInterval(interval: NSTimeInterval) {
let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(interval * Double(NSEC_PER_SEC)))
dispatch_after(delay, pingPongQueue, {
private func pingRTMServerAtInterval(_ interval: TimeInterval) {
let delay = DispatchTime.now() + Double(Int64(interval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
pingPongQueue.after(when: delay, execute: {
guard self.connected && self.timeoutCheck() else {
self.disconnect()
return
@@ -144,21 +143,20 @@ public final class Client: WebSocketDelegate {
return
}
let json: [String: AnyObject] = [
"id": NSDate().slackTimestamp(),
"id": Date().slackTimestamp(),
"type": "ping",
]
guard let data = try? NSJSONSerialization.dataWithJSONObject(json, options: []) else {
guard let data = try? JSONSerialization.data(withJSONObject: json, options: []) else {
return
}
let string = NSString(data: data, encoding: NSUTF8StringEncoding)
if let writePing = string as? String {
if let string = String(data: data, encoding: String.Encoding.utf8) {
ping = json["id"] as? Double
webSocket?.writeString(writePing)
webSocket?.write(string: string)
}
}
private func timeoutCheck() -> Bool {
if let pong = pong, ping = ping, timeout = options?.timeout {
if let pong = pong, let ping = ping, let timeout = options?.timeout {
if pong - ping < timeout {
return true
} else {
@@ -171,7 +169,7 @@ public final class Client: WebSocketDelegate {
}
//MARK: - Client setup
private func initialSetup(json: [String: AnyObject]) {
private func initialSetup(_ json: [String: AnyObject]) {
team = Team(team: json["team"] as? [String: AnyObject])
authenticatedUser = User(user: json["self"] as? [String: AnyObject])
authenticatedUser?.doNotDisturbStatus = DoNotDisturbStatus(status: json["dnd"] as? [String: AnyObject])
@@ -184,28 +182,28 @@ public final class Client: WebSocketDelegate {
enumerateSubteams(json["subteams"] as? [String: AnyObject])
}
private func addUser(aUser: [String: AnyObject]) {
private func addUser(_ aUser: [String: AnyObject]) {
let user = User(user: aUser)
if let id = user.id {
users[id] = user
}
}
private func addChannel(aChannel: [String: AnyObject]) {
private func addChannel(_ aChannel: [String: AnyObject]) {
let channel = Channel(channel: aChannel)
if let id = channel.id {
channels[id] = channel
}
}
private func addBot(aBot: [String: AnyObject]) {
private func addBot(_ aBot: [String: AnyObject]) {
let bot = Bot(bot: aBot)
if let id = bot.id {
bots[id] = bot
}
}
private func enumerateSubteams(subteams: [String: AnyObject]?) {
private func enumerateSubteams(_ subteams: [String: AnyObject]?) {
if let subteams = subteams {
if let all = subteams["all"] as? [[String: AnyObject]] {
for item in all {
@@ -223,7 +221,7 @@ public final class Client: WebSocketDelegate {
}
// MARK: - Utilities
private func enumerateObjects(array: [AnyObject]?, initalizer: ([String: AnyObject])-> Void) {
private func enumerateObjects(_ array: [AnyObject]?, initalizer: ([String: AnyObject])-> Void) {
if let array = array {
for object in array {
if let dictionary = object as? [String: AnyObject] {
@@ -240,26 +238,26 @@ public final class Client: WebSocketDelegate {
}
}
public func websocketDidDisconnect(socket: WebSocket, error: NSError?) {
public func websocketDidDisconnect(_ socket: WebSocket, error: NSError?) {
connected = false
webSocket = nil
authenticatedUser = nil
connectionEventsDelegate?.clientDisconnected(self)
if let options = options where options.reconnect == true {
if let options = options, options.reconnect == true {
connect(options: options)
}
}
public func websocketDidReceiveMessage(socket: WebSocket, text: String) {
guard let data = text.dataUsingEncoding(NSUTF8StringEncoding) else {
public func websocketDidReceiveMessage(_ socket: WebSocket, text: String) {
guard let data = text.data(using: String.Encoding.utf8) else {
return
}
if let json = (try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments)) as? [String: AnyObject] {
if let json = (try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments)) as? [String: AnyObject] {
dispatch(json)
}
}
public func websocketDidReceiveData(socket: WebSocket, data: NSData) {}
public func websocketDidReceiveData(_ socket: WebSocket, data: Data) {}
}
+3 -3
View File
@@ -28,11 +28,11 @@ public struct ClientOptions {
let simpleLatest: Bool?
let noUnreads: Bool?
let mpimAware: Bool?
let pingInterval: NSTimeInterval?
let timeout: NSTimeInterval?
let pingInterval: TimeInterval?
let timeout: TimeInterval?
let reconnect: Bool?
public init(simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, pingInterval: NSTimeInterval? = nil, timeout: NSTimeInterval? = nil, reconnect: Bool? = nil) {
public init(simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, pingInterval: TimeInterval? = nil, timeout: TimeInterval? = nil, reconnect: Bool? = nil) {
self.simpleLatest = simpleLatest
self.noUnreads = noUnreads
self.mpimAware = mpimAware
+1 -1
View File
@@ -50,7 +50,7 @@ public struct CustomProfileField {
self.id = id
}
internal mutating func updateProfileField(profile: CustomProfileField?) {
internal mutating func updateProfileField(_ profile: CustomProfileField?) {
id = profile?.id != nil ? profile?.id : id
alt = profile?.alt != nil ? profile?.alt : alt
value = profile?.value != nil ? profile?.value : value
+48 -48
View File
@@ -22,88 +22,88 @@
// THE SOFTWARE.
public protocol ConnectionEventsDelegate: class {
func clientConnected(client: Client)
func clientDisconnected(client: Client)
func clientConnectionFailed(client: Client, error: SlackError)
func clientConnected(_ client: Client)
func clientDisconnected(_ client: Client)
func clientConnectionFailed(_ client: Client, error: SlackError)
}
public protocol MessageEventsDelegate: class {
func messageSent(client: Client, message: Message)
func messageReceived(client: Client, message: Message)
func messageChanged(client: Client, message: Message)
func messageDeleted(client: Client, message: Message?)
func messageSent(_ client: Client, message: Message)
func messageReceived(_ client: Client, message: Message)
func messageChanged(_ client: Client, message: Message)
func messageDeleted(_ client: Client, message: Message?)
}
public protocol ChannelEventsDelegate: class {
func userTyping(client: Client, channel: Channel, user: User)
func channelMarked(client: Client, channel: Channel, timestamp: String)
func channelCreated(client: Client, channel: Channel)
func channelDeleted(client: Client, channel: Channel)
func channelRenamed(client: Client, channel: Channel)
func channelArchived(client: Client, channel: Channel)
func channelHistoryChanged(client: Client, channel: Channel)
func channelJoined(client: Client, channel: Channel)
func channelLeft(client: Client, channel: Channel)
func userTyping(_ client: Client, channel: Channel, user: User)
func channelMarked(_ client: Client, channel: Channel, timestamp: String)
func channelCreated(_ client: Client, channel: Channel)
func channelDeleted(_ client: Client, channel: Channel)
func channelRenamed(_ client: Client, channel: Channel)
func channelArchived(_ client: Client, channel: Channel)
func channelHistoryChanged(_ client: Client, channel: Channel)
func channelJoined(_ client: Client, channel: Channel)
func channelLeft(_ client: Client, channel: Channel)
}
public protocol DoNotDisturbEventsDelegate: class {
func doNotDisturbUpdated(client: Client, dndStatus: DoNotDisturbStatus)
func doNotDisturbUserUpdated(client: Client, dndStatus: DoNotDisturbStatus, user: User)
func doNotDisturbUpdated(_ client: Client, dndStatus: DoNotDisturbStatus)
func doNotDisturbUserUpdated(_ client: Client, dndStatus: DoNotDisturbStatus, user: User)
}
public protocol GroupEventsDelegate: class {
func groupOpened(client: Client, group: Channel)
func groupOpened(_ client: Client, group: Channel)
}
public protocol FileEventsDelegate: class {
func fileProcessed(client: Client, file: File)
func fileMadePrivate(client: Client, file: File)
func fileDeleted(client: Client, file: File)
func fileCommentAdded(client: Client, file: File, comment: Comment)
func fileCommentEdited(client: Client, file: File, comment: Comment)
func fileCommentDeleted(client: Client, file: File, comment: Comment)
func fileProcessed(_ client: Client, file: File)
func fileMadePrivate(_ client: Client, file: File)
func fileDeleted(_ client: Client, file: File)
func fileCommentAdded(_ client: Client, file: File, comment: Comment)
func fileCommentEdited(_ client: Client, file: File, comment: Comment)
func fileCommentDeleted(_ client: Client, file: File, comment: Comment)
}
public protocol PinEventsDelegate: class {
func itemPinned(client: Client, item: Item, channel: Channel?)
func itemUnpinned(client: Client, item: Item, channel: Channel?)
func itemPinned(_ client: Client, item: Item, channel: Channel?)
func itemUnpinned(_ client: Client, item: Item, channel: Channel?)
}
public protocol StarEventsDelegate: class {
func itemStarred(client: Client, item: Item, star: Bool)
func itemStarred(_ client: Client, item: Item, star: Bool)
}
public protocol ReactionEventsDelegate: class {
func reactionAdded(client: Client, reaction: String, item: Item, itemUser: String)
func reactionRemoved(client: Client, reaction: String, item: Item, itemUser: String)
func reactionAdded(_ client: Client, reaction: String, item: Item, itemUser: String)
func reactionRemoved(_ client: Client, reaction: String, item: Item, itemUser: String)
}
public protocol SlackEventsDelegate: class {
func preferenceChanged(client: Client, preference: String, value: AnyObject?)
func userChanged(client: Client, user: User)
func presenceChanged(client: Client, user: User, presence: String)
func manualPresenceChanged(client: Client, user: User, presence: String)
func botEvent(client: Client, bot: Bot)
func preferenceChanged(_ client: Client, preference: String, value: AnyObject?)
func userChanged(_ client: Client, user: User)
func presenceChanged(_ client: Client, user: User, presence: String)
func manualPresenceChanged(_ client: Client, user: User, presence: String)
func botEvent(_ client: Client, bot: Bot)
}
public protocol TeamEventsDelegate: class {
func teamJoined(client: Client, user: User)
func teamPlanChanged(client: Client, plan: String)
func teamPreferencesChanged(client: Client, preference: String, value: AnyObject?)
func teamNameChanged(client: Client, name: String)
func teamDomainChanged(client: Client, domain: String)
func teamEmailDomainChanged(client: Client, domain: String)
func teamEmojiChanged(client: Client)
func teamJoined(_ client: Client, user: User)
func teamPlanChanged(_ client: Client, plan: String)
func teamPreferencesChanged(_ client: Client, preference: String, value: AnyObject?)
func teamNameChanged(_ client: Client, name: String)
func teamDomainChanged(_ client: Client, domain: String)
func teamEmailDomainChanged(_ client: Client, domain: String)
func teamEmojiChanged(_ client: Client)
}
public protocol SubteamEventsDelegate: class {
func subteamEvent(client: Client, userGroup: UserGroup)
func subteamSelfAdded(client: Client, subteamID: String)
func subteamSelfRemoved(client: Client, subteamID: String)
func subteamEvent(_ client: Client, userGroup: UserGroup)
func subteamSelfAdded(_ client: Client, subteamID: String)
func subteamSelfRemoved(_ client: Client, subteamID: String)
}
public protocol TeamProfileEventsDelegate: class {
func teamProfileChanged(client: Client, profile: CustomProfile)
func teamProfileDeleted(client: Client, profile: CustomProfile)
func teamProfileReordered(client: Client, profile: CustomProfile)
func teamProfileChanged(_ client: Client, profile: CustomProfile)
func teamProfileDeleted(_ client: Client, profile: CustomProfile)
func teamProfileReordered(_ client: Client, profile: CustomProfile)
}
+6 -6
View File
@@ -23,10 +23,10 @@
import Foundation
public extension NSDate {
public extension Date {
func slackTimestamp() -> Double {
return NSNumber(double: timeIntervalSince1970).doubleValue
return NSNumber(value: timeIntervalSince1970).doubleValue
}
}
@@ -34,9 +34,9 @@ public extension NSDate {
internal extension String {
func slackFormatEscaping() -> String {
var escapedString = stringByReplacingOccurrencesOfString("&", withString: "&amp;")
escapedString = stringByReplacingOccurrencesOfString("<", withString: "&lt;")
escapedString = stringByReplacingOccurrencesOfString(">", withString: "&gt;")
var escapedString = replacingOccurrences(of: "&", with: "&amp;")
escapedString = replacingOccurrences(of: "<", with: "&lt;")
escapedString = replacingOccurrences(of: ">", with: "&gt;")
return escapedString
}
@@ -47,7 +47,7 @@ internal extension Dictionary where Key: StringLiteralConvertible, Value: AnyObj
var requestStringFromParameters: String {
var requestString = ""
for key in self.keys {
if let value = self[key] as? String, encodedValue = value.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLHostAllowedCharacterSet()) {
if let value = self[key] as? String, let encodedValue = value.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlHostAllowed) {
requestString += "&\(key)=\(encodedValue)"
} else if let value = self[key] as? Int {
requestString += "&\(key)=\(value)"
+3 -3
View File
@@ -25,13 +25,13 @@ import Foundation
public struct History {
internal(set) public var latest: NSDate?
internal(set) public var latest: Date?
internal(set) public var messages = [Message]()
public let hasMore: Bool?
internal init(history: [String: AnyObject]?) {
if let latestStr = history?["latest"] as? String, latestDouble = Double(latestStr) {
latest = NSDate(timeIntervalSince1970: NSTimeInterval(latestDouble))
if let latestStr = history?["latest"] as? String, let latestDouble = Double(latestStr) {
latest = Date(timeIntervalSince1970: TimeInterval(latestDouble))
}
if let msgs = history?["messages"] as? [[String: AnyObject]] {
for message in msgs {
+3 -3
View File
@@ -50,8 +50,8 @@ public struct IncomingWebhook {
self.configurationURL = nil
}
public func postMessage(response: Response, success: ((Bool)->Void)? = nil, failure: ((SlackError)->Void)? = nil) {
if let url = self.url, data = try? NSJSONSerialization.dataWithJSONObject(jsonBody(response.json()), options: []) {
public func postMessage(_ response: Response, success: ((Bool)->Void)? = nil, failure: ((SlackError)->Void)? = nil) {
if let url = self.url, let data = try? JSONSerialization.data(withJSONObject: jsonBody(response.json()), options: []) {
NetworkInterface().customRequest(url, data: data, success: { _ in
success?(true)
}, errorClosure: {(error) in
@@ -60,7 +60,7 @@ public struct IncomingWebhook {
}
}
private func jsonBody(response: [String: AnyObject]) -> [String: AnyObject] {
private func jsonBody(_ response: [String: AnyObject]) -> [String: AnyObject] {
var json = response
json["channel"] = channel
json["username"] = username
@@ -29,9 +29,9 @@ public struct MessageActionResponder {
self.responses = responses
}
internal func responseForRequest(request:MessageActionRequest) -> Reply? {
internal func responseForRequest(_ request:MessageActionRequest) -> Reply? {
if let response = responses.filter({$0.0.name == request.action?.name}).first?.1 {
return Reply.JSON(response: response)
return Reply.json(response: response)
} else {
return nil
}
+4 -4
View File
@@ -31,16 +31,16 @@ public class MessageActionServer: Server {
addRoute(route)
}
internal func addRoute(route: String) {
internal func addRoute(_ route: String) {
http.POST["/\(route)"] = { request in
let payload = request.parseUrlencodedForm()
let actionRequest = MessageActionRequest(response: self.jsonFromRequest(payload[0].1))
if let reply = self.responder.responseForRequest(actionRequest) where actionRequest.token == self.token {
if let reply = self.responder.responseForRequest(actionRequest), actionRequest.token == self.token {
return self.request(actionRequest, reply: reply)
} else {
return .BadRequest(.Text("Bad request."))
return .badRequest(.text("Bad request."))
}
}
}
}
}
+26 -26
View File
@@ -27,7 +27,7 @@ internal struct NetworkInterface {
private let apiUrl = "https://slack.com/api/"
internal func request(endpoint: Endpoint, token: String? = nil, parameters: [String: AnyObject]?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) {
internal func request(_ endpoint: Endpoint, token: String? = nil, parameters: [String: AnyObject]?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) {
var requestString = "\(apiUrl)\(endpoint.rawValue)?"
if let token = token {
requestString += "token=\(token)"
@@ -35,12 +35,12 @@ internal struct NetworkInterface {
if let params = parameters {
requestString += params.requestStringFromParameters
}
guard let url = NSURL(string: requestString) else {
guard let url = URL(string: requestString) else {
errorClosure(SlackError.ClientNetworkError)
return
}
let request = NSURLRequest(URL:url)
NSURLSession.sharedSession().dataTaskWithRequest(request) {
let request = URLRequest(url:url)
URLSession.shared.dataTask(with: request) {
(data, response, internalError) -> Void in
self.handleResponse(data, response: response, internalError: internalError, successClosure: {(json) in
successClosure(json)
@@ -50,18 +50,18 @@ internal struct NetworkInterface {
}.resume()
}
internal func customRequest(url: String, data: NSData, success: (Bool)->Void, errorClosure: (SlackError)->Void) {
guard let requestString = url.stringByRemovingPercentEncoding, url = NSURL(string: requestString) else {
internal func customRequest(_ url: String, data: Data, success: (Bool)->Void, errorClosure: (SlackError)->Void) {
guard let url = URL(string: url.removePercentEncoding()) else {
errorClosure(SlackError.ClientNetworkError)
return
}
let request = NSMutableURLRequest(URL:url)
request.HTTPMethod = "POST"
var request = URLRequest(url:url)
request.httpMethod = "POST"
let contentType = "application/json"
request.setValue(contentType, forHTTPHeaderField: "Content-Type")
request.HTTPBody = data
request.httpBody = data
NSURLSession.sharedSession().dataTaskWithRequest(request) {
URLSession.shared.dataTask(with: request) {
(data, response, internalError) -> Void in
if internalError == nil {
success(true)
@@ -71,17 +71,17 @@ internal struct NetworkInterface {
}.resume()
}
internal func uploadRequest(token: String, data: NSData, parameters: [String: AnyObject]?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) {
internal func uploadRequest(_ token: String, data: Data, parameters: [String: AnyObject]?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) {
var requestString = "\(apiUrl)\(Endpoint.FilesUpload.rawValue)?token=\(token)"
if let params = parameters {
requestString = requestString + params.requestStringFromParameters
}
guard let url = NSURL(string: requestString) else {
guard let url = URL(string: requestString) else {
errorClosure(SlackError.ClientNetworkError)
return
}
let request = NSMutableURLRequest(URL:url)
request.HTTPMethod = "POST"
var request = URLRequest(url:url)
request.httpMethod = "POST"
let boundaryConstant = randomBoundary()
let contentType = "multipart/form-data; boundary=" + boundaryConstant
let boundaryStart = "--\(boundaryConstant)\r\n"
@@ -89,18 +89,18 @@ internal struct NetworkInterface {
let contentDispositionString = "Content-Disposition: form-data; name=\"file\"; filename=\"\(parameters!["filename"])\"\r\n"
let contentTypeString = "Content-Type: \(parameters!["filetype"])\r\n\r\n"
let requestBodyData : NSMutableData = NSMutableData()
requestBodyData.appendData(boundaryStart.dataUsingEncoding(NSUTF8StringEncoding)!)
requestBodyData.appendData(contentDispositionString.dataUsingEncoding(NSUTF8StringEncoding)!)
requestBodyData.appendData(contentTypeString.dataUsingEncoding(NSUTF8StringEncoding)!)
requestBodyData.appendData(data)
requestBodyData.appendData("\r\n".dataUsingEncoding(NSUTF8StringEncoding)!)
requestBodyData.appendData(boundaryEnd.dataUsingEncoding(NSUTF8StringEncoding)!)
var requestBodyData: Data = Data()
requestBodyData.append(boundaryStart.data(using: String.Encoding.utf8)!)
requestBodyData.append(contentDispositionString.data(using: String.Encoding.utf8)!)
requestBodyData.append(contentTypeString.data(using: String.Encoding.utf8)!)
requestBodyData.append(data)
requestBodyData.append("\r\n".data(using: String.Encoding.utf8)!)
requestBodyData.append(boundaryEnd.data(using: String.Encoding.utf8)!)
request.setValue(contentType, forHTTPHeaderField: "Content-Type")
request.HTTPBody = requestBodyData
request.httpBody = requestBodyData as Data
NSURLSession.sharedSession().dataTaskWithRequest(request) {
URLSession.shared.dataTask(with: request) {
(data, response, internalError) -> Void in
self.handleResponse(data, response: response, internalError: internalError, successClosure: {(json) in
successClosure(json)
@@ -110,13 +110,13 @@ internal struct NetworkInterface {
}.resume()
}
private func handleResponse(data: NSData?, response:NSURLResponse?, internalError:NSError?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) {
guard let data = data, response = response as? NSHTTPURLResponse else {
private func handleResponse(_ data: Data?, response:URLResponse?, internalError:NSError?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) {
guard let data = data, let response = response as? HTTPURLResponse else {
errorClosure(SlackError.ClientNetworkError)
return
}
do {
guard let json = try NSJSONSerialization.JSONObjectWithData(data, options: []) as? [String: AnyObject] else {
guard let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: AnyObject] else {
errorClosure(SlackError.ClientJSONError)
return
}
+1 -1
View File
@@ -33,7 +33,7 @@ internal struct OAuthResponse {
init(response: [String: AnyObject]?) {
accessToken = response?["access_token"] as? String
scope = (response?["scope"] as? String)?.componentsSeparatedByString(",").flatMap{Scope(rawValue:$0)}
scope = (response?["scope"] as? String)?.components(separatedBy: ",").flatMap{Scope(rawValue:$0)}
userID = response?["user_id"] as? String
teamName = response?["team_name"] as? String
teamID = response?["team_id"] as? String
+16 -20
View File
@@ -25,7 +25,7 @@ import Foundation
import Swifter
internal protocol OAuthDelegate {
mutating func userAuthed(response: OAuthResponse)
func userAuthed(_ response: OAuthResponse)
}
public struct OAuthServer {
@@ -49,7 +49,7 @@ public struct OAuthServer {
start(port, forceIPV4: forceIPV4)
}
public func start(port: in_port_t = 8080, forceIPV4: Bool = false) {
public func start(_ port: in_port_t = 8080, forceIPV4: Bool = false) {
do {
try http.start(port, forceIPv4: forceIPV4)
} catch let error as NSError {
@@ -61,37 +61,33 @@ public struct OAuthServer {
http.stop()
}
private mutating func oauthRoute() {
private func oauthRoute() {
http["/oauth"] = { request in
guard let response = AuthorizeResponse(queryParameters: request.queryParams) where response.state == self.state else {
return .BadRequest(.Text("Bad request."))
guard let response = AuthorizeResponse(queryParameters: request.queryParams), response.state == self.state else {
return .badRequest(.text("Bad request."))
}
self.oauthRequest(response)
WebAPI.oauthAccess(self.clientID, clientSecret: self.clientSecret, code: response.code, redirectURI: self.redirectURI, success: {(response) in
self.delegate?.userAuthed(OAuthResponse(response: response))
}, failure: {(error) in
print("Authorization failed")
})
if let redirect = self.redirectURI {
return .MovedPermanently(redirect)
return .movedPermanently(redirect)
}
return .OK(.Text("Authentication successful."))
return .ok(.text("Authentication successful."))
}
}
private mutating func oauthRequest(auth: AuthorizeResponse) {
WebAPI.oauthAccess(self.clientID, clientSecret: self.clientSecret, code: auth.code, redirectURI: self.redirectURI, success: {(response) in
self.delegate?.userAuthed(OAuthResponse(response: response))
}, failure: {(error) in
})
}
private func oauthURLRequest(authorize: AuthorizeRequest) -> NSURLRequest? {
private func oauthURLRequest(_ authorize: AuthorizeRequest) -> URLRequest? {
var requestString = "\(oauthURL)?client_id=\(authorize.clientID)"
requestString += authorize.parameters.requestStringFromParameters
guard let url = NSURL(string: requestString) else {
guard let url = URL(string: requestString) else {
return nil
}
return NSURLRequest(URL:url)
return URLRequest(url:url)
}
public func authorizeRequest(scope:[Scope], redirectURI: String, state: String = "slackkit", team: String? = nil) -> NSURLRequest? {
public func authorizeRequest(_ scope:[Scope], redirectURI: String, state: String = "slackkit", team: String? = nil) -> URLRequest? {
let request = AuthorizeRequest(clientID: clientID, scope: scope, redirectURI: redirectURI, state: state, team: team)
return oauthURLRequest(request)
}
+2 -2
View File
@@ -34,11 +34,11 @@ public struct Reaction {
self.user = user
}
static func reactionsFromArray(array: [[String: AnyObject]]?) -> [Reaction] {
static func reactionsFromArray(_ array: [[String: AnyObject]]?) -> [Reaction] {
var reactions = [Reaction]()
if let array = array {
for reaction in array {
if let users = reaction["users"] as? [String], name = reaction["name"] as? String {
if let users = reaction["users"] as? [String], let name = reaction["name"] as? String {
for user in users {
reactions.append(Reaction(name: name, user: user))
}
+1 -1
View File
@@ -37,7 +37,7 @@ public struct Response {
var json = [String : AnyObject]()
json["text"] = text
json["response_type"] = responseType?.rawValue
json["attachments"] = attachments?.flatMap({$0.dictionary()})
json["attachments"] = attachments?.map({$0.dictionary()})
return json
}
+19 -19
View File
@@ -25,9 +25,9 @@ import Foundation
import Swifter
internal enum Reply {
case JSON(response: Response)
case Text(body: String)
case BadRequest
case json(response: Response)
case text(body: String)
case badRequest
}
internal protocol Request {
@@ -43,7 +43,7 @@ public class Server {
self.token = token
}
public func start(port: in_port_t = 8080, forceIPV4: Bool = false) {
public func start(_ port: in_port_t = 8080, forceIPV4: Bool = false) {
do {
try http.start(port, forceIPv4: forceIPV4)
} catch let error as NSError {
@@ -55,24 +55,24 @@ public class Server {
http.stop()
}
internal func request(request:Request, reply: Reply) -> HttpResponse {
internal func request(_ request:Request, reply: Reply) -> HttpResponse {
switch reply {
case .Text(let body):
return .OK(.Text(body))
case .JSON(let response):
return .OK(.Json(response.json()))
case .BadRequest:
return .BadRequest(.Text("Bad request."))
case .text(let body):
return .ok(.text(body))
case .json(let response):
return .ok(.json(response.json()))
case .badRequest:
return .badRequest(.text("Bad request."))
}
}
internal func dictionaryFromRequest(body: [UInt8]) -> [String: AnyObject]? {
let string = NSString(data: NSData(bytes: body, length: body.count), encoding: NSUTF8StringEncoding)
if let body = string?.componentsSeparatedByString("&") {
internal func dictionaryFromRequest(_ body: [UInt8]) -> [String: AnyObject]? {
let string = String(data: Data(bytes: UnsafePointer<UInt8>(body), count: body.count), encoding: String.Encoding.utf8)
if let body = string?.components(separatedBy: "&") {
var dict: [String: AnyObject] = [:]
for argument in body {
let kv = argument.componentsSeparatedByString("=")
if let key = kv.first, value = kv.last {
let kv = argument.components(separatedBy: "=")
if let key = kv.first, let value = kv.last {
dict[key] = value
}
}
@@ -81,11 +81,11 @@ public class Server {
return nil
}
internal func jsonFromRequest(string: String) -> [String: AnyObject]? {
guard let data = string.dataUsingEncoding(NSUTF8StringEncoding) else {
internal func jsonFromRequest(_ string: String) -> [String: AnyObject]? {
guard let data = string.data(using: String.Encoding.utf8) else {
return nil
}
return (try? NSJSONSerialization.JSONObjectWithData(data, options: [])) as? [String: AnyObject] ?? nil
return (try? JSONSerialization.jsonObject(with: data, options: [])) as? [String: AnyObject] ?? nil
}
}
+1 -1
View File
@@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
public enum SlackError: String, ErrorType {
public enum SlackError: String, ErrorProtocol {
case AccountInactive = "account_inactive"
case AlreadyArchived = "already_archived"
case AlreadyInChannel = "already_in_channel"
+1 -1
View File
@@ -46,7 +46,7 @@ public final class SlackKit: OAuthDelegate {
oauth = try? OAuthServer(clientID: clientID, clientSecret: clientSecret, state: state, redirectURI: redirectURI, port: port, forceIPV4: forceIPV4, delegate: self)
}
internal func userAuthed(response: OAuthResponse) {
internal func userAuthed(_ response: OAuthResponse) {
// User auth
if let token = response.accessToken {
let client = Client(apiToken: token)
+69 -70
View File
@@ -115,7 +115,7 @@ public final class WebAPI {
}
//MARK: - RTM
public func rtmStart(simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, success: ((response: [String: AnyObject])->Void)?, failure: FailureClosure?) {
public func rtmStart(_ simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, success: ((response: [String: AnyObject])->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["simple_latest": simpleLatest, "no_unreads": noUnreads, "mpim_aware": mpimAware]
networkInterface.request(.RTMStart, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
@@ -126,7 +126,7 @@ public final class WebAPI {
}
//MARK: - Auth
public func authenticationTest(success: ((authenticated: Bool)->Void)?, failure: FailureClosure?) {
public func authenticationTest(_ success: ((authenticated: Bool)->Void)?, failure: FailureClosure?) {
networkInterface.request(.AuthTest, token: token, parameters: nil, successClosure: {
(response) -> Void in
success?(authenticated: true)
@@ -135,7 +135,7 @@ public final class WebAPI {
}
}
public static func oauthAccess(clientID: String, clientSecret: String, code: String, redirectURI: String? = nil, success: ((response: [String: AnyObject])->Void)?, failure: ((SlackError)->Void)?) {
public static func oauthAccess(_ clientID: String, clientSecret: String, code: String, redirectURI: String? = nil, success: ((response: [String: AnyObject])->Void)?, failure: ((SlackError)->Void)?) {
let parameters: [String: AnyObject?] = ["client_id": clientID, "client_secret": clientSecret, "code": code, "redirect_uri": redirectURI]
NetworkInterface().request(.OAuthAccess, parameters: filterNilParameters(parameters), successClosure: {
(response) -> Void in
@@ -145,7 +145,7 @@ public final class WebAPI {
}
}
public static func oauthRevoke(token: String, test: Bool? = nil, success: ((revoked:Bool)->Void)?, failure: ((SlackError)->Void)?) {
public static func oauthRevoke(_ token: String, test: Bool? = nil, success: ((revoked:Bool)->Void)?, failure: ((SlackError)->Void)?) {
let parameters: [String: AnyObject?] = ["token": token, "test": test]
NetworkInterface().request(.AuthRevoke, parameters: filterNilParameters(parameters), successClosure: {
(response) -> Void in
@@ -156,7 +156,7 @@ public final class WebAPI {
}
//MARK: - Channels
public func channelHistory(id: String, latest: String = "\(NSDate().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
public func channelHistory(_ id: String, latest: String = "\(Date().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
history(.ChannelsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
(history) -> Void in
success?(history: history)
@@ -165,7 +165,7 @@ public final class WebAPI {
}
}
public func channelInfo(id: String, success: ((channel: Channel)->Void)?, failure: FailureClosure?) {
public func channelInfo(_ id: String, success: ((channel: Channel)->Void)?, failure: FailureClosure?) {
info(.ChannelsInfo, type:ChannelType.Channel, id: id, success: {
(channel) -> Void in
success?(channel: channel)
@@ -174,7 +174,7 @@ public final class WebAPI {
}
}
public func channelsList(excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
public func channelsList(_ excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
list(.ChannelsList, type:ChannelType.Channel, excludeArchived: excludeArchived, success: {
(channels) -> Void in
success?(channels: channels)
@@ -183,7 +183,7 @@ public final class WebAPI {
}
}
public func markChannel(channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
public func markChannel(_ channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
mark(.ChannelsMark, channel: channel, timestamp: timestamp, success: {
(ts) -> Void in
success?(ts:timestamp)
@@ -192,7 +192,7 @@ public final class WebAPI {
}
}
public func setChannelPurpose(channel: String, purpose: String, success: ((purposeSet: Bool)->Void)?, failure: FailureClosure?) {
public func setChannelPurpose(_ channel: String, purpose: String, success: ((purposeSet: Bool)->Void)?, failure: FailureClosure?) {
setInfo(.ChannelsSetPurpose, type: .Purpose, channel: channel, text: purpose, success: {
(purposeSet) -> Void in
success?(purposeSet: purposeSet)
@@ -201,7 +201,7 @@ public final class WebAPI {
}
}
public func setChannelTopic(channel: String, topic: String, success: ((topicSet: Bool)->Void)?, failure: FailureClosure?) {
public func setChannelTopic(_ channel: String, topic: String, success: ((topicSet: Bool)->Void)?, failure: FailureClosure?) {
setInfo(.ChannelsSetTopic, type: .Topic, channel: channel, text: topic, success: {
(topicSet) -> Void in
success?(topicSet: topicSet)
@@ -211,7 +211,7 @@ public final class WebAPI {
}
//MARK: - Messaging
public func deleteMessage(channel: String, ts: String, success: ((deleted: Bool)->Void)?, failure: FailureClosure?) {
public func deleteMessage(_ channel: String, ts: String, success: ((deleted: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["channel": channel, "ts": ts]
networkInterface.request(.ChatDelete, token: token, parameters: parameters, successClosure: { (response) -> Void in
success?(deleted: true)
@@ -220,7 +220,7 @@ public final class WebAPI {
}
}
public func sendMessage(channel: String, text: String, username: String? = nil, asUser: Bool? = nil, parse: ParseMode? = nil, linkNames: Bool? = nil, attachments: [Attachment?]? = nil, unfurlLinks: Bool? = nil, unfurlMedia: Bool? = nil, iconURL: String? = nil, iconEmoji: String? = nil, success: (((ts: String?, channel: String?))->Void)?, failure: FailureClosure?) {
public func sendMessage(_ channel: String, text: String, username: String? = nil, asUser: Bool? = nil, parse: ParseMode? = nil, linkNames: Bool? = nil, attachments: [Attachment?]? = nil, unfurlLinks: Bool? = nil, unfurlMedia: Bool? = nil, iconURL: String? = nil, iconEmoji: String? = nil, success: (((ts: String?, channel: String?))->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["channel":channel, "text":text.slackFormatEscaping(), "as_user":asUser, "parse":parse?.rawValue, "link_names":linkNames, "unfurl_links":unfurlLinks, "unfurlMedia":unfurlMedia, "username":username, "attachments":encodeAttachments(attachments), "icon_url":iconURL, "icon_emoji":iconEmoji]
networkInterface.request(.ChatPostMessage, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
@@ -230,7 +230,7 @@ public final class WebAPI {
}
}
public func updateMessage(channel: String, ts: String, message: String, attachments: [Attachment?]? = nil, parse:ParseMode = .None, linkNames: Bool = false, success: ((updated: Bool)->Void)?, failure: FailureClosure?) {
public func updateMessage(_ channel: String, ts: String, message: String, attachments: [Attachment?]? = nil, parse:ParseMode = .None, linkNames: Bool = false, success: ((updated: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["channel": channel, "ts": ts, "text": message.slackFormatEscaping(), "parse": parse.rawValue, "link_names": linkNames, "attachments":encodeAttachments(attachments)]
networkInterface.request(.ChatUpdate, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
@@ -241,7 +241,7 @@ public final class WebAPI {
}
//MARK: - Do Not Disturb
public func dndInfo(user: String? = nil, success: ((status: DoNotDisturbStatus)->Void)?, failure: FailureClosure?) {
public func dndInfo(_ user: String? = nil, success: ((status: DoNotDisturbStatus)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["user": user]
networkInterface.request(.DNDInfo, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
@@ -251,8 +251,8 @@ public final class WebAPI {
}
}
public func dndTeamInfo(users: [String]? = nil, success: ((statuses: [String: DoNotDisturbStatus])->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["users":users?.joinWithSeparator(",")]
public func dndTeamInfo(_ users: [String]? = nil, success: ((statuses: [String: DoNotDisturbStatus])->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["users":users?.joined(separator: ",")]
networkInterface.request(.DNDTeamInfo, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
guard let usersDictionary = response["users"] as? [String: AnyObject] else {
@@ -266,7 +266,7 @@ public final class WebAPI {
}
//MARK: - Emoji
public func emojiList(success: ((emojiList: [String: AnyObject]?)->Void)?, failure: FailureClosure?) {
public func emojiList(_ success: ((emojiList: [String: AnyObject]?)->Void)?, failure: FailureClosure?) {
networkInterface.request(.EmojiList, token: token, parameters: nil, successClosure: {
(response) -> Void in
success?(emojiList: response["emoji"] as? [String: AnyObject])
@@ -276,7 +276,7 @@ public final class WebAPI {
}
//MARK: - Files
public func deleteFile(fileID: String, success: ((deleted: Bool)->Void)?, failure: FailureClosure?) {
public func deleteFile(_ fileID: String, success: ((deleted: Bool)->Void)?, failure: FailureClosure?) {
let parameters = ["file":fileID]
networkInterface.request(.FilesDelete, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -286,7 +286,7 @@ public final class WebAPI {
}
}
public func fileInfo(fileID: String, commentCount: Int = 100, totalPages: Int = 1, success: ((file: File)->Void)?, failure: FailureClosure?) {
public func fileInfo(_ fileID: String, commentCount: Int = 100, totalPages: Int = 1, success: ((file: File)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["file":fileID, "count": commentCount, "totalPages":totalPages]
networkInterface.request(.FilesInfo, token: token, parameters: parameters, successClosure: {
(response) in
@@ -303,8 +303,8 @@ public final class WebAPI {
}
}
public func uploadFile(file: NSData, filename: String, filetype: String = "auto", title: String? = nil, initialComment: String? = nil, channels: [String]? = nil, success: ((file: File)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["file":file, "filename": filename, "filetype":filetype, "title":title, "initial_comment":initialComment, "channels":channels?.joinWithSeparator(",")]
public func uploadFile(_ file: Data, filename: String, filetype: String = "auto", title: String? = nil, initialComment: String? = nil, channels: [String]? = nil, success: ((file: File)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["file":file, "filename": filename, "filetype":filetype, "title":title, "initial_comment":initialComment, "channels":channels?.joined(separator: ",")]
networkInterface.uploadRequest(token, data: file, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
success?(file: File(file: response["file"] as? [String: AnyObject]))
@@ -314,7 +314,7 @@ public final class WebAPI {
}
//MARK: - File Comments
public func addFileComment(fileID: String, comment: String, success: ((comment: Comment)->Void)?, failure: FailureClosure?) {
public func addFileComment(_ fileID: String, comment: String, success: ((comment: Comment)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["file":fileID, "comment":comment.slackFormatEscaping()]
networkInterface.request(.FilesCommentsAdd, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -324,7 +324,7 @@ public final class WebAPI {
}
}
public func editFileComment(fileID: String, commentID: String, comment: String, success: ((comment: Comment)->Void)?, failure: FailureClosure?) {
public func editFileComment(_ fileID: String, commentID: String, comment: String, success: ((comment: Comment)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["file":fileID, "id":commentID, "comment":comment.slackFormatEscaping()]
networkInterface.request(.FilesCommentsEdit, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -334,7 +334,7 @@ public final class WebAPI {
}
}
public func deleteFileComment(fileID: String, commentID: String, success: ((deleted: Bool?)->Void)?, failure: FailureClosure?) {
public func deleteFileComment(_ fileID: String, commentID: String, success: ((deleted: Bool?)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["file":fileID, "id": commentID]
networkInterface.request(.FilesCommentsDelete, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -345,7 +345,7 @@ public final class WebAPI {
}
//MARK: - Groups
public func closeGroup(groupID: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
public func closeGroup(_ groupID: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
close(.GroupsClose, channelID: groupID, success: {
(closed) -> Void in
success?(closed:closed)
@@ -354,7 +354,7 @@ public final class WebAPI {
}
}
public func groupHistory(id: String, latest: String = "\(NSDate().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
public func groupHistory(_ id: String, latest: String = "\(Date().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
history(.GroupsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
(history) -> Void in
success?(history: history)
@@ -363,7 +363,7 @@ public final class WebAPI {
}
}
public func groupInfo(id: String, success: ((channel: Channel)->Void)?, failure: FailureClosure?) {
public func groupInfo(_ id: String, success: ((channel: Channel)->Void)?, failure: FailureClosure?) {
info(.GroupsInfo, type:ChannelType.Group, id: id, success: {
(channel) -> Void in
success?(channel: channel)
@@ -372,7 +372,7 @@ public final class WebAPI {
}
}
public func groupsList(excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
public func groupsList(_ excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
list(.GroupsList, type:ChannelType.Group, excludeArchived: excludeArchived, success: {
(channels) -> Void in
success?(channels: channels)
@@ -381,7 +381,7 @@ public final class WebAPI {
}
}
public func markGroup(channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
public func markGroup(_ channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
mark(.GroupsMark, channel: channel, timestamp: timestamp, success: {
(ts) -> Void in
success?(ts: timestamp)
@@ -390,7 +390,7 @@ public final class WebAPI {
}
}
public func openGroup(channel: String, success: ((opened: Bool)->Void)?, failure: FailureClosure?) {
public func openGroup(_ channel: String, success: ((opened: Bool)->Void)?, failure: FailureClosure?) {
let parameters = ["channel":channel]
networkInterface.request(.GroupsOpen, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -400,7 +400,7 @@ public final class WebAPI {
}
}
public func setGroupPurpose(channel: String, purpose: String, success: ((purposeSet: Bool)->Void)?, failure: FailureClosure?) {
public func setGroupPurpose(_ channel: String, purpose: String, success: ((purposeSet: Bool)->Void)?, failure: FailureClosure?) {
setInfo(.GroupsSetPurpose, type: .Purpose, channel: channel, text: purpose, success: {
(purposeSet) -> Void in
success?(purposeSet: purposeSet)
@@ -409,7 +409,7 @@ public final class WebAPI {
}
}
public func setGroupTopic(channel: String, topic: String, success: ((topicSet: Bool)->Void)?, failure: FailureClosure?) {
public func setGroupTopic(_ channel: String, topic: String, success: ((topicSet: Bool)->Void)?, failure: FailureClosure?) {
setInfo(.GroupsSetTopic, type: .Topic, channel: channel, text: topic, success: {
(topicSet) -> Void in
success?(topicSet: topicSet)
@@ -419,7 +419,7 @@ public final class WebAPI {
}
//MARK: - IM
public func closeIM(channel: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
public func closeIM(_ channel: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
close(.IMClose, channelID: channel, success: {
(closed) -> Void in
success?(closed: closed)
@@ -428,7 +428,7 @@ public final class WebAPI {
}
}
public func imHistory(id: String, latest: String = "\(NSDate().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
public func imHistory(_ id: String, latest: String = "\(Date().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
history(.IMHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
(history) -> Void in
success?(history: history)
@@ -437,7 +437,7 @@ public final class WebAPI {
}
}
public func imsList(excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
public func imsList(_ excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
list(.IMList, type:ChannelType.IM, excludeArchived: excludeArchived, success: {
(channels) -> Void in
success?(channels: channels)
@@ -446,7 +446,7 @@ public final class WebAPI {
}
}
public func markIM(channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
public func markIM(_ channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
mark(.IMMark, channel: channel, timestamp: timestamp, success: {
(ts) -> Void in
success?(ts: timestamp)
@@ -455,7 +455,7 @@ public final class WebAPI {
}
}
public func openIM(userID: String, success: ((imID: String?)->Void)?, failure: FailureClosure?) {
public func openIM(_ userID: String, success: ((imID: String?)->Void)?, failure: FailureClosure?) {
let parameters = ["user":userID]
networkInterface.request(.IMOpen, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -467,7 +467,7 @@ public final class WebAPI {
}
//MARK: - MPIM
public func closeMPIM(channel: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
public func closeMPIM(_ channel: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
close(.MPIMClose, channelID: channel, success: {
(closed) -> Void in
success?(closed: closed)
@@ -476,7 +476,7 @@ public final class WebAPI {
}
}
public func mpimHistory(id: String, latest: String = "\(NSDate().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
public func mpimHistory(_ id: String, latest: String = "\(Date().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
history(.MPIMHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
(history) -> Void in
success?(history: history)
@@ -485,7 +485,7 @@ public final class WebAPI {
}
}
public func mpimsList(excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
public func mpimsList(_ excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
list(.MPIMList, type:ChannelType.Group, excludeArchived: excludeArchived, success: {
(channels) -> Void in
success?(channels: channels)
@@ -494,7 +494,7 @@ public final class WebAPI {
}
}
public func markMPIM(channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
public func markMPIM(_ channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
mark(.MPIMMark, channel: channel, timestamp: timestamp, success: {
(ts) -> Void in
success?(ts: timestamp)
@@ -503,8 +503,8 @@ public final class WebAPI {
}
}
public func openMPIM(userIDs: [String], success: ((mpimID: String?)->Void)?, failure: FailureClosure?) {
let parameters = ["users":userIDs.joinWithSeparator(",")]
public func openMPIM(_ userIDs: [String], success: ((mpimID: String?)->Void)?, failure: FailureClosure?) {
let parameters = ["users":userIDs.joined(separator: ",")]
networkInterface.request(.MPIMOpen, token: token, parameters: parameters, successClosure: {
(response) -> Void in
let group = response["group"] as? [String: AnyObject]
@@ -515,7 +515,7 @@ public final class WebAPI {
}
//MARK: - Pins
public func pinItem(channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((pinned: Bool)->Void)?, failure: FailureClosure?) {
public func pinItem(_ channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((pinned: Bool)->Void)?, failure: FailureClosure?) {
pin(.PinsAdd, channel: channel, file: file, fileComment: fileComment, timestamp: timestamp, success: {
(ok) -> Void in
success?(pinned: ok)
@@ -524,7 +524,7 @@ public final class WebAPI {
}
}
public func unpinItem(channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((unpinned: Bool)->Void)?, failure: FailureClosure?) {
public func unpinItem(_ channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((unpinned: Bool)->Void)?, failure: FailureClosure?) {
pin(.PinsRemove, channel: channel, file: file, fileComment: fileComment, timestamp: timestamp, success: {
(ok) -> Void in
success?(unpinned: ok)
@@ -533,7 +533,7 @@ public final class WebAPI {
}
}
private func pin(endpoint: Endpoint, channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
private func pin(_ endpoint: Endpoint, channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["channel":channel, "file":file, "file_comment":fileComment, "timestamp":timestamp]
networkInterface.request(endpoint, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
@@ -545,7 +545,7 @@ public final class WebAPI {
//MARK: - Reactions
// One of file, file_comment, or the combination of channel and timestamp must be specified.
public func addReaction(name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((reacted: Bool)->Void)?, failure: FailureClosure?) {
public func addReaction(_ name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((reacted: Bool)->Void)?, failure: FailureClosure?) {
react(.ReactionsAdd, name: name, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: {
(ok) -> Void in
success?(reacted: ok)
@@ -555,7 +555,7 @@ public final class WebAPI {
}
// One of file, file_comment, or the combination of channel and timestamp must be specified.
public func removeReaction(name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((unreacted: Bool)->Void)?, failure: FailureClosure?) {
public func removeReaction(_ name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((unreacted: Bool)->Void)?, failure: FailureClosure?) {
react(.ReactionsRemove, name: name, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: {
(ok) -> Void in
success?(unreacted: ok)
@@ -564,7 +564,7 @@ public final class WebAPI {
}
}
private func react(endpoint: Endpoint, name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
private func react(_ endpoint: Endpoint, name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["name":name, "file":file, "file_comment":fileComment, "channel":channel, "timestamp":timestamp]
networkInterface.request(endpoint, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
@@ -576,7 +576,7 @@ public final class WebAPI {
//MARK: - Stars
// One of file, file_comment, channel, or the combination of channel and timestamp must be specified.
public func addStar(file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((starred: Bool)->Void)?, failure: FailureClosure?) {
public func addStar(_ file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((starred: Bool)->Void)?, failure: FailureClosure?) {
star(.StarsAdd, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: {
(ok) -> Void in
success?(starred: ok)
@@ -586,7 +586,7 @@ public final class WebAPI {
}
// One of file, file_comment, channel, or the combination of channel and timestamp must be specified.
public func removeStar(file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((unstarred: Bool)->Void)?, failure: FailureClosure?) {
public func removeStar(_ file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((unstarred: Bool)->Void)?, failure: FailureClosure?) {
star(.StarsRemove, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: {
(ok) -> Void in
success?(unstarred: ok)
@@ -595,7 +595,7 @@ public final class WebAPI {
}
}
private func star(endpoint: Endpoint, file: String?, fileComment: String?, channel: String?, timestamp: String?, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
private func star(_ endpoint: Endpoint, file: String?, fileComment: String?, channel: String?, timestamp: String?, success: ((ok: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["file":file, "file_comment":fileComment, "channel":channel, "timestamp":timestamp]
networkInterface.request(endpoint, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
@@ -607,7 +607,7 @@ public final class WebAPI {
//MARK: - Team
public func teamInfo(success: ((info: [String: AnyObject]?)->Void)?, failure: FailureClosure?) {
public func teamInfo(_ success: ((info: [String: AnyObject]?)->Void)?, failure: FailureClosure?) {
networkInterface.request(.TeamInfo, token: token, parameters: nil, successClosure: {
(response) -> Void in
success?(info: response["team"] as? [String: AnyObject])
@@ -617,7 +617,7 @@ public final class WebAPI {
}
//MARK: - Users
public func userPresence(user: String, success: ((presence: String?)->Void)?, failure: FailureClosure?) {
public func userPresence(_ user: String, success: ((presence: String?)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["user":user]
networkInterface.request(.UsersGetPresence, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -627,7 +627,7 @@ public final class WebAPI {
}
}
public func userInfo(id: String, success: ((user: User)->Void)?, failure: FailureClosure?) {
public func userInfo(_ id: String, success: ((user: User)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["user":id]
networkInterface.request(.UsersInfo, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -637,7 +637,7 @@ public final class WebAPI {
}
}
public func usersList(includePresence: Bool = false, success: ((userList: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
public func usersList(_ includePresence: Bool = false, success: ((userList: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["presence":includePresence]
networkInterface.request(.UsersList, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -647,7 +647,7 @@ public final class WebAPI {
}
}
public func setUserActive(success: ((success: Bool)->Void)?, failure: FailureClosure?) {
public func setUserActive(_ success: ((success: Bool)->Void)?, failure: FailureClosure?) {
networkInterface.request(.UsersSetActive, token: token, parameters: nil, successClosure: {
(response) -> Void in
success?(success: true)
@@ -656,7 +656,7 @@ public final class WebAPI {
}
}
public func setUserPresence(presence: Presence, success: ((success: Bool)->Void)?, failure: FailureClosure?) {
public func setUserPresence(_ presence: Presence, success: ((success: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["presence":presence.rawValue]
networkInterface.request(.UsersSetPresence, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -667,7 +667,7 @@ public final class WebAPI {
}
//MARK: - Channel Utilities
private func close(endpoint: Endpoint, channelID: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
private func close(_ endpoint: Endpoint, channelID: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["channel":channelID]
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -677,7 +677,7 @@ public final class WebAPI {
}
}
private func history(endpoint: Endpoint, id: String, latest: String = "\(NSDate().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
private func history(_ endpoint: Endpoint, id: String, latest: String = "\(Date().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["channel": id, "latest": latest, "oldest": oldest, "inclusive":inclusive, "count":count, "unreads":unreads]
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -687,7 +687,7 @@ public final class WebAPI {
}
}
private func info(endpoint: Endpoint, type: ChannelType, id: String, success: ((channel: Channel)->Void)?, failure: FailureClosure?) {
private func info(_ endpoint: Endpoint, type: ChannelType, id: String, success: ((channel: Channel)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["channel": id]
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -697,7 +697,7 @@ public final class WebAPI {
}
}
private func list(endpoint: Endpoint, type: ChannelType, excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
private func list(_ endpoint: Endpoint, type: ChannelType, excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["exclude_archived": excludeArchived]
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -707,7 +707,7 @@ public final class WebAPI {
}
}
private func mark(endpoint: Endpoint, channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
private func mark(_ endpoint: Endpoint, channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["channel": channel, "ts": timestamp]
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -717,7 +717,7 @@ public final class WebAPI {
}
}
private func setInfo(endpoint: Endpoint, type: InfoType, channel: String, text: String, success: ((success: Bool)->Void)?, failure: FailureClosure?) {
private func setInfo(_ endpoint: Endpoint, type: InfoType, channel: String, text: String, success: ((success: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject] = ["channel": channel, type.rawValue: text]
networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: {
(response) -> Void in
@@ -728,7 +728,7 @@ public final class WebAPI {
}
//MARK: - Encode Attachments
private func encodeAttachments(attachments: [Attachment?]?) -> NSString? {
private func encodeAttachments(_ attachments: [Attachment?]?) -> String? {
if let attachments = attachments {
var attachmentArray: [[String: AnyObject]] = []
for attachment in attachments {
@@ -737,9 +737,8 @@ public final class WebAPI {
}
}
do {
let data = try NSJSONSerialization.dataWithJSONObject(attachmentArray, options: [])
let string = NSString(data: data, encoding: NSUTF8StringEncoding)
return string
let data = try JSONSerialization.data(withJSONObject: attachmentArray, options: [])
return String(data: data, encoding: String.Encoding.utf8)
} catch _ {
}
@@ -748,7 +747,7 @@ public final class WebAPI {
}
//MARK: - Filter Nil Parameters
internal static func filterNilParameters(parameters: [String: AnyObject?]) -> [String: AnyObject] {
internal static func filterNilParameters(_ parameters: [String: AnyObject?]) -> [String: AnyObject] {
var finalParameters = [String: AnyObject]()
for (key, value) in parameters {
if let unwrapped = value {
@@ -759,7 +758,7 @@ public final class WebAPI {
}
//MARK: - Enumerate Do Not Disturb Status
private func enumerateDNDStatuses(statuses: [String: AnyObject]) -> [String: DoNotDisturbStatus] {
private func enumerateDNDStatuses(_ statuses: [String: AnyObject]) -> [String: DoNotDisturbStatus] {
var retVal = [String: DoNotDisturbStatus]()
for key in statuses.keys {
retVal[key] = DoNotDisturbStatus(status: statuses[key] as? [String: AnyObject])
+5 -5
View File
@@ -28,22 +28,22 @@ public class WebhookServer: Server {
addRoute(route, response: response)
}
public func addRoute(route: String, response: Response) {
public func addRoute(_ route: String, response: Response) {
http["/\(route)"] = { request in
let webhookRequest = WebhookRequest(request: self.dictionaryFromRequest(request.body))
if webhookRequest.token == self.token {
return self.request(webhookRequest, reply: self.replyForResponse(response))
} else {
return .BadRequest(.Text("Bad request."))
return .badRequest(.text("Bad request."))
}
}
}
private func replyForResponse(response: Response) -> Reply {
private func replyForResponse(_ response: Response) -> Reply {
if response.attachments == nil && response.responseType == nil {
return Reply.Text(body: response.text)
return Reply.text(body: response.text)
} else {
return Reply.JSON(response: response)
return Reply.json(response: response)
}
}