Compare commits

..

6 Commits

Author SHA1 Message Date
Peter Zignego 247fe176fe Version bump 2016-09-26 00:05:56 -04:00
Peter Zignego c7365455d2 Update readme 2016-09-25 18:10:26 -04:00
Peter Zignego 3a03f745bf CocoaPods 2016-09-25 18:10:20 -04:00
Peter Zignego d291975368 SPM doesn’t support Swift 2.3 2016-09-25 18:08:31 -04:00
Peter Zignego cd273f266e Update Cartfile with 2.3 targets 2016-09-25 12:51:15 -04:00
Peter Zignego a01c51dd0d Set SWIFT_VERSION = 2.3 2016-09-25 12:49:07 -04:00
59 changed files with 959 additions and 954 deletions
+1 -1
View File
@@ -1 +1 @@
3.0
2.3
+2 -2
View File
@@ -1,2 +1,2 @@
git "https://github.com/daltoniam/Starscream" == 2.0.0
git "https://github.com/pvzig/swifter.git" == 3.0.4
github "daltoniam/Starscream" "swift-23"
github "pvzig/swifter.git" "077f1000d26cc5fa436a26e6d67284130b735a12"
+2 -2
View File
@@ -1,2 +1,2 @@
git "https://github.com/daltoniam/Starscream" "2.0.0"
git "https://github.com/pvzig/swifter.git" "3.0.4"
github "daltoniam/Starscream" "8f3761215b3bd70d5111048e5e3ac435c862c13d"
github "pvzig/swifter" "077f1000d26cc5fa436a26e6d67284130b735a12"
-11
View File
@@ -1,11 +0,0 @@
import PackageDescription
let package = Package(
name: "SlackKit",
targets: [],
dependencies: [
.Package(url: "https://github.com/pvzig/swifter.git",
majorVersion: 3, minor: 0),
.Package(url: "https://github.com/daltoniam/Starscream", majorVersion: 2, minor: 0)
]
)
+15 -6
View File
@@ -3,16 +3,25 @@ source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
target 'SlackKit OS X' do
pod 'Starscream', '~> 2.0.0'
pod 'Swifter', '~> 1.3.2'
pod 'Starscream', :git => 'https://github.com/pvzig/Starscream.git', :branch => 'swift-23'
pod 'Swifter', :git => 'https://github.com/pvzig/swifter.git', :branch => 'stable'
end
target 'SlackKit iOS' do
pod 'Starscream', '~> 2.0.0'
pod 'Swifter', '~> 1.3.2'
pod 'Starscream', :git => 'https://github.com/pvzig/Starscream.git', :branch => 'swift-23'
pod 'Swifter', :git => 'https://github.com/pvzig/swifter.git', :branch => 'stable'
end
target 'SlackKit tvOS' do
pod 'Starscream', '~> 2.0.0'
pod 'Swifter', '~> 1.3.2'
pod 'Starscream', :git => 'https://github.com/pvzig/Starscream.git', :branch => 'swift-23'
pod 'Swifter', :git => 'https://github.com/pvzig/swifter.git', :branch => 'stable'
end
# Set SWIFT_VERSION to 2.3 manually
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '2.3'
end
end
end
+24 -8
View File
@@ -1,15 +1,31 @@
PODS:
- Starscream (2.0.0)
- Swifter (1.3.2)
- Starscream (1.1.4)
- Swifter (1.2.6)
DEPENDENCIES:
- Starscream (~> 2.0.0)
- Swifter (~> 1.3.2)
- Starscream (from `https://github.com/pvzig/Starscream.git`, branch `swift-23`)
- Swifter (from `https://github.com/pvzig/swifter.git`, branch `stable`)
EXTERNAL SOURCES:
Starscream:
:branch: swift-23
:git: https://github.com/pvzig/Starscream.git
Swifter:
:branch: stable
:git: https://github.com/pvzig/swifter.git
CHECKOUT OPTIONS:
Starscream:
:commit: fc5529e18f1352fbe18bf8c0d8b333e02b636a1d
:git: https://github.com/pvzig/Starscream.git
Swifter:
:commit: 077f1000d26cc5fa436a26e6d67284130b735a12
:git: https://github.com/pvzig/swifter.git
SPEC CHECKSUMS:
Starscream: 947c865596f0d6bb3f0203fee23228ed2d471468
Swifter: dd1800ba8eb3e28b22b8bd20f91a8561a0110fac
Starscream: f919aeaf81afca6d5d4d3e5f6dd136ec92af2aa1
Swifter: c6f13d053398f1e2f209c7a394dfd5e863ae0157
PODFILE CHECKSUM: 3d4e92bde92fd20d6fe672ad26f677fcbfafda1f
PODFILE CHECKSUM: eb199f4d00b2166c447035baee5537560b583b38
COCOAPODS: 1.1.0.rc.3
COCOAPODS: 1.0.1
+61 -83
View File
@@ -1,28 +1,22 @@
![SlackKit](https://cloud.githubusercontent.com/assets/8311605/10260893/5ec60f96-694e-11e5-91fd-da6845942201.png)
![Swift Version](https://img.shields.io/badge/Swift-3.0-orange.svg) ![Plaforms](https://img.shields.io/badge/Platforms-macOS,iOS,tvOS-lightgrey.svg) ![License MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg) [![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-brightgreen.svg)](https://github.com/Carthage/Carthage)
![Swift Version](https://img.shields.io/badge/Swift-2.3-orange.svg) ![Plaforms](https://img.shields.io/badge/Platforms-macOS,iOS,tvOS-lightgrey.svg) ![License MIT](https://img.shields.io/badge/License-MIT-lightgrey.svg) ![Pod Version](https://img.shields.io/badge/Pod-2.3.0-blue.svg) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-brightgreen.svg)](https://github.com/Carthage/Carthage)
## 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).
This is the **Swift 3** branch of SlackKit. SlackKit also has support for [Swift 2.3](https://github.com/pvzig/SlackKit/tree/swift2.3) and [Linux](https://github.com/pvzig/SlackKit/tree/linux).
This is the Swift 2.3 branch of SlackKit. SlackKit also has support for [Swift 3](https://github.com/pvzig/SlackKit/tree/swift3) and [Linux](https://github.com/pvzig/SlackKit/tree/linux).
#### 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 SlackKit to your pod file:
Add the pod to your podfile:
```
use_frameworks!
pod 'SlackKit', '~> 3.1.2'
pod 'SlackKit'
```
and run
```
# Use CocoaPods version >= 1.1.0.rc.2 (gem install cocoapods --pre)
pod install
```
@@ -30,7 +24,7 @@ pod install
Add SlackKit to your Cartfile:
```
github "https://github.com/pvzig/slackkit.git"
github "pvzig/SlackKit" ~> 2.3
```
and run
```
@@ -40,24 +34,8 @@ carthage bootstrap
```
carthage bootstrap --configuration "Debug"
```
Drag the built `SlackKit.framework` into your Xcode project.
#### Swift Package Manager
Add SlackKit to your Package.swift
```swift
import PackageDescription
let package = Package(
dependencies: [
.Package(url: "https://github.com/pvzig/SlackKit.git", majorVersion: 3)
]
)
```
Run `swift build` on your applications main directory.
To use the library in your project import it:
```
import SlackKit
@@ -152,7 +130,6 @@ SlackKit currently supports the a subset of the Slack Web APIs that are availabl
- channels.setPurpose
- channels.setTopic
- chat.delete
- chat.meMessage
- chat.postMessage
- chat.update
- emoji.list
@@ -200,22 +177,23 @@ SlackKit currently supports the a subset of the Slack Web APIs that are availabl
They can be accessed through a Client objects `webAPI` property:
```swift
client.webAPI.authenticationTest({(auth) in
print(auth)
}, failure: {(error) in
client.webAPI.authenticationTest({ (authenticated) -> Void in
print(authenticated)
}){(error) -> Void in
print(error)
})
}
```
#### Delegate methods
To receive delegate callbacks for events, register an object as the delegate for those events using the `onClientInitalization` block:
```swift
let bot = SlackKit(clientID: clientID, clientSecret: clientSecret)
let bot = SlackKit(clientID: "CLIENT_ID", clientSecret: "CLIENT_SECRET")
bot.onClientInitalization = { (client: Client) in
DispatchQueue.main.async(execute: {
dispatch_async(dispatch_get_main_queue(), {
client.connectionEventsDelegate = self
client.messageEventsDelegate = self
})
})
}
```
@@ -225,90 +203,90 @@ There are a number of delegates that you can set to receive callbacks for certai
##### ConnectionEventsDelegate
```swift
connected(_ client: Client)
disconnected(_ client: Client)
connectionFailed(_ client: Client, error: SlackError)
clientConnected(client: Client)
clientDisconnected(client: Client)
clientConnectionFailed(client: Client, error: SlackError)
```
##### MessageEventsDelegate
```swift
sent(_ message: Message, client: Client)
received(_ message: Message, client: Client)
changed(_ message: Message, client: Client)
deleted(_ message: Message?, client: Client)
messageSent(client: Client, message: Message)
messageReceived(client: Client, message: Message)
messageChanged(client: Client, message: Message)
messageDeleted(client: Client, message: Message?)
```
##### ChannelEventsDelegate
```swift
userTypingIn(_ channel: Channel, user: User, client: Client)
marked(_ channel: Channel, timestamp: String, client: Client)
created(_ channel: Channel, client: Client)
deleted(_ channel: Channel, client: Client)
renamed(_ channel: Channel, client: Client)
archived(_ channel: Channel, client: Client)
historyChanged(_ channel: Channel, client: Client)
joined(_ channel: Channel, client: Client)
left(_ channel: Channel, client: Client)
userTyping(client: Client, channel: Channel, user: User)
channelMarked(client: Client, channel: Channel, timestamp: String)
channelCreated(client: Client, channel: Channel)
channelDeleted(client: Client, channel: Channel)
channelRenamed(client: Client, channel: Channel)
channelArchived(client: Client, channel: Channel)
channelHistoryChanged(client: Client, channel: Channel)
channelJoined(client: Client, channel: Channel)
channelLeft(client: Client, channel: Channel)
```
##### DoNotDisturbEventsDelegate
```swift
updated(_ status: DoNotDisturbStatus, client: Client)
userUpdated(_ status: DoNotDisturbStatus, user: User, client: Client)
doNotDisturbUpdated(client: Client, dndStatus: DoNotDisturbStatus)
doNotDisturbUserUpdated(client: Client, dndStatus: DoNotDisturbStatus, user: User)
```
##### GroupEventsDelegate
```swift
opened(_ group: Channel, client: Client)
groupOpened(client: Client, group: Channel)
```
##### FileEventsDelegate
```swift
processed(_ file: File, client: Client)
madePrivate(_ file: File, client: Client)
deleted(_ file: File, client: Client)
commentAdded(_ file: File, comment: Comment, client: Client)
commentEdited(_ file: File, comment: Comment, client: Client)
commentDeleted(_ file: File, comment: Comment, client: Client)
fileProcessed(client: Client, file: File)
fileMadePrivate(client: Client, file: File)
fileDeleted(client: Client, file: File)
fileCommentAdded(client: Client, file: File, comment: Comment)
fileCommentEdited(client: Client, file: File, comment: Comment)
fileCommentDeleted(client: Client, file: File, comment: Comment)
```
##### PinEventsDelegate
```swift
pinned(_ item: Item, channel: Channel?, client: Client)
unpinned(_ item: Item, channel: Channel?, client: Client)
itemPinned(client: Client, item: Item, channel: Channel?)
itemUnpinned(client: Client, item: Item, channel: Channel?)
```
##### StarEventsDelegate
```swift
starred(_ item: Item, starred: Bool, _ client: Client)
itemStarred(client: Client, item: Item, star: Bool)
```
##### ReactionEventsDelegate
```swift
added(_ reaction: String, item: Item, itemUser: String, client: Client)
removed(_ reaction: String, item: Item, itemUser: String, client: Client)
reactionAdded(client: Client, reaction: String, item: Item, itemUser: String)
reactionRemoved(client: Client, reaction: String, item: Item, itemUser: String)
```
##### SlackEventsDelegate
```swift
preferenceChanged(_ preference: String, value: Any?, client: Client)
userChanged(_ user: User, client: Client)
presenceChanged(_ user: User, presence: String, client: Client)
manualPresenceChanged(_ user: User, presence: String, client: Client)
botEvent(_ bot: Bot, client: Client)
preferenceChanged(client: Client, preference: String, value: AnyObject?)
userChanged(client: Client, user: User)
presenceChanged(client: Client, user: User, presence: String)
manualPresenceChanged(client: Client, user: User, presence: String)
botEvent(client: Client, bot: Bot)
```
##### TeamEventsDelegate
```swift
userJoined(_ user: User, client: Client)
planChanged(_ plan: String, client: Client)
preferencesChanged(_ preference: String, value: Any?, client: Client)
nameChanged(_ name: String, client: Client)
domainChanged(_ domain: String, client: Client)
emailDomainChanged(_ domain: String, client: Client)
emojiChanged(_ client: Client)
teamJoined(client: Client, user: User)
teamPlanChanged(client: Client, plan: String)
teamPreferencesChanged(client: Client, preference: String, value: AnyObject?)
teamNameChanged(client: Client, name: String)
teamDomainChanged(client: Client, domain: String)
teamEmailDomainChanged(client: Client, domain: String)
teamEmojiChanged(client: Client)
```
##### SubteamEventsDelegate
```swift
event(_ userGroup: UserGroup, client: Client)
selfAdded(_ subteamID: String, client: Client)
selfRemoved(_ subteamID: String, client: Client)
subteamEvent(client: Client, userGroup: UserGroup)
subteamSelfAdded(client: Client, subteamID: String)
subteamSelfRemoved(client: Client, subteamID: String)
```
##### TeamProfileEventsDelegate
```swift
changed(_ profile: CustomProfile, client: Client)
deleted(_ profile: CustomProfile, client: Client)
reordered(_ profile: CustomProfile, client: Client)
teamProfileChanged(client: Client, profile: CustomProfile)
teamProfileDeleted(client: Client, profile: CustomProfile)
teamProfileReordered(client: Client, profile: CustomProfile)
```
### Examples
+3 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SlackKit"
s.version = "3.1.2"
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'
@@ -13,6 +13,7 @@ Pod::Spec.new do |s|
s.requires_arc = true
s.source_files = 'SlackKit/Sources/*.swift'
s.frameworks = 'Foundation'
s.dependency 'Starscream'
s.dependency 'Starscream', '~> 1.1.3'
s.dependency 'Swifter'
end
+23 -37
View File
@@ -30,6 +30,7 @@
263993A71CE90EE0004A6E93 /* Client+EventHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A85FF81CE3BCEF00756C40 /* Client+EventHandling.swift */; };
263993A81CE90EE0004A6E93 /* NetworkInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260EC2311C4DC61D0093B253 /* NetworkInterface.swift */; };
263993A91CE90EE0004A6E93 /* EventDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26BBA18B1C398E3C00BF7225 /* EventDelegate.swift */; };
263993AB1CE90EE0004A6E93 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4307A07F1CC6D0910011D5DE /* Starscream.framework */; };
263993AD1CE90EE0004A6E93 /* SlackKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 2661A6A41BBF62FF0026F67B /* SlackKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
263993B61CE90EED004A6E93 /* Client+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = C16C98791CE7D3DD00692776 /* Client+Utilities.swift */; };
263993B71CE90EED004A6E93 /* Channel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26BBA1881C398E3C00BF7225 /* Channel.swift */; };
@@ -49,13 +50,8 @@
263993C61CE90EED004A6E93 /* Client+EventHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A85FF81CE3BCEF00756C40 /* Client+EventHandling.swift */; };
263993C71CE90EED004A6E93 /* NetworkInterface.swift in Sources */ = {isa = PBXBuildFile; fileRef = 260EC2311C4DC61D0093B253 /* NetworkInterface.swift */; };
263993C81CE90EED004A6E93 /* EventDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26BBA18B1C398E3C00BF7225 /* EventDelegate.swift */; };
263993CA1CE90EED004A6E93 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4307A07F1CC6D0910011D5DE /* Starscream.framework */; };
263993CC1CE90EED004A6E93 /* SlackKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 2661A6A41BBF62FF0026F67B /* SlackKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
2659FC1B1DADC4E0003F3930 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4307A07F1CC6D0910011D5DE /* Starscream.framework */; };
2659FC1C1DADC4E0003F3930 /* Swifter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26B30B6B1D289FA0004D4AB5 /* Swifter.framework */; };
2659FC1D1DADC4F2003F3930 /* Swifter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 26B30B6E1D289FB2004D4AB5 /* Swifter.framework */; };
2659FC1F1DADC4F2003F3930 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2659FC1E1DADC4F2003F3930 /* Starscream.framework */; };
2659FC201DADC4FC003F3930 /* Swifter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 269B47CB1D3AE5670042D137 /* Swifter.framework */; };
2659FC221DADC4FC003F3930 /* Starscream.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2659FC211DADC4FC003F3930 /* Starscream.framework */; };
2678B5941D3151B900CE521A /* AuthorizeResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2678B5931D3151B900CE521A /* AuthorizeResponse.swift */; };
2678B5951D3151B900CE521A /* AuthorizeResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2678B5931D3151B900CE521A /* AuthorizeResponse.swift */; };
2678B5961D3151B900CE521A /* AuthorizeResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2678B5931D3151B900CE521A /* AuthorizeResponse.swift */; };
@@ -78,9 +74,12 @@
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 */; };
@@ -148,6 +147,7 @@
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 */; };
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 */; };
C1A85FFA1CE3BCEF00756C40 /* Client+EventHandling.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A85FF81CE3BCEF00756C40 /* Client+EventHandling.swift */; };
@@ -161,8 +161,6 @@
260EC2321C4DC61D0093B253 /* WebAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebAPI.swift; path = Sources/WebAPI.swift; sourceTree = "<group>"; };
263993B21CE90EE0004A6E93 /* SlackKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SlackKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
263993D11CE90EED004A6E93 /* SlackKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SlackKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2659FC1E1DADC4F2003F3930 /* Starscream.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Starscream.framework; path = Carthage/Build/iOS/Starscream.framework; sourceTree = "<group>"; };
2659FC211DADC4FC003F3930 /* Starscream.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Starscream.framework; path = Carthage/Build/tvOS/Starscream.framework; sourceTree = "<group>"; };
2661A6A41BBF62FF0026F67B /* SlackKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SlackKit.h; sourceTree = "<group>"; };
2678B5931D3151B900CE521A /* AuthorizeResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AuthorizeResponse.swift; path = Sources/AuthorizeResponse.swift; sourceTree = "<group>"; };
268E46131CE8F79D009F19CC /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Info-iOS.plist"; path = "Supporting Files/Info-iOS.plist"; sourceTree = "<group>"; };
@@ -219,8 +217,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2659FC1B1DADC4E0003F3930 /* Starscream.framework in Frameworks */,
2659FC1C1DADC4E0003F3930 /* Swifter.framework in Frameworks */,
4307A0801CC6D0910011D5DE /* Starscream.framework in Frameworks */,
26B30B6C1D289FA0004D4AB5 /* Swifter.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -228,8 +226,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2659FC1F1DADC4F2003F3930 /* Starscream.framework in Frameworks */,
2659FC1D1DADC4F2003F3930 /* Swifter.framework in Frameworks */,
263993AB1CE90EE0004A6E93 /* Starscream.framework in Frameworks */,
26B30B6F1D289FB2004D4AB5 /* Swifter.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -237,8 +235,8 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2659FC221DADC4FC003F3930 /* Starscream.framework in Frameworks */,
2659FC201DADC4FC003F3930 /* Swifter.framework in Frameworks */,
263993CA1CE90EED004A6E93 /* Starscream.framework in Frameworks */,
269B47CC1D3AE5670042D137 /* Swifter.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -355,8 +353,6 @@
CA70A3A1A9A1A259960DFBCF /* Frameworks */ = {
isa = PBXGroup;
children = (
2659FC211DADC4FC003F3930 /* Starscream.framework */,
2659FC1E1DADC4F2003F3930 /* Starscream.framework */,
269B47CB1D3AE5670042D137 /* Swifter.framework */,
26B30B6E1D289FB2004D4AB5 /* Swifter.framework */,
26B30B6B1D289FA0004D4AB5 /* Swifter.framework */,
@@ -456,12 +452,11 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = "Launch Software LLC";
TargetAttributes = {
26072A331BB48B3A00CD650C = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
};
};
};
@@ -682,10 +677,8 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
@@ -731,10 +724,8 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
@@ -763,7 +754,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -782,7 +773,7 @@
PRODUCT_NAME = SlackKit;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 2.3;
};
name = Debug;
};
@@ -790,7 +781,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -808,8 +799,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.launchsoft.SlackKit;
PRODUCT_NAME = SlackKit;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 2.3;
};
name = Release;
};
@@ -818,7 +808,6 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -827,6 +816,7 @@
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
"$(PROJECT_DIR)/Carthage/Build/Mac",
);
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = "$(SRCROOT)/SlackKit/Supporting Files/Info-iOS.plist";
@@ -840,7 +830,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 2.3;
};
name = Debug;
};
@@ -849,7 +839,6 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -858,6 +847,7 @@
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Carthage/Build/iOS",
"$(PROJECT_DIR)/Carthage/Build/Mac",
);
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = "$(SRCROOT)/SlackKit/Supporting Files/Info-iOS.plist";
@@ -870,8 +860,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 2.3;
};
name = Release;
};
@@ -879,7 +868,6 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -900,7 +888,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvsimulator appletvos";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 2.3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Debug;
@@ -909,7 +897,6 @@
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_MODULES = YES;
"CODE_SIGN_IDENTITY[sdk=appletvos*]" = "";
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
@@ -929,8 +916,7 @@
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "appletvsimulator appletvos";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 2.3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
name = Release;
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
+10 -8
View File
@@ -30,13 +30,13 @@ public struct Action {
public let style: ActionStyle?
public let confirm: Confirm?
internal init(action:[String: Any]?) {
internal init(action:[String: AnyObject]?) {
name = action?["name"] as? String
text = action?["text"] as? String
type = action?["type"] as? String
value = action?["value"] as? String
style = ActionStyle(rawValue: action?["style"] as? String ?? "")
confirm = Confirm(confirm:action?["confirm"] as? [String: Any])
confirm = Confirm(confirm:action?["confirm"] as? [String: AnyObject])
}
public init(name: String, text: String, style: ActionStyle = .Default, value: String? = nil, confirm: Confirm? = nil) {
@@ -48,14 +48,14 @@ public struct Action {
self.confirm = confirm
}
internal var dictionary: [String: Any] {
var dict = [String: Any]()
internal func dictionary() -> [String: AnyObject] {
var dict = [String: AnyObject]()
dict["name"] = name
dict["text"] = text
dict["type"] = type
dict["value"] = value
dict["style"] = style?.rawValue
dict["confirm"] = confirm?.dictionary
dict["confirm"] = confirm?.dictionary()
return dict
}
@@ -66,7 +66,7 @@ public struct Action {
public let okText: String?
public let dismissText: String?
internal init(confirm:[String: Any]?) {
internal init(confirm:[String: AnyObject]?) {
title = confirm?["title"] as? String
text = confirm?["text"] as? String
okText = confirm?["ok_text"] as? String
@@ -80,15 +80,17 @@ public struct Action {
self.dismissText = dismissText
}
internal var dictionary: [String: Any] {
var dict = [String: Any]()
internal func dictionary() -> [String: AnyObject] {
var dict = [String: AnyObject]()
dict["title"] = title
dict["text"] = text
dict["ok_text"] = okText
dict["dismiss_text"] = dismissText
return dict
}
}
}
public enum ActionStyle: String {
+8 -7
View File
@@ -42,7 +42,7 @@ public struct Attachment {
public let footerIcon: String?
public let ts: Int?
internal init(attachment: [String: Any]?) {
internal init(attachment: [String: AnyObject]?) {
fallback = attachment?["fallback"] as? String
callbackID = attachment?["callback_id"] as? String
type = attachment?["attachment_type"] as? String
@@ -59,8 +59,8 @@ public struct Attachment {
footer = attachment?["footer"] as? String
footerIcon = attachment?["footer_icon"] as? String
ts = attachment?["ts"] as? Int
fields = (attachment?["fields"] as? [[String: Any]])?.map { AttachmentField(field: $0) }
actions = (attachment?["actions"] as? [[String: Any]])?.map { Action(action: $0) }
fields = (attachment?["fields"] as? [[String: AnyObject]])?.map { AttachmentField(field: $0) }
actions = (attachment?["actions"] as? [[String: AnyObject]])?.map { Action(action: $0) }
}
public init(fallback: String, title:String, callbackID: String? = nil, type: String? = nil, colorHex: String? = nil, pretext: String? = nil, authorName: String? = nil, authorLink: String? = nil, authorIcon: String? = nil, titleLink: String? = nil, text: String? = nil, fields: [AttachmentField]? = nil, actions: [Action]? = nil, imageURL: String? = nil, thumbURL: String? = nil, footer: String? = nil, footerIcon:String? = nil, ts:Int? = nil) {
@@ -84,8 +84,8 @@ public struct Attachment {
self.ts = ts
}
internal var dictionary: [String: Any] {
var attachment = [String: Any]()
internal func dictionary() -> [String: AnyObject] {
var attachment = [String: AnyObject]()
attachment["fallback"] = fallback
attachment["callback_id"] = callbackID
attachment["attachment_type"] = type
@@ -97,8 +97,8 @@ public struct Attachment {
attachment["title"] = title
attachment["title_link"] = titleLink
attachment["text"] = text
attachment["fields"] = fields?.map{$0.dictionary}
attachment["actions"] = actions?.map{$0.dictionary}
attachment["fields"] = fields?.map{$0.dictionary()}
attachment["actions"] = actions?.map{$0.dictionary()}
attachment["image_url"] = imageURL
attachment["thumb_url"] = thumbURL
attachment["footer"] = footer
@@ -106,6 +106,7 @@ public struct Attachment {
attachment["ts"] = ts
return attachment
}
}
public enum AttachmentColor: String {
+5 -4
View File
@@ -27,7 +27,7 @@ public struct AttachmentField {
public let value: String?
public let short: Bool?
internal init(field: [String: Any]?) {
internal init(field: [String: AnyObject]?) {
title = field?["title"] as? String
value = field?["value"] as? String
short = field?["short"] as? Bool
@@ -35,15 +35,16 @@ public struct AttachmentField {
public init(title:String, value:String, short: Bool? = nil) {
self.title = title
self.value = value.slackFormatEscaping
self.value = value.slackFormatEscaping()
self.short = short
}
internal var dictionary: [String: Any] {
var field = [String: Any]()
internal func dictionary() -> [String: AnyObject] {
var field = [String: AnyObject]()
field["title"] = title
field["value"] = value
field["short"] = short
return field
}
}
+5 -4
View File
@@ -29,9 +29,9 @@ internal struct AuthorizeRequest {
let state: String
let team: String?
var parameters: [String: Any] {
var json = [String : Any]()
json["scope"] = scope.map({$0.rawValue}).joined(separator: ",")
var parameters: [String: AnyObject] {
var json = [String : AnyObject]()
json["scope"] = scope.map({$0.rawValue}).joinWithSeparator(",")
json["state"] = state
json["team"] = team
return json
@@ -44,4 +44,5 @@ internal struct AuthorizeRequest {
self.state = state
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, let state = queryParameters.last?.1 else {
guard let code = queryParameters.first?.1, state = queryParameters.last?.1 else {
return nil
}
self.code = code
+5 -4
View File
@@ -26,16 +26,17 @@ public struct Bot {
public let id: String?
internal(set) public var botToken: String?
internal(set) public var name: String?
internal(set) public var icons: [String: Any]?
internal(set) public var icons: [String: AnyObject]?
internal init(bot: [String: Any]?) {
internal init(bot: [String: AnyObject]?) {
id = bot?["id"] as? String
name = bot?["name"] as? String
icons = bot?["icons"] as? [String: Any]
icons = bot?["icons"] as? [String: AnyObject]
}
internal init(botUser: [String: Any]?) {
internal init(botUser: [String: AnyObject]?) {
id = botUser?["bot_user_id"] as? String
botToken = botUser?["bot_access_token"] as? String
}
}
+5 -5
View File
@@ -49,7 +49,7 @@ public struct Channel {
internal(set) public var usersTyping = [String]()
internal(set) public var messages = [String: Message]()
internal init(channel: [String: Any]?) {
internal init(channel: [String: AnyObject]?) {
id = channel?["id"] as? String
name = channel?["name"] as? String
created = channel?["created"] as? Int
@@ -62,8 +62,8 @@ public struct Channel {
isUserDeleted = channel?["is_user_deleted"] as? Bool
user = channel?["user"] as? String
isOpen = channel?["is_open"] as? Bool
topic = Topic(topic: channel?["topic"] as? [String: Any])
purpose = Topic(topic: channel?["purpose"] as? [String: Any])
topic = Topic(topic: channel?["topic"] as? [String: AnyObject])
purpose = Topic(topic: channel?["purpose"] as? [String: AnyObject])
isMember = channel?["is_member"] as? Bool
lastRead = channel?["last_read"] as? String
unread = channel?["unread_count"] as? Int
@@ -71,8 +71,8 @@ public struct Channel {
hasPins = channel?["has_pins"] as? Bool
members = channel?["members"] as? [String]
if let latestMesssageDictionary = channel?["latest"] as? [String: Any] {
latest = Message(dictionary: latestMesssageDictionary)
if let latestMsgDictionary = channel?["latest"] as? [String: AnyObject] {
latest = Message(message: latestMsgDictionary)
} else {
latest = Message(ts: channel?["latest"] as? String)
}
@@ -23,7 +23,7 @@
internal extension Client {
func dispatch(_ event: [String: Any]) {
func dispatch(event: [String: AnyObject]) {
let event = Event(event: event)
guard let type = event.type else {
return
@@ -31,7 +31,7 @@ internal extension Client {
switch type {
case .Hello:
connected = true
connectionEventsDelegate?.connected(self)
connectionEventsDelegate?.clientConnected(self)
case .Ok:
messageSent(event)
case .Message:
@@ -156,11 +156,12 @@ internal extension Client {
subteamRemovedSelf(event)
case .Error:
print("Error: \(event)")
break
}
}
func messageDispatcher(_ event:Event) {
guard let value = event.subtype, let subtype = MessageSubtype(rawValue:value) else {
func messageDispatcher(event:Event) {
guard let value = event.subtype, subtype = MessageSubtype(rawValue:value) else {
return
}
switch subtype {
@@ -172,4 +173,5 @@ internal extension Client {
messageReceived(event)
}
}
}
+149 -148
View File
@@ -26,254 +26,254 @@ 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, let message = sentMessages[NSNumber(value: reply).stringValue], let channel = message.channel, let ts = message.ts else {
func messageSent(event: Event) {
guard let reply = event.replyTo, message = sentMessages[NSNumber(double: reply).stringValue], channel = message.channel, ts = message.ts else {
return
}
message.ts = event.ts
message.text = event.text
channels[channel]?.messages[ts] = message
messageEventsDelegate?.sent(message, client: self)
messageEventsDelegate?.messageSent(self, message: message)
}
func messageReceived(_ event: Event) {
guard let channel = event.channel, let message = event.message, let id = channel.id, let ts = message.ts else {
func messageReceived(event: Event) {
guard let channel = event.channel, message = event.message, id = channel.id, ts = message.ts else {
return
}
channels[id]?.messages[ts] = message
messageEventsDelegate?.received(message, client:self)
messageEventsDelegate?.messageReceived(self, message: message)
}
func messageChanged(_ event: Event) {
guard let id = event.channel?.id, let nested = event.nestedMessage, let ts = nested.ts else {
func messageChanged(event: Event) {
guard let id = event.channel?.id, nested = event.nestedMessage, ts = nested.ts else {
return
}
channels[id]?.messages[ts] = nested
messageEventsDelegate?.changed(nested, client:self)
messageEventsDelegate?.messageChanged(self, message: nested)
}
func messageDeleted(_ event: Event) {
guard let id = event.channel?.id, let key = event.message?.deletedTs, let message = channels[id]?.messages[key] else {
func messageDeleted(event: Event) {
guard let id = event.channel?.id, key = event.message?.deletedTs, message = channels[id]?.messages[key] else {
return
}
_ = channels[id]?.messages.removeValue(forKey: key)
messageEventsDelegate?.deleted(message, client:self)
channels[id]?.messages.removeValueForKey(key)
messageEventsDelegate?.messageDeleted(self, message: message)
}
//MARK: - Channels
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 {
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 {
return
}
channels[channelID]?.usersTyping.append(userID)
channelEventsDelegate?.userTypingIn(channel, user: user, client: self)
channelEventsDelegate?.userTyping(self, channel: channel, user: user)
let timeout = DispatchTime.now() + Double(Int64(5.0 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
DispatchQueue.main.asyncAfter(deadline: timeout, execute: {
if let index = self.channels[channelID]?.usersTyping.index(of: userID) {
self.channels[channelID]?.usersTyping.remove(at: index)
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)
}
})
}
}
func channelMarked(_ event: Event) {
guard let channel = event.channel, let id = channel.id, let timestamp = event.ts else {
func channelMarked(event: Event) {
guard let channel = event.channel, id = channel.id, timestamp = event.ts else {
return
}
channels[id]?.lastRead = event.ts
channelEventsDelegate?.marked(channel, timestamp: timestamp, client: self)
channelEventsDelegate?.channelMarked(self, channel: channel, timestamp: timestamp)
}
func channelCreated(_ event: Event) {
guard let channel = event.channel, let id = channel.id else {
func channelCreated(event: Event) {
guard let channel = event.channel, id = channel.id else {
return
}
channels[id] = channel
channelEventsDelegate?.created(channel, client: self)
channelEventsDelegate?.channelCreated(self, channel: channel)
}
func channelDeleted(_ event: Event) {
guard let channel = event.channel, let id = channel.id else {
func channelDeleted(event: Event) {
guard let channel = event.channel, id = channel.id else {
return
}
channels.removeValue(forKey: id)
channelEventsDelegate?.deleted(channel, client: self)
channels.removeValueForKey(id)
channelEventsDelegate?.channelDeleted(self, channel: channel)
}
func channelJoined(_ event: Event) {
guard let channel = event.channel, let id = channel.id else {
func channelJoined(event: Event) {
guard let channel = event.channel, id = channel.id else {
return
}
channels[id] = event.channel
channelEventsDelegate?.joined(channel, client: self)
channelEventsDelegate?.channelJoined(self, channel: channel)
}
func channelLeft(_ event: Event) {
guard let channel = event.channel, let id = channel.id else {
func channelLeft(event: Event) {
guard let channel = event.channel, id = channel.id else {
return
}
if let userID = authenticatedUser?.id, let index = channels[id]?.members?.index(of: userID) {
channels[id]?.members?.remove(at: index)
if let userID = authenticatedUser?.id, index = channels[id]?.members?.indexOf(userID) {
channels[id]?.members?.removeAtIndex(index)
}
channelEventsDelegate?.left(channel, client: self)
channelEventsDelegate?.channelLeft(self, channel: channel)
}
func channelRenamed(_ event: Event) {
guard let channel = event.channel, let id = channel.id else {
func channelRenamed(event: Event) {
guard let channel = event.channel, id = channel.id else {
return
}
channels[id]?.name = channel.name
channelEventsDelegate?.renamed(channel, client: self)
channelEventsDelegate?.channelRenamed(self, channel: channel)
}
func channelArchived(_ event: Event, archived: Bool) {
guard let channel = event.channel, let id = channel.id else {
func channelArchived(event: Event, archived: Bool) {
guard let channel = event.channel, id = channel.id else {
return
}
channels[id]?.isArchived = archived
channelEventsDelegate?.archived(channel, client: self)
channelEventsDelegate?.channelArchived(self, channel: channel)
}
func channelHistoryChanged(_ event: Event) {
func channelHistoryChanged(event: Event) {
guard let channel = event.channel else {
return
}
channelEventsDelegate?.historyChanged(channel, client: self)
channelEventsDelegate?.channelHistoryChanged(self, channel: channel)
}
//MARK: - Do Not Disturb
func doNotDisturbUpdated(_ event: Event) {
func doNotDisturbUpdated(event: Event) {
guard let dndStatus = event.dndStatus else {
return
}
authenticatedUser?.doNotDisturbStatus = dndStatus
doNotDisturbEventsDelegate?.updated(dndStatus, client: self)
doNotDisturbEventsDelegate?.doNotDisturbUpdated(self, dndStatus: dndStatus)
}
func doNotDisturbUserUpdated(_ event: Event) {
guard let dndStatus = event.dndStatus, let user = event.user, let id = user.id else {
func doNotDisturbUserUpdated(event: Event) {
guard let dndStatus = event.dndStatus, user = event.user, id = user.id else {
return
}
users[id]?.doNotDisturbStatus = dndStatus
doNotDisturbEventsDelegate?.userUpdated(dndStatus, user: user, client: self)
doNotDisturbEventsDelegate?.doNotDisturbUserUpdated(self, dndStatus: dndStatus, user: user)
}
//MARK: - IM & Group Open/Close
func open(_ event: Event, open: Bool) {
guard let channel = event.channel, let id = channel.id else {
func open(event: Event, open: Bool) {
guard let channel = event.channel, id = channel.id else {
return
}
channels[id]?.isOpen = open
groupEventsDelegate?.opened(channel, client: self)
groupEventsDelegate?.groupOpened(self, group: channel)
}
//MARK: - Files
func processFile(_ event: Event) {
guard let file = event.file, let id = file.id else {
func processFile(event: Event) {
guard let file = event.file, id = file.id else {
return
}
if let comment = file.initialComment, let commentID = comment.id {
if let comment = file.initialComment, commentID = comment.id {
if files[id]?.comments[commentID] == nil {
files[id]?.comments[commentID] = comment
}
}
files[id] = file
fileEventsDelegate?.processed(file, client: self)
fileEventsDelegate?.fileProcessed(self, file: file)
}
func filePrivate(_ event: Event) {
guard let file = event.file, let id = file.id else {
func filePrivate(event: Event) {
guard let file = event.file, id = file.id else {
return
}
files[id]?.isPublic = false
fileEventsDelegate?.madePrivate(file, client: self)
fileEventsDelegate?.fileMadePrivate(self, file: file)
}
func deleteFile(_ event: Event) {
guard let file = event.file, let id = file.id else {
func deleteFile(event: Event) {
guard let file = event.file, id = file.id else {
return
}
if files[id] != nil {
files.removeValue(forKey: id)
files.removeValueForKey(id)
}
fileEventsDelegate?.deleted(file, client: self)
fileEventsDelegate?.fileDeleted(self, file: file)
}
func fileCommentAdded(_ event: Event) {
guard let file = event.file, let id = file.id, let comment = event.comment, let commentID = comment.id else {
func fileCommentAdded(event: Event) {
guard let file = event.file, id = file.id, comment = event.comment, commentID = comment.id else {
return
}
files[id]?.comments[commentID] = comment
fileEventsDelegate?.commentAdded(file, comment: comment, client: self)
fileEventsDelegate?.fileCommentAdded(self, file: file, comment: comment)
}
func fileCommentEdited(_ event: Event) {
guard let file = event.file, let id = file.id, let comment = event.comment, let commentID = comment.id else {
func fileCommentEdited(event: Event) {
guard let file = event.file, id = file.id, comment = event.comment, commentID = comment.id else {
return
}
files[id]?.comments[commentID]?.comment = comment.comment
fileEventsDelegate?.commentAdded(file, comment: comment, client: self)
fileEventsDelegate?.fileCommentEdited(self, file: file, comment: comment)
}
func fileCommentDeleted(_ event: Event) {
guard let file = event.file, let id = file.id, let comment = event.comment, let commentID = comment.id else {
func fileCommentDeleted(event: Event) {
guard let file = event.file, id = file.id, comment = event.comment, commentID = comment.id else {
return
}
_ = files[id]?.comments.removeValue(forKey: commentID)
fileEventsDelegate?.commentDeleted(file, comment: comment, client: self)
files[id]?.comments.removeValueForKey(commentID)
fileEventsDelegate?.fileCommentDeleted(self, file: file, comment: comment)
}
//MARK: - Pins
func pinAdded(_ event: Event) {
guard let id = event.channelID, let item = event.item else {
func pinAdded(event: Event) {
guard let id = event.channelID, item = event.item else {
return
}
channels[id]?.pinnedItems.append(item)
pinEventsDelegate?.pinned(item, channel: channels[id], client: self)
pinEventsDelegate?.itemPinned(self, item: item, channel: channels[id])
}
func pinRemoved(_ event: Event) {
guard let id = event.channelID, let item = event.item else {
func pinRemoved(event: Event) {
guard let id = event.channelID, item = event.item else {
return
}
if let pins = channels[id]?.pinnedItems.filter({$0 != item}) {
channels[id]?.pinnedItems = pins
}
pinEventsDelegate?.unpinned(item, channel: channels[id], client: self)
pinEventsDelegate?.itemUnpinned(self, item: item, channel: channels[id])
}
//MARK: - Stars
func itemStarred(_ event: Event, star: Bool) {
guard let item = event.item, let type = item.type else {
func itemStarred(event: Event, star: Bool) {
guard let item = event.item, type = item.type else {
return
}
switch type {
@@ -287,18 +287,18 @@ internal extension Client {
break
}
starEventsDelegate?.starred(item, starred: star, self)
starEventsDelegate?.itemStarred(self, item: item, star: star)
}
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 {
func starMessage(item: Item, star: Bool) {
guard let message = item.message, ts = message.ts, channel = item.channel where channels[channel]?.messages[ts] != nil else {
return
}
channels[channel]?.messages[ts]?.isStarred = star
}
func starFile(_ item: Item, star: Bool) {
guard let file = item.file, let id = file.id else {
func starFile(item: Item, star: Bool) {
guard let file = item.file, id = file.id else {
return
}
@@ -314,22 +314,22 @@ internal extension Client {
}
}
func starComment(_ item: Item) {
guard let file = item.file, let id = file.id, let comment = item.comment, let commentID = comment.id else {
func starComment(item: Item) {
guard let file = item.file, id = file.id, comment = item.comment, commentID = comment.id else {
return
}
files[id]?.comments[commentID] = comment
}
//MARK: - Reactions
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 {
func addedReaction(event: Event) {
guard let item = event.item, type = item.type, reaction = event.reaction, userID = event.user?.id, itemUser = event.itemUser else {
return
}
switch type {
case "message":
guard let channel = item.channel, let ts = item.ts, let message = channels[channel]?.messages[ts] else {
guard let channel = item.channel, ts = item.ts, 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, let commentID = item.fileCommentID else {
guard let id = item.file?.id, commentID = item.fileCommentID else {
return
}
files[id]?.comments[commentID]?.reactions.append(Reaction(name: reaction, user: userID))
@@ -347,27 +347,27 @@ internal extension Client {
break
}
reactionEventsDelegate?.added(reaction, item: item, itemUser: itemUser, client: self)
reactionEventsDelegate?.reactionAdded(self, reaction: reaction, item: item, itemUser: itemUser)
}
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 {
func removedReaction(event: Event) {
guard let item = event.item, type = item.type, key = event.reaction, userID = event.user?.id, itemUser = event.itemUser else {
return
}
switch type {
case "message":
guard let channel = item.channel, let ts = item.ts, let message = channels[channel]?.messages[ts] else {
guard let channel = item.channel, ts = item.ts, 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, let id = itemFile.id else {
guard let itemFile = item.file, 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, let commentID = item.fileCommentID else {
guard let id = item.file?.id, commentID = item.fileCommentID else {
return
}
files[id]?.comments[commentID]?.reactions = files[id]!.comments[commentID]!.reactions.filter({$0.name != key && $0.user != userID})
@@ -375,140 +375,140 @@ internal extension Client {
break
}
reactionEventsDelegate?.removed(key, item: item, itemUser: itemUser, client: self)
reactionEventsDelegate?.reactionRemoved(self, reaction: key, item: item, itemUser: itemUser)
}
//MARK: - Preferences
func changePreference(_ event: Event) {
func changePreference(event: Event) {
guard let name = event.name else {
return
}
authenticatedUser?.preferences?[name] = event.value
slackEventsDelegate?.preferenceChanged(name, value: event.value, client: self)
slackEventsDelegate?.preferenceChanged(self, preference: name, value: event.value)
}
//Mark: - User Change
func userChange(_ event: Event) {
guard let user = event.user, let id = user.id else {
func userChange(event: Event) {
guard let user = event.user, id = user.id else {
return
}
let preferences = users[id]?.preferences
users[id] = user
users[id]?.preferences = preferences
slackEventsDelegate?.userChanged(user, client: self)
slackEventsDelegate?.userChanged(self, user: user)
}
//MARK: - User Presence
func presenceChange(_ event: Event) {
guard let user = event.user, let id = user.id, let presence = event.presence else {
func presenceChange(event: Event) {
guard let user = event.user, id = user.id, presence = event.presence else {
return
}
users[id]?.presence = event.presence
slackEventsDelegate?.presenceChanged(user, presence: presence, client: self)
slackEventsDelegate?.presenceChanged(self, user: user, presence: presence)
}
//MARK: - Team
func teamJoin(_ event: Event) {
guard let user = event.user, let id = user.id else {
func teamJoin(event: Event) {
guard let user = event.user, id = user.id else {
return
}
users[id] = user
teamEventsDelegate?.userJoined(user, client: self)
teamEventsDelegate?.teamJoined(self, user: user)
}
func teamPlanChange(_ event: Event) {
func teamPlanChange(event: Event) {
guard let plan = event.plan else {
return
}
team?.plan = plan
teamEventsDelegate?.planChanged(plan, client: self)
teamEventsDelegate?.teamPlanChanged(self, plan: plan)
}
func teamPreferenceChange(_ event: Event) {
func teamPreferenceChange(event: Event) {
guard let name = event.name else {
return
}
team?.prefs?[name] = event.value
teamEventsDelegate?.preferencesChanged(name, value: event.value, client: self)
teamEventsDelegate?.teamPreferencesChanged(self, preference: name, value: event.value)
}
func teamNameChange(_ event: Event) {
func teamNameChange(event: Event) {
guard let name = event.name else {
return
}
team?.name = name
teamEventsDelegate?.nameChanged(name, client: self)
teamEventsDelegate?.teamNameChanged(self, name: name)
}
func teamDomainChange(_ event: Event) {
func teamDomainChange(event: Event) {
guard let domain = event.domain else {
return
}
team?.domain = domain
teamEventsDelegate?.domainChanged(domain, client: self)
teamEventsDelegate?.teamDomainChanged(self, domain: domain)
}
func emailDomainChange(_ event: Event) {
func emailDomainChange(event: Event) {
guard let domain = event.emailDomain else {
return
}
team?.emailDomain = domain
teamEventsDelegate?.emailDomainChanged(domain, client: self)
teamEventsDelegate?.teamEmailDomainChanged(self, domain: domain)
}
func emojiChanged(_ event: Event) {
teamEventsDelegate?.emojiChanged(self)
func emojiChanged(event: Event) {
teamEventsDelegate?.teamEmojiChanged(self)
}
//MARK: - Bots
func bot(_ event: Event) {
guard let bot = event.bot, let id = bot.id else {
func bot(event: Event) {
guard let bot = event.bot, id = bot.id else {
return
}
bots[id] = bot
slackEventsDelegate?.botEvent(bot, client: self)
slackEventsDelegate?.botEvent(self, bot: bot)
}
//MARK: - Subteams
func subteam(_ event: Event) {
guard let subteam = event.subteam, let id = subteam.id else {
func subteam(event: Event) {
guard let subteam = event.subteam, id = subteam.id else {
return
}
userGroups[id] = subteam
subteamEventsDelegate?.event(subteam, client: self)
subteamEventsDelegate?.subteamEvent(self, userGroup: subteam)
}
func subteamAddedSelf(_ event: Event) {
guard let subteamID = event.subteamID, let _ = authenticatedUser?.userGroups else {
func subteamAddedSelf(event: Event) {
guard let subteamID = event.subteamID, _ = authenticatedUser?.userGroups else {
return
}
authenticatedUser?.userGroups![subteamID] = subteamID
subteamEventsDelegate?.selfAdded(subteamID, client: self)
subteamEventsDelegate?.subteamSelfAdded(self, subteamID: subteamID)
}
func subteamRemovedSelf(_ event: Event) {
func subteamRemovedSelf(event: Event) {
guard let subteamID = event.subteamID else {
return
}
_ = authenticatedUser?.userGroups?.removeValue(forKey: subteamID)
subteamEventsDelegate?.selfRemoved(subteamID, client: self)
authenticatedUser?.userGroups?.removeValueForKey(subteamID)
subteamEventsDelegate?.subteamSelfRemoved(self, subteamID: subteamID)
}
//MARK: - Team Profiles
func teamProfileChange(_ event: Event) {
func teamProfileChange(event: Event) {
guard let profile = event.profile else {
return
}
@@ -519,10 +519,10 @@ internal extension Client {
}
}
teamProfileEventsDelegate?.changed(profile, client: self)
teamProfileEventsDelegate?.teamProfileChanged(self, profile: profile)
}
func teamProfileDeleted(_ event: Event) {
func teamProfileDeleted(event: Event) {
guard let profile = event.profile else {
return
}
@@ -533,10 +533,10 @@ internal extension Client {
}
}
teamProfileEventsDelegate?.deleted(profile, client: self)
teamProfileEventsDelegate?.teamProfileDeleted(self, profile: profile)
}
func teamProfileReordered(_ event: Event) {
func teamProfileReordered(event: Event) {
guard let profile = event.profile else {
return
}
@@ -547,16 +547,17 @@ internal extension Client {
}
}
teamProfileEventsDelegate?.reordered(profile, client: self)
teamProfileEventsDelegate?.teamProfileReordered(self, profile: profile)
}
//MARK: - Authenticated User
func manualPresenceChange(_ event: Event) {
guard let presence = event.presence, let user = authenticatedUser else {
func manualPresenceChange(event: Event) {
guard let presence = event.presence, user = authenticatedUser else {
return
}
authenticatedUser?.presence = presence
slackEventsDelegate?.manualPresenceChanged(user, presence: presence, client: self)
slackEventsDelegate?.manualPresenceChanged(self, user: user, presence: presence)
}
}
+13 -13
View File
@@ -21,43 +21,43 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
public enum ClientError: Error {
case channelDoesNotExist
case userDoesNotExist
public enum ClientError: ErrorType {
case ChannelDoesNotExist
case UserDoesNotExist
}
public extension Client {
//MARK: - User & Channel
public func getChannelIDWith(name: String) throws -> String {
guard let id = channels.filter({$0.1.name == strip(string:name)}).first?.0 else {
throw ClientError.channelDoesNotExist
public func getChannelIDByName(name: String) throws -> String {
guard let id = channels.filter({$0.1.name == stripString(name)}).first?.0 else {
throw ClientError.ChannelDoesNotExist
}
return id
}
public func getUserIDWith(name: String) throws -> String {
guard let id = users.filter({$0.1.name == strip(string:name)}).first?.0 else {
throw ClientError.userDoesNotExist
public func getUserIDByName(name: String) throws -> String {
guard let id = users.filter({$0.1.name == stripString(name)}).first?.0 else {
throw ClientError.UserDoesNotExist
}
return id
}
public func getImIDForUserWith(id: String, success: @escaping (_ imID: String?)->Void, failure: @escaping (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 {
success(channel.0)
success(imID: channel.0)
} else {
webAPI.openIM(id, success: success, failure: failure)
}
}
//MARK: - Utilities
internal func strip(string: String) -> String {
internal func stripString(string: String) -> String {
var strippedString = string
if string[string.startIndex] == "@" || string[string.startIndex] == "#" {
strippedString = string.substring(from: string.characters.index(string.startIndex, offsetBy: 1))
strippedString = string.substringFromIndex(string.startIndex.advancedBy(1))
}
return strippedString
}
+65 -63
View File
@@ -44,7 +44,7 @@ public final class Client: WebSocketDelegate {
}
internal var webSocket: WebSocket?
fileprivate let pingPongQueue = DispatchQueue(label: "com.launchsoft.SlackKit")
private let pingPongQueue = dispatch_queue_create("com.launchsoft.SlackKit", DISPATCH_QUEUE_SERIAL)
internal var ping: Double?
internal var pong: Double?
internal var options: ClientOptions?
@@ -69,23 +69,24 @@ 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: ClientOptions = ClientOptions()) {
public func connect(options options: ClientOptions = ClientOptions()) {
self.options = options
webAPI.rtmStart(options.simpleLatest, noUnreads: options.noUnreads, mpimAware: options.mpimAware, success: {(response) in
guard let socketURL = response["url"] as? String, let url = URL(string: socketURL) else {
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 {
return
}
self.initialSetup(JSON: response)
self.initialSetup(response)
self.webSocket = WebSocket(url: url)
self.webSocket?.delegate = self
self.webSocket?.connect()
}, failure: {(error) in
self.connectionEventsDelegate?.connectionFailed(self, error: error)
})
}, failure: {(error) -> Void in
self.connectionEventsDelegate?.clientConnectionFailed(self, error: error)
})
}
public func disconnect() {
@@ -93,69 +94,71 @@ public final class Client: WebSocketDelegate {
}
//MARK: - RTM Message send
public func send(message: String, channelID: String) {
public func sendMessage(message: String, channelID: String) {
guard connected else { return }
if let data = try? format(message: message, channel: channelID), let string = String(data: data, encoding: String.Encoding.utf8) {
webSocket?.write(string: string)
if let data = try? formatMessageToSlackJsonString(msg: message, channel: channelID),
string = NSString(data: data, encoding: NSUTF8StringEncoding) as? String {
webSocket?.writeString(string)
}
}
fileprivate func format(message: String, channel: String) throws -> Data {
let json: [String: Any] = [
"id": Date().slackTimestamp,
private func formatMessageToSlackJsonString(message: (msg: String, channel: String)) throws -> NSData {
let json: [String: AnyObject] = [
"id": NSDate().slackTimestamp(),
"type": "message",
"channel": channel,
"text": message.slackFormatEscaping
"channel": message.channel,
"text": message.msg.slackFormatEscaping()
]
addSentMessage(json)
return try JSONSerialization.data(withJSONObject: json, options: [])
return try NSJSONSerialization.dataWithJSONObject(json, options: [])
}
fileprivate func addSentMessage(_ dictionary: [String: Any]) {
private func addSentMessage(dictionary: [String: AnyObject]) {
var message = dictionary
guard let id = message["id"] as? NSNumber else {
return
}
let ts = String(describing: id)
message.removeValue(forKey: "id")
let ts = String(id)
message.removeValueForKey("id")
message["ts"] = ts
message["user"] = self.authenticatedUser?.id
sentMessages[ts] = Message(dictionary: message)
sentMessages[ts] = Message(message: message)
}
//MARK: - RTM Ping
fileprivate func pingRTMServerAt(interval: TimeInterval) {
let delay = DispatchTime.now() + Double(Int64(interval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)
pingPongQueue.asyncAfter(deadline: delay, execute: {
private func pingRTMServerAtInterval(interval: NSTimeInterval) {
let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(interval * Double(NSEC_PER_SEC)))
dispatch_after(delay, pingPongQueue, {
guard self.connected && self.timeoutCheck() else {
self.disconnect()
return
}
self.sendRTMPing()
self.pingRTMServerAt(interval: interval)
self.pingRTMServerAtInterval(interval)
})
}
fileprivate func sendRTMPing() {
private func sendRTMPing() {
guard connected else {
return
}
let json: [String: Any] = [
"id": Date().slackTimestamp,
"type": "ping"
let json: [String: AnyObject] = [
"id": NSDate().slackTimestamp(),
"type": "ping",
]
guard let data = try? JSONSerialization.data(withJSONObject: json, options: []) else {
guard let data = try? NSJSONSerialization.dataWithJSONObject(json, options: []) else {
return
}
if let string = String(data: data, encoding: String.Encoding.utf8) {
let string = NSString(data: data, encoding: NSUTF8StringEncoding)
if let writePing = string as? String {
ping = json["id"] as? Double
webSocket?.write(string: string)
webSocket?.writeString(writePing)
}
}
fileprivate func timeoutCheck() -> Bool {
if let pong = pong, let ping = ping, let timeout = options?.timeout {
private func timeoutCheck() -> Bool {
if let pong = pong, ping = ping, timeout = options?.timeout {
if pong - ping < timeout {
return true
} else {
@@ -168,64 +171,62 @@ public final class Client: WebSocketDelegate {
}
//MARK: - Client setup
fileprivate func initialSetup(JSON: [String: Any]) {
team = Team(team: JSON["team"] as? [String: Any])
authenticatedUser = User(user: JSON["self"] as? [String: Any])
authenticatedUser?.doNotDisturbStatus = DoNotDisturbStatus(status: JSON["dnd"] as? [String: Any])
enumerateObjects(JSON["users"] as? Array) { (user) in self.addUser(user) }
enumerateObjects(JSON["channels"] as? Array) { (channel) in self.addChannel(channel) }
enumerateObjects(JSON["groups"] as? Array) { (group) in self.addChannel(group) }
enumerateObjects(JSON["mpims"] as? Array) { (mpim) in self.addChannel(mpim) }
enumerateObjects(JSON["ims"] as? Array) { (ims) in self.addChannel(ims) }
enumerateObjects(JSON["bots"] as? Array) { (bots) in self.addBot(bots) }
enumerateSubteams(JSON["subteams"] as? [String: Any])
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])
enumerateObjects(json["users"] as? Array) { (user) in self.addUser(user) }
enumerateObjects(json["channels"] as? Array) { (channel) in self.addChannel(channel) }
enumerateObjects(json["groups"] as? Array) { (group) in self.addChannel(group) }
enumerateObjects(json["mpims"] as? Array) { (mpim) in self.addChannel(mpim) }
enumerateObjects(json["ims"] as? Array) { (ims) in self.addChannel(ims) }
enumerateObjects(json["bots"] as? Array) { (bots) in self.addBot(bots) }
enumerateSubteams(json["subteams"] as? [String: AnyObject])
}
fileprivate func addUser(_ aUser: [String: Any]) {
private func addUser(aUser: [String: AnyObject]) {
let user = User(user: aUser)
if let id = user.id {
users[id] = user
}
}
fileprivate func addChannel(_ aChannel: [String: Any]) {
private func addChannel(aChannel: [String: AnyObject]) {
let channel = Channel(channel: aChannel)
if let id = channel.id {
channels[id] = channel
}
}
fileprivate func addBot(_ aBot: [String: Any]) {
private func addBot(aBot: [String: AnyObject]) {
let bot = Bot(bot: aBot)
if let id = bot.id {
bots[id] = bot
}
}
fileprivate func enumerateSubteams(_ subteams: [String: Any]?) {
private func enumerateSubteams(subteams: [String: AnyObject]?) {
if let subteams = subteams {
if let all = subteams["all"] as? [[String: Any]] {
if let all = subteams["all"] as? [[String: AnyObject]] {
for item in all {
let u = UserGroup(userGroup: item)
if let id = u.id {
self.userGroups[id] = u
}
self.userGroups[u.id!] = u
}
}
if let auth = subteams["self"] as? [String] {
for item in auth {
authenticatedUser?.userGroups = [String: String]()
authenticatedUser?.userGroups?[item] = item
authenticatedUser?.userGroups![item] = item
}
}
}
}
// MARK: - Utilities
fileprivate func enumerateObjects(_ array: [Any]?, initalizer: ([String: Any])-> Void) {
private func enumerateObjects(array: [AnyObject]?, initalizer: ([String: AnyObject])-> Void) {
if let array = array {
for object in array {
if let dictionary = object as? [String: Any] {
if let dictionary = object as? [String: AnyObject] {
initalizer(dictionary)
}
}
@@ -235,7 +236,7 @@ public final class Client: WebSocketDelegate {
// MARK: - WebSocketDelegate
public func websocketDidConnect(socket: WebSocket) {
if let pingInterval = options?.pingInterval {
pingRTMServerAt(interval: pingInterval)
pingRTMServerAtInterval(pingInterval)
}
}
@@ -243,21 +244,22 @@ public final class Client: WebSocketDelegate {
connected = false
webSocket = nil
authenticatedUser = nil
connectionEventsDelegate?.disconnected(self)
if let options = options, options.reconnect == true {
connectionEventsDelegate?.clientDisconnected(self)
if let options = options where options.reconnect == true {
connect(options: options)
}
}
public func websocketDidReceiveMessage(socket: WebSocket, text: String) {
guard let data = text.data(using: String.Encoding.utf8) else {
guard let data = text.dataUsingEncoding(NSUTF8StringEncoding) else {
return
}
if let json = (try? JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments)) as? [String: Any] {
if let json = (try? NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.AllowFragments)) as? [String: AnyObject] {
dispatch(json)
}
}
public func websocketDidReceiveData(socket: WebSocket, data: Data) {}
public func websocketDidReceiveData(socket: WebSocket, data: NSData) {}
}
+4 -3
View File
@@ -28,11 +28,11 @@ public struct ClientOptions {
let simpleLatest: Bool?
let noUnreads: Bool?
let mpimAware: Bool?
let pingInterval: TimeInterval?
let timeout: TimeInterval?
let pingInterval: NSTimeInterval?
let timeout: NSTimeInterval?
let reconnect: Bool?
public init(simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, pingInterval: TimeInterval? = nil, timeout: TimeInterval? = nil, reconnect: Bool? = nil) {
public init(simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, pingInterval: NSTimeInterval? = nil, timeout: NSTimeInterval? = nil, reconnect: Bool? = nil) {
self.simpleLatest = simpleLatest
self.noUnreads = noUnreads
self.mpimAware = mpimAware
@@ -40,4 +40,5 @@ public struct ClientOptions {
self.timeout = timeout
self.reconnect = reconnect
}
}
+8 -7
View File
@@ -21,8 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
public struct Comment: Equatable {
public struct Comment {
public let id: String?
public let user: String?
internal(set) public var created: Int?
@@ -31,7 +30,7 @@ public struct Comment: Equatable {
internal(set) public var stars: Int?
internal(set) public var reactions = [Reaction]()
internal init(comment:[String: Any]?) {
internal init(comment:[String: AnyObject]?) {
id = comment?["id"] as? String
created = comment?["created"] as? Int
user = comment?["user"] as? String
@@ -44,8 +43,10 @@ public struct Comment: Equatable {
self.id = id
self.user = nil
}
public static func ==(lhs: Comment, rhs: Comment) -> Bool {
return lhs.id == rhs.id
}
}
extension Comment: Equatable {}
public func ==(lhs: Comment, rhs: Comment) -> Bool {
return lhs.id == rhs.id
}
+6 -6
View File
@@ -22,14 +22,13 @@
// THE SOFTWARE.
public struct CustomProfile {
internal(set) public var fields = [String: CustomProfileField]()
internal init(profile: [String: Any]?) {
if let eventFields = profile?["fields"] as? [Any] {
internal init(profile: [String: AnyObject]?) {
if let eventFields = profile?["fields"] as? [AnyObject] {
for field in eventFields {
var cpf: CustomProfileField?
if let fieldDictionary = field as? [String: Any] {
if let fieldDictionary = field as? [String: AnyObject] {
cpf = CustomProfileField(field: fieldDictionary)
} else {
cpf = CustomProfileField(id: field as? String)
@@ -39,12 +38,13 @@ public struct CustomProfile {
}
}
internal init(customFields: [String: Any]?) {
internal init(customFields: [String: AnyObject]?) {
if let customFields = customFields {
for key in customFields.keys {
let cpf = CustomProfileField(field: customFields[key] as? [String: Any])
let cpf = CustomProfileField(field: customFields[key] as? [String: AnyObject])
self.fields[key] = cpf
}
}
}
}
+2 -3
View File
@@ -22,7 +22,6 @@
// THE SOFTWARE.
public struct CustomProfileField {
internal(set) public var id: String?
internal(set) public var alt: String?
internal(set) public var value: String?
@@ -34,7 +33,7 @@ public struct CustomProfileField {
internal(set) public var possibleValues: [String]?
internal(set) public var type: String?
internal init(field: [String: Any]?) {
internal init(field: [String: AnyObject]?) {
id = field?["id"] as? String
alt = field?["alt"] as? String
value = field?["value"] as? String
@@ -51,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
+2 -2
View File
@@ -22,18 +22,18 @@
// THE SOFTWARE.
public struct DoNotDisturbStatus {
internal(set) public var enabled: Bool?
internal(set) public var nextDoNotDisturbStart: Int?
internal(set) public var nextDoNotDisturbEnd: Int?
internal(set) public var snoozeEnabled: Bool?
internal(set) public var snoozeEndtime: Int?
internal init(status: [String: Any]?) {
internal init(status: [String: AnyObject]?) {
enabled = status?["dnd_enabled"] as? Bool
nextDoNotDisturbStart = status?["next_dnd_start_ts"] as? Int
nextDoNotDisturbEnd = status?["next_dnd_end_ts"] as? Int
snoozeEnabled = status?["snooze_enabled"] as? Bool
snoozeEndtime = status?["snooze_endtime"] as? Int
}
}
+1 -2
View File
@@ -22,11 +22,10 @@
// THE SOFTWARE.
public struct Edited {
public let user: String?
public let ts: String?
internal init(edited:[String: Any]?) {
internal init(edited:[String: AnyObject]?) {
user = edited?["user"] as? String
ts = edited?["ts"] as? String
}
+17 -17
View File
@@ -22,7 +22,6 @@
// THE SOFTWARE.
internal enum EventType: String {
case Hello = "hello"
case Message = "message"
case UserTyping = "user_typing"
@@ -97,7 +96,6 @@ internal enum EventType: String {
}
internal enum MessageSubtype: String {
case BotMessage = "bot_message"
case MeMessage = "me_message"
case MessageChanged = "message_changed"
@@ -139,14 +137,14 @@ internal struct Event {
let fileID: String?
let presence: String?
let name: String?
let value: Any?
let value: AnyObject?
let plan: String?
let url: String?
let domain: String?
let emailDomain: String?
let reaction: String?
let replyTo: Double?
let reactions: [[String: Any]]?
let reactions: [[String: AnyObject]]?
let edited: Edited?
let bot: Bot?
let channel: Channel?
@@ -162,7 +160,7 @@ internal struct Event {
let subteamID: String?
var profile: CustomProfile?
init(event:[String: Any]) {
init(event:[String: AnyObject]) {
type = EventType(rawValue: event["type"] as? String ?? "ok")
ts = event["ts"] as? String
subtype = event["subtype"] as? String
@@ -184,36 +182,38 @@ internal struct Event {
emailDomain = event["email_domain"] as? String
reaction = event["reaction"] as? String
replyTo = event["reply_to"] as? Double
reactions = event["reactions"] as? [[String: Any]]
bot = Bot(bot: event["bot"] as? [String: Any])
edited = Edited(edited:event["edited"] as? [String: Any])
dndStatus = DoNotDisturbStatus(status: event["dnd_status"] as? [String: Any])
reactions = event["reactions"] as? [[String: AnyObject]]
bot = Bot(bot: event["bot"] as? [String: AnyObject])
edited = Edited(edited:event["edited"] as? [String: AnyObject])
dndStatus = DoNotDisturbStatus(status: event["dnd_status"] as? [String: AnyObject])
itemUser = event["item_user"] as? String
item = Item(item: event["item"] as? [String: Any])
subteam = UserGroup(userGroup: event["subteam"] as? [String: Any])
item = Item(item: event["item"] as? [String: AnyObject])
subteam = UserGroup(userGroup: event["subteam"] as? [String: AnyObject])
subteamID = event["subteam_id"] as? String
message = Message(dictionary: event)
nestedMessage = Message(dictionary: event["message"] as? [String: Any])
profile = CustomProfile(profile: event["profile"] as? [String: Any])
message = Message(message: event)
nestedMessage = Message(message: event["message"] as? [String: AnyObject])
profile = CustomProfile(profile: event["profile"] as? [String: AnyObject])
file = File(id: event["file"] as? String)
// Comment, Channel, and User can come across as Strings or Dictionaries
if let commentDictionary = event["comment"] as? [String: Any] {
if let commentDictionary = event["comment"] as? [String: AnyObject] {
comment = Comment(comment: commentDictionary)
} else {
comment = Comment(id: event["comment"] as? String)
}
if let userDictionary = event["user"] as? [String: Any] {
if let userDictionary = event["user"] as? [String: AnyObject] {
user = User(user: userDictionary)
} else {
user = User(id: event["user"] as? String)
}
if let channelDictionary = event["channel"] as? [String: Any] {
if let channelDictionary = event["channel"] as? [String: AnyObject] {
channel = Channel(channel: channelDictionary)
} else {
channel = Channel(id: event["channel"] as? String)
}
}
}
+48 -48
View File
@@ -22,88 +22,88 @@
// THE SOFTWARE.
public protocol ConnectionEventsDelegate: class {
func connected(_ client: Client)
func disconnected(_ client: Client)
func connectionFailed(_ client: Client, error: SlackError)
func clientConnected(client: Client)
func clientDisconnected(client: Client)
func clientConnectionFailed(client: Client, error: SlackError)
}
public protocol MessageEventsDelegate: class {
func sent(_ message: Message, client: Client)
func received(_ message: Message, client: Client)
func changed(_ message: Message, client: Client)
func deleted(_ message: Message?, client: Client)
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 userTypingIn(_ channel: Channel, user: User, client: Client)
func marked(_ channel: Channel, timestamp: String, client: Client)
func created(_ channel: Channel, client: Client)
func deleted(_ channel: Channel, client: Client)
func renamed(_ channel: Channel, client: Client)
func archived(_ channel: Channel, client: Client)
func historyChanged(_ channel: Channel, client: Client)
func joined(_ channel: Channel, client: Client)
func left(_ channel: Channel, client: Client)
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 updated(_ status: DoNotDisturbStatus, client: Client)
func userUpdated(_ status: DoNotDisturbStatus, user: User, client: Client)
func doNotDisturbUpdated(client: Client, dndStatus: DoNotDisturbStatus)
func doNotDisturbUserUpdated(client: Client, dndStatus: DoNotDisturbStatus, user: User)
}
public protocol GroupEventsDelegate: class {
func opened(_ group: Channel, client: Client)
func groupOpened(client: Client, group: Channel)
}
public protocol FileEventsDelegate: class {
func processed(_ file: File, client: Client)
func madePrivate(_ file: File, client: Client)
func deleted(_ file: File, client: Client)
func commentAdded(_ file: File, comment: Comment, client: Client)
func commentEdited(_ file: File, comment: Comment, client: Client)
func commentDeleted(_ file: File, comment: Comment, client: Client)
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 pinned(_ item: Item, channel: Channel?, client: Client)
func unpinned(_ item: Item, channel: Channel?, client: Client)
func itemPinned(client: Client, item: Item, channel: Channel?)
func itemUnpinned(client: Client, item: Item, channel: Channel?)
}
public protocol StarEventsDelegate: class {
func starred(_ item: Item, starred: Bool, _ client: Client)
func itemStarred(client: Client, item: Item, star: Bool)
}
public protocol ReactionEventsDelegate: class {
func added(_ reaction: String, item: Item, itemUser: String, client: Client)
func removed(_ reaction: String, item: Item, itemUser: String, client: Client)
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(_ preference: String, value: Any?, client: Client)
func userChanged(_ user: User, client: Client)
func presenceChanged(_ user: User, presence: String, client: Client)
func manualPresenceChanged(_ user: User, presence: String, client: Client)
func botEvent(_ bot: Bot, client: Client)
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 userJoined(_ user: User, client: Client)
func planChanged(_ plan: String, client: Client)
func preferencesChanged(_ preference: String, value: Any?, client: Client)
func nameChanged(_ name: String, client: Client)
func domainChanged(_ domain: String, client: Client)
func emailDomainChanged(_ domain: String, client: Client)
func emojiChanged(_ 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 event(_ userGroup: UserGroup, client: Client)
func selfAdded(_ subteamID: String, client: Client)
func selfRemoved(_ subteamID: String, client: Client)
func subteamEvent(client: Client, userGroup: UserGroup)
func subteamSelfAdded(client: Client, subteamID: String)
func subteamSelfRemoved(client: Client, subteamID: String)
}
public protocol TeamProfileEventsDelegate: class {
func changed(_ profile: CustomProfile, client: Client)
func deleted(_ profile: CustomProfile, client: Client)
func reordered(_ profile: CustomProfile, client: Client)
func teamProfileChanged(client: Client, profile: CustomProfile)
func teamProfileDeleted(client: Client, profile: CustomProfile)
func teamProfileReordered(client: Client, profile: CustomProfile)
}
+12 -9
View File
@@ -23,29 +23,31 @@
import Foundation
public extension Date {
public extension NSDate {
var slackTimestamp: Double {
return NSNumber(value: timeIntervalSince1970).doubleValue
func slackTimestamp() -> Double {
return NSNumber(double: timeIntervalSince1970).doubleValue
}
}
internal extension String {
var slackFormatEscaping: String {
var escapedString = replacingOccurrences(of: "&", with: "&amp;")
escapedString = replacingOccurrences(of: "<", with: "&lt;")
escapedString = replacingOccurrences(of: ">", with: "&gt;")
func slackFormatEscaping() -> String {
var escapedString = stringByReplacingOccurrencesOfString("&", withString: "&amp;")
escapedString = stringByReplacingOccurrencesOfString("<", withString: "&lt;")
escapedString = stringByReplacingOccurrencesOfString(">", withString: "&gt;")
return escapedString
}
}
internal extension Dictionary where Key: ExpressibleByStringLiteral, Value: Any {
internal extension Dictionary where Key: StringLiteralConvertible, Value: AnyObject {
var requestStringFromParameters: String {
var requestString = ""
for key in self.keys {
if let value = self[key] as? String, let encodedValue = value.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlHostAllowed) {
if let value = self[key] as? String, encodedValue = value.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLHostAllowedCharacterSet()) {
requestString += "&\(key)=\(encodedValue)"
} else if let value = self[key] as? Int {
requestString += "&\(key)=\(value)"
@@ -54,5 +56,6 @@ internal extension Dictionary where Key: ExpressibleByStringLiteral, Value: Any
return requestString
}
}
+11 -8
View File
@@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
public struct File: Equatable {
public struct File {
public let id: String?
public let created: Int?
@@ -78,7 +78,7 @@ public struct File: Equatable {
internal(set) public var comments = [String: Comment]()
internal(set) public var reactions = [Reaction]()
public init(file:[String: Any]?) {
public init(file:[String: AnyObject]?) {
id = file?["id"] as? String
created = file?["created"] as? Int
name = file?["name"] as? String
@@ -127,11 +127,11 @@ public struct File: Equatable {
channels = file?["channels"] as? [String]
groups = file?["groups"] as? [String]
ims = file?["ims"] as? [String]
initialComment = Comment(comment: file?["initial_comment"] as? [String: Any])
initialComment = Comment(comment: file?["initial_comment"] as? [String: AnyObject])
stars = file?["num_stars"] as? Int
isStarred = file?["is_starred"] as? Bool
pinnedTo = file?["pinned_to"] as? [String]
reactions = Reaction.reactionsFromArray(file?["reactions"] as? [[String: Any]])
reactions = Reaction.reactionsFromArray(file?["reactions"] as? [[String: AnyObject]])
}
internal init(id:String?) {
@@ -179,8 +179,11 @@ public struct File: Equatable {
linesMore = nil
initialComment = nil
}
public static func ==(lhs: File, rhs: File) -> Bool {
return lhs.id == rhs.id
}
}
extension File: Equatable {}
public func ==(lhs: File, rhs: File) -> Bool {
return lhs.id == rhs.id
}
+6 -6
View File
@@ -25,17 +25,17 @@ import Foundation
public struct History {
internal(set) public var latest: Date?
internal(set) public var latest: NSDate?
internal(set) public var messages = [Message]()
public let hasMore: Bool?
internal init(history: [String: Any]?) {
if let latestStr = history?["latest"] as? String, let latestDouble = Double(latestStr) {
latest = Date(timeIntervalSince1970: TimeInterval(latestDouble))
internal init(history: [String: AnyObject]?) {
if let latestStr = history?["latest"] as? String, latestDouble = Double(latestStr) {
latest = NSDate(timeIntervalSince1970: NSTimeInterval(latestDouble))
}
if let msgs = history?["messages"] as? [[String: Any]] {
if let msgs = history?["messages"] as? [[String: AnyObject]] {
for message in msgs {
messages.append(Message(dictionary: message))
messages.append(Message(message: message))
}
}
hasMore = history?["has_more"] as? Bool
+5 -4
View File
@@ -32,7 +32,7 @@ public struct IncomingWebhook {
public let iconEmoji: String?
public let iconURL: String?
internal init(webhook: [String: Any]?) {
internal init(webhook: [String: AnyObject]?) {
url = webhook?["url"] as? String
channel = webhook?["channel"] as? String
configurationURL = webhook?["configuration_url"] as? String
@@ -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, let data = try? JSONSerialization.data(withJSONObject: jsonBody(response.json), options: []) {
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: []) {
NetworkInterface().customRequest(url, data: data, success: { _ in
success?(true)
}, errorClosure: {(error) in
@@ -60,7 +60,7 @@ public struct IncomingWebhook {
}
}
fileprivate func jsonBody(_ response: [String: Any]) -> [String: Any] {
private func jsonBody(response: [String: AnyObject]) -> [String: AnyObject] {
var json = response
json["channel"] = channel
json["username"] = username
@@ -68,4 +68,5 @@ public struct IncomingWebhook {
json["icon_url"] = iconURL
return json
}
}
+12 -10
View File
@@ -21,8 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
public struct Item: Equatable {
public struct Item {
public let type: String?
public let ts: String?
public let channel: String?
@@ -31,20 +30,21 @@ public struct Item: Equatable {
public let comment: Comment?
public let fileCommentID: String?
internal init(item:[String: Any]?) {
internal init(item:[String: AnyObject]?) {
type = item?["type"] as? String
ts = item?["ts"] as? String
channel = item?["channel"] as? String
message = Message(dictionary: item?["message"] as? [String: Any])
message = Message(message: item?["message"] as? [String: AnyObject])
// Comment and File can come across as Strings or Dictionaries
if let commentDictionary = item?["comment"] as? [String: Any] {
if let commentDictionary = item?["comment"] as? [String: AnyObject] {
comment = Comment(comment: commentDictionary)
} else {
comment = Comment(id: item?["comment"] as? String)
}
if let fileDictionary = item?["file"] as? [String: Any] {
if let fileDictionary = item?["file"] as? [String: AnyObject] {
file = File(file: fileDictionary)
} else {
file = File(id: item?["file"] as? String)
@@ -52,8 +52,10 @@ public struct Item: Equatable {
fileCommentID = item?["file_comment"] as? String
}
public static func ==(lhs: Item, rhs: Item) -> Bool {
return lhs.type == rhs.type && lhs.channel == rhs.channel && lhs.file == rhs.file && lhs.comment == rhs.comment && lhs.message == rhs.message
}
}
extension Item: Equatable {}
public func ==(lhs: Item, rhs: Item) -> Bool {
return lhs.type == rhs.type && lhs.channel == rhs.channel && lhs.file == rhs.file && lhs.comment == rhs.comment && lhs.message == rhs.message
}
+36 -33
View File
@@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
public final class Message: Equatable {
public final class Message {
public let type = "message"
public let subtype: String?
@@ -32,7 +32,7 @@ public final class Message: Equatable {
internal(set) public var text: String?
public let botID: String?
public let username: String?
public let icons: [String: Any]?
public let icons: [String: AnyObject]?
public let deletedTs: String?
internal(set) var purpose: String?
internal(set) var topic: String?
@@ -51,33 +51,33 @@ public final class Message: Equatable {
internal(set) public var replaceOriginal: Bool?
internal(set) public var deleteOriginal: Bool?
public init(dictionary: [String: Any]?) {
subtype = dictionary?["subtype"] as? String
ts = dictionary?["ts"] as? String
user = dictionary?["user"] as? String
channel = dictionary?["channel"] as? String
hidden = dictionary?["hidden"] as? Bool
text = dictionary?["text"] as? String
botID = dictionary?["bot_id"] as? String
username = dictionary?["username"] as? String
icons = dictionary?["icons"] as? [String: Any]
deletedTs = dictionary?["deleted_ts"] as? String
purpose = dictionary?["purpose"] as? String
topic = dictionary?["topic"] as? String
name = dictionary?["name"] as? String
members = dictionary?["members"] as? [String]
oldName = dictionary?["old_name"] as? String
upload = dictionary?["upload"] as? Bool
itemType = dictionary?["item_type"] as? String
isStarred = dictionary?["is_starred"] as? Bool
pinnedTo = dictionary?["pinned_to"] as? [String]
comment = Comment(comment: dictionary?["comment"] as? [String: Any])
file = File(file: dictionary?["file"] as? [String: Any])
reactions = Reaction.reactionsFromArray(dictionary?["reactions"] as? [[String: Any]])
attachments = (dictionary?["attachments"] as? [[String: Any]])?.map{Attachment(attachment: $0)}
responseType = ResponseType(rawValue: dictionary?["response_type"] as? String ?? "")
replaceOriginal = dictionary?["replace_original"] as? Bool
deleteOriginal = dictionary?["delete_original"] as? Bool
public init(message: [String: AnyObject]?) {
subtype = message?["subtype"] as? String
ts = message?["ts"] as? String
user = message?["user"] as? String
channel = message?["channel"] as? String
hidden = message?["hidden"] as? Bool
text = message?["text"] as? String
botID = message?["bot_id"] as? String
username = message?["username"] as? String
icons = message?["icons"] as? [String: AnyObject]
deletedTs = message?["deleted_ts"] as? String
purpose = message?["purpose"] as? String
topic = message?["topic"] as? String
name = message?["name"] as? String
members = message?["members"] as? [String]
oldName = message?["old_name"] as? String
upload = message?["upload"] as? Bool
itemType = message?["item_type"] as? String
isStarred = message?["is_starred"] as? Bool
pinnedTo = message?["pinned_to"] as? [String]
comment = Comment(comment: message?["comment"] as? [String: AnyObject])
file = File(file: message?["file"] as? [String: AnyObject])
reactions = Reaction.reactionsFromArray(message?["reactions"] as? [[String: AnyObject]])
attachments = (message?["attachments"] as? [[String: AnyObject]])?.map{Attachment(attachment: $0)}
responseType = ResponseType(rawValue: message?["response_type"] as? String ?? "")
replaceOriginal = message?["replace_original"] as? Bool
deleteOriginal = message?["delete_original"] as? Bool
}
internal init(ts:String?) {
@@ -94,8 +94,11 @@ public final class Message: Equatable {
comment = nil
file = nil
}
public static func ==(lhs: Message, rhs: Message) -> Bool {
return lhs.ts == rhs.ts && lhs.user == rhs.user && lhs.text == rhs.text
}
}
extension Message: Equatable {}
public func ==(lhs: Message, rhs: Message) -> Bool {
return lhs.ts == rhs.ts && lhs.user == rhs.user && lhs.text == rhs.text
}
+7 -6
View File
@@ -35,17 +35,18 @@ internal struct MessageActionRequest: Request {
let originalMessage: Message?
let responseURL: String
init(response: [String: Any]?) {
action = (response?["actions"] as? [[String:Any]])?.map({Action(action: $0)}).first
init(response: [String: AnyObject]?) {
action = (response?["actions"] as? [[String:AnyObject]])?.map({Action(action: $0)}).first
callbackID = response?["callback_id"] as? String
team = Team(team: response?["team"] as? [String: Any])
channel = Channel(channel: response?["channel"] as? [String: Any])
user = User(user: response?["channel"] as? [String: Any])
team = Team(team: response?["team"] as? [String: AnyObject])
channel = Channel(channel: response?["channel"] as? [String: AnyObject])
user = User(user: response?["channel"] as? [String: AnyObject])
actionTS = response?["action_ts"] as? String
messageTS = response?["message_ts"] as? String
attachmentID = response?["attachment_id"] as? String
token = response?["token"] as? String
originalMessage = Message(dictionary: response?["original_message"] as? [String: Any])
originalMessage = Message(message: response?["original_message"] as? [String: AnyObject])
responseURL = response?["response_url"] as? String ?? ""
}
}
@@ -29,11 +29,12 @@ 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
}
}
}
+6 -5
View File
@@ -21,7 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
open class MessageActionServer: Server {
public class MessageActionServer: Server {
internal let responder: MessageActionResponder
@@ -31,15 +31,16 @@ open 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), actionRequest.token == self.token {
if let reply = self.responder.responseForRequest(actionRequest) where actionRequest.token == self.token {
return self.request(actionRequest, reply: reply)
} else {
return .badRequest(.text("Bad request."))
return .BadRequest(.Text("Bad request."))
}
}
}
}
}
+28 -28
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: Any]?, successClosure: @escaping ([String: Any])->Void, errorClosure: @escaping (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,13 +35,12 @@ internal struct NetworkInterface {
if let params = parameters {
requestString += params.requestStringFromParameters
}
guard let url = URL(string: requestString) else {
guard let url = NSURL(string: requestString) else {
errorClosure(SlackError.ClientNetworkError)
return
}
let request = URLRequest(url:url)
URLSession.shared.dataTask(with: request) {
let request = NSURLRequest(URL:url)
NSURLSession.sharedSession().dataTaskWithRequest(request) {
(data, response, internalError) -> Void in
self.handleResponse(data, response: response, internalError: internalError, successClosure: {(json) in
successClosure(json)
@@ -51,38 +50,38 @@ internal struct NetworkInterface {
}.resume()
}
internal func customRequest(_ url: String, data: Data, success: @escaping (Bool)->Void, errorClosure: @escaping (SlackError)->Void) {
guard let url = URL(string: url.removePercentEncoding()) else {
internal func customRequest(url: String, data: NSData, success: (Bool)->Void, errorClosure: (SlackError)->Void) {
guard let requestString = url.stringByRemovingPercentEncoding, url = NSURL(string: requestString) else {
errorClosure(SlackError.ClientNetworkError)
return
}
var request = URLRequest(url:url)
request.httpMethod = "POST"
let request = NSMutableURLRequest(URL:url)
request.HTTPMethod = "POST"
let contentType = "application/json"
request.setValue(contentType, forHTTPHeaderField: "Content-Type")
request.httpBody = data
request.HTTPBody = data
URLSession.shared.dataTask(with: request) {
NSURLSession.sharedSession().dataTaskWithRequest(request) {
(data, response, internalError) -> Void in
if internalError == nil {
success(true)
} else {
errorClosure(SlackError.ClientNetworkError)
}
}.resume()
}.resume()
}
internal func uploadRequest(_ token: String, data: Data, parameters: [String: Any]?, successClosure: @escaping ([String: Any])->Void, errorClosure: @escaping (SlackError)->Void) {
internal func uploadRequest(token: String, data: NSData, 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 = URL(string: requestString) else {
guard let url = NSURL(string: requestString) else {
errorClosure(SlackError.ClientNetworkError)
return
}
var request = URLRequest(url:url)
request.httpMethod = "POST"
let request = NSMutableURLRequest(URL:url)
request.HTTPMethod = "POST"
let boundaryConstant = randomBoundary()
let contentType = "multipart/form-data; boundary=" + boundaryConstant
let boundaryStart = "--\(boundaryConstant)\r\n"
@@ -90,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"
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)!)
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)!)
request.setValue(contentType, forHTTPHeaderField: "Content-Type")
request.httpBody = requestBodyData as Data
request.HTTPBody = requestBodyData
URLSession.shared.dataTask(with: request) {
NSURLSession.sharedSession().dataTaskWithRequest(request) {
(data, response, internalError) -> Void in
self.handleResponse(data, response: response, internalError: internalError, successClosure: {(json) in
successClosure(json)
@@ -111,13 +110,13 @@ internal struct NetworkInterface {
}.resume()
}
private func handleResponse(_ data: Data?, response:URLResponse?, internalError:Error?, successClosure: ([String: Any])->Void, errorClosure: (SlackError)->Void) {
guard let data = data, let response = response as? HTTPURLResponse else {
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 {
errorClosure(SlackError.ClientNetworkError)
return
}
do {
guard let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
guard let json = try NSJSONSerialization.JSONObjectWithData(data, options: []) as? [String: AnyObject] else {
errorClosure(SlackError.ClientJSONError)
return
}
@@ -150,4 +149,5 @@ internal struct NetworkInterface {
private func randomBoundary() -> String {
return String(format: "slackkit.boundary.%08x%08x", arc4random(), arc4random())
}
}
+4 -4
View File
@@ -31,14 +31,14 @@ internal struct OAuthResponse {
let incomingWebhook: IncomingWebhook?
let bot: Bot?
init(response: [String: Any]?) {
init(response: [String: AnyObject]?) {
accessToken = response?["access_token"] as? String
scope = (response?["scope"] as? String)?.components(separatedBy: ",").flatMap{Scope(rawValue:$0)}
scope = (response?["scope"] as? String)?.componentsSeparatedByString(",").flatMap{Scope(rawValue:$0)}
userID = response?["user_id"] as? String
teamName = response?["team_name"] as? String
teamID = response?["team_id"] as? String
incomingWebhook = IncomingWebhook(webhook: response?["incoming_webhook"] as? [String: Any])
bot = Bot(botUser: response?["bot"] as? [String: Any])
incomingWebhook = IncomingWebhook(webhook: response?["incoming_webhook"] as? [String: AnyObject])
bot = Bot(botUser: response?["bot"] as? [String: AnyObject])
}
}
+28 -23
View File
@@ -25,19 +25,19 @@ import Foundation
import Swifter
internal protocol OAuthDelegate {
func userAuthed(_ response: OAuthResponse)
mutating func userAuthed(response: OAuthResponse)
}
public struct OAuthServer {
fileprivate let oauthURL = "https://slack.com/oauth/authorize"
private let oauthURL = "https://slack.com/oauth/authorize"
fileprivate let http = HttpServer()
fileprivate let clientID: String
fileprivate let clientSecret: String
fileprivate let state: String?
fileprivate let redirectURI: String?
fileprivate var delegate: OAuthDelegate?
private let http = HttpServer()
private let clientID: String
private let clientSecret: String
private let state: String?
private let redirectURI: String?
private var delegate: OAuthDelegate?
internal init(clientID: String, clientSecret: String, state: String? = nil, redirectURI: String? = nil, port:in_port_t = 8080, forceIPV4: Bool = false, delegate: OAuthDelegate? = nil) throws {
self.clientID = clientID
@@ -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,34 +61,39 @@ public struct OAuthServer {
http.stop()
}
fileprivate func oauthRoute() {
private mutating func oauthRoute() {
http["/oauth"] = { request in
guard let response = AuthorizeResponse(queryParameters: request.queryParams), response.state == self.state else {
return .badRequest(.text("Bad request."))
guard let response = AuthorizeResponse(queryParameters: request.queryParams) where response.state == self.state else {
return .BadRequest(.Text("Bad request."))
}
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")
})
self.oauthRequest(response)
if let redirect = self.redirectURI {
return .movedPermanently(redirect)
return .MovedPermanently(redirect)
}
return .ok(.text("Authentication successful."))
return .OK(.Text("Authentication successful."))
}
}
fileprivate func oauthURLRequest(_ authorize: AuthorizeRequest) -> URLRequest? {
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? {
var requestString = "\(oauthURL)?client_id=\(authorize.clientID)"
requestString += authorize.parameters.requestStringFromParameters
guard let url = URL(string: requestString) else {
guard let url = NSURL(string: requestString) else {
return nil
}
return URLRequest(url:url)
return NSURLRequest(URL:url)
}
public func authorizeRequest(_ scope:[Scope], redirectURI: String, state: String = "slackkit", team: String? = nil) -> URLRequest? {
public func authorizeRequest(scope:[Scope], redirectURI: String, state: String = "slackkit", team: String? = nil) -> NSURLRequest? {
let request = AuthorizeRequest(clientID: clientID, scope: scope, redirectURI: redirectURI, state: state, team: team)
return oauthURLRequest(request)
}
}
+10 -8
View File
@@ -21,12 +21,11 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
public struct Reaction: Equatable {
public struct Reaction {
public let name: String?
internal(set) public var user: String?
internal init(reaction:[String: Any]?) {
internal init(reaction:[String: AnyObject]?) {
name = reaction?["name"] as? String
}
@@ -35,11 +34,11 @@ public struct Reaction: Equatable {
self.user = user
}
static func reactionsFromArray(_ array: [[String: Any]]?) -> [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], let name = reaction["name"] as? String {
if let users = reaction["users"] as? [String], name = reaction["name"] as? String {
for user in users {
reactions.append(Reaction(name: name, user: user))
}
@@ -49,7 +48,10 @@ public struct Reaction: Equatable {
return reactions
}
public static func ==(lhs: Reaction, rhs: Reaction) -> Bool {
return lhs.name == rhs.name
}
}
extension Reaction: Equatable {}
public func ==(lhs: Reaction, rhs: Reaction) -> Bool {
return lhs.name == rhs.name
}
+4 -3
View File
@@ -33,11 +33,12 @@ public struct Response {
self.attachments = attachments
}
internal var json: [String: Any] {
var json = [String : Any]()
internal func json() -> [String: AnyObject] {
var json = [String : AnyObject]()
json["text"] = text
json["response_type"] = responseType?.rawValue
json["attachments"] = attachments?.map({$0.dictionary})
json["attachments"] = attachments?.map({$0.dictionary()})
return json
}
}
+24 -23
View File
@@ -25,16 +25,16 @@ 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 {
var responseURL: String { get }
}
open class Server {
public class Server {
internal let http = HttpServer()
internal let token: String
@@ -43,7 +43,7 @@ open class Server {
self.token = token
}
open 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 {
@@ -51,29 +51,29 @@ open class Server {
}
}
open func stop() {
public func stop() {
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 as AnyObject))
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: Any]? {
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: Any] = [:]
internal func dictionaryFromRequest(body: [UInt8]) -> [String: AnyObject]? {
let string = NSString(data: NSData(bytes: body, length: body.count), encoding: NSUTF8StringEncoding)
if let body = string?.componentsSeparatedByString("&") {
var dict: [String: AnyObject] = [:]
for argument in body {
let kv = argument.components(separatedBy: "=")
if let key = kv.first, let value = kv.last {
dict[key] = value as Any?
let kv = argument.componentsSeparatedByString("=")
if let key = kv.first, value = kv.last {
dict[key] = value
}
}
return dict
@@ -81,10 +81,11 @@ open class Server {
return nil
}
internal func jsonFromRequest(_ string: String) -> [String: Any]? {
guard let data = string.data(using: String.Encoding.utf8) else {
internal func jsonFromRequest(string: String) -> [String: AnyObject]? {
guard let data = string.dataUsingEncoding(NSUTF8StringEncoding) else {
return nil
}
return (try? JSONSerialization.jsonObject(with: data, options: [])) as? [String: Any] ?? nil
return (try? NSJSONSerialization.JSONObjectWithData(data, options: [])) as? [String: AnyObject] ?? nil
}
}
+1 -2
View File
@@ -21,8 +21,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
public enum SlackError: String, Error {
public enum SlackError: String, ErrorType {
case AccountInactive = "account_inactive"
case AlreadyArchived = "already_archived"
case AlreadyInChannel = "already_in_channel"
+4 -3
View File
@@ -27,7 +27,7 @@ public final class SlackKit: OAuthDelegate {
internal(set) public var oauth: OAuthServer?
internal(set) public var clients: [String: Client] = [:]
fileprivate let clientOptions: ClientOptions
private let clientOptions: ClientOptions
// Initalization block
public var onClientInitalization: ((Client) -> Void)?
@@ -35,7 +35,7 @@ public final class SlackKit: OAuthDelegate {
public init(withAPIToken token: String, clientOptions: ClientOptions = ClientOptions()) {
self.clientOptions = clientOptions
let client = Client(apiToken: token)
DispatchQueue.main.async(execute: {
dispatch_async(dispatch_get_main_queue(), {
self.onClientInitalization?(client)
})
clients[token] = client
@@ -48,7 +48,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)
@@ -63,4 +63,5 @@ public final class SlackKit: OAuthDelegate {
client.connect(options: self.clientOptions)
}
}
}
+4 -4
View File
@@ -29,19 +29,19 @@ public struct Team {
internal(set) public var emailDomain: String?
internal(set) public var messageEditWindowMinutes: Int?
internal(set) public var overStorageLimit: Bool?
internal(set) public var prefs: [String: Any]?
internal(set) public var prefs: [String: AnyObject]?
internal(set) public var plan: String?
internal(set) public var icon: TeamIcon?
internal init(team: [String: Any]?) {
internal init(team: [String: AnyObject]?) {
id = team?["id"] as? String
name = team?["name"] as? String
domain = team?["domain"] as? String
emailDomain = team?["email_domain"] as? String
messageEditWindowMinutes = team?["msg_edit_window_mins"] as? Int
overStorageLimit = team?["over_storage_limit"] as? Bool
prefs = team?["prefs"] as? [String: Any]
prefs = team?["prefs"] as? [String: AnyObject]
plan = team?["plan"] as? String
icon = TeamIcon(icon: team?["icon"] as? [String: Any])
icon = TeamIcon(icon: team?["icon"] as? [String: AnyObject])
}
}
+1 -2
View File
@@ -22,7 +22,6 @@
// THE SOFTWARE.
public struct TeamIcon {
internal(set) public var image34: String?
internal(set) public var image44: String?
internal(set) public var image68: String?
@@ -32,7 +31,7 @@ public struct TeamIcon {
internal(set) public var imageOriginal: String?
internal(set) public var imageDefault: Bool?
internal init(icon: [String: Any]?) {
internal init(icon: [String: AnyObject]?) {
image34 = icon?["image_34"] as? String
image44 = icon?["image_44"] as? String
image68 = icon?["image_68"] as? String
+1 -2
View File
@@ -22,12 +22,11 @@
// THE SOFTWARE.
public struct Topic {
public let value: String?
public let creator: String?
public let lastSet: Int?
internal init(topic: [String: Any]?) {
internal init(topic: [String: AnyObject]?) {
value = topic?["value"] as? String
creator = topic?["creator"] as? String
lastSet = topic?["last_set"] as? Int
+8 -8
View File
@@ -24,7 +24,6 @@
public struct User {
public struct Profile {
internal(set) public var firstName: String?
internal(set) public var lastName: String?
internal(set) public var realName: String?
@@ -38,7 +37,7 @@ public struct User {
internal(set) public var image192: String?
internal(set) public var customProfile: CustomProfile?
internal init(profile: [String: Any]?) {
internal init(profile: [String: AnyObject]?) {
firstName = profile?["first_name"] as? String
lastName = profile?["last_name"] as? String
realName = profile?["real_name"] as? String
@@ -50,10 +49,11 @@ public struct User {
image48 = profile?["image_48"] as? String
image72 = profile?["image_72"] as? String
image192 = profile?["image_192"] as? String
customProfile = CustomProfile(customFields: profile?["fields"] as? [String: Any])
customProfile = CustomProfile(customFields: profile?["fields"] as? [String: AnyObject])
}
}
public let id: String?
internal(set) public var name: String?
internal(set) public var deleted: Bool?
@@ -73,15 +73,15 @@ public struct User {
internal(set) public var timeZone: String?
internal(set) public var timeZoneLabel: String?
internal(set) public var timeZoneOffSet: Int?
internal(set) public var preferences: [String: Any]?
internal(set) public var preferences: [String: AnyObject]?
// Client properties
internal(set) public var userGroups: [String: String]?
internal init(user: [String: Any]?) {
internal init(user: [String: AnyObject]?) {
id = user?["id"] as? String
name = user?["name"] as? String
deleted = user?["deleted"] as? Bool
profile = Profile(profile: user?["profile"] as? [String: Any])
profile = Profile(profile: user?["profile"] as? [String: AnyObject])
color = user?["color"] as? String
isAdmin = user?["is_admin"] as? Bool
isOwner = user?["is_owner"] as? Bool
@@ -96,11 +96,11 @@ public struct User {
timeZone = user?["tz"] as? String
timeZoneLabel = user?["tz_label"] as? String
timeZoneOffSet = user?["tz_offset"] as? Int
preferences = user?["prefs"] as? [String: Any]
preferences = user?["prefs"] as? [String: AnyObject]
}
internal init(id: String?) {
self.id = id
self.isBot = nil
}
}
}
+4 -3
View File
@@ -37,11 +37,11 @@ public struct UserGroup {
public let createdBy: String?
internal(set) public var updatedBy: String?
internal(set) public var deletedBy: String?
internal(set) public var preferences: [String: Any]?
internal(set) public var preferences: [String: AnyObject]?
internal(set) public var users: [String]?
internal(set) public var userCount: Int?
internal init(userGroup: [String: Any]?) {
internal init(userGroup: [String: AnyObject]?) {
id = userGroup?["id"] as? String
teamID = userGroup?["team_id"] as? String
isUserGroup = userGroup?["is_usergroup"] as? Bool
@@ -56,10 +56,11 @@ public struct UserGroup {
createdBy = userGroup?["created_by"] as? String
updatedBy = userGroup?["updated_by"] as? String
deletedBy = userGroup?["deleted_by"] as? String
preferences = userGroup?["prefs"] as? [String: Any]
preferences = userGroup?["prefs"] as? [String: AnyObject]
users = userGroup?["users"] as? [String]
if let count = userGroup?["user_count"] as? String {
userCount = Int(count)
}
}
}
+234 -244
View File
@@ -24,7 +24,6 @@
import Foundation
internal enum Endpoint: String {
case APITest = "api.test"
case AuthRevoke = "auth.revoke"
case AuthTest = "auth.test"
@@ -36,7 +35,6 @@ internal enum Endpoint: String {
case ChannelsSetTopic = "channels.setTopic"
case ChatDelete = "chat.delete"
case ChatPostMessage = "chat.postMessage"
case ChatMeMessage = "chat.meMessage"
case ChatUpdate = "chat.update"
case DNDInfo = "dnd.info"
case DNDTeamInfo = "dnd.teamInfo"
@@ -85,7 +83,7 @@ internal enum Endpoint: String {
public final class WebAPI {
public typealias FailureClosure = (_ error: SlackError)->Void
public typealias FailureClosure = (error: SlackError)->Void
public enum InfoType: String {
case Purpose = "purpose"
@@ -102,14 +100,14 @@ public final class WebAPI {
case Away = "away"
}
fileprivate enum ChannelType: String {
private enum ChannelType: String {
case Channel = "channel"
case Group = "group"
case IM = "im"
}
fileprivate let networkInterface: NetworkInterface
fileprivate let token: String
private let networkInterface: NetworkInterface
private let token: String
public init(token: String) {
self.networkInterface = NetworkInterface()
@@ -117,640 +115,631 @@ public final class WebAPI {
}
//MARK: - RTM
public func rtmStart(_ simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, success: ((_ response: [String: Any])->Void)?, failure: FailureClosure?) {
let parameters: [String: Any?] = ["simple_latest": simpleLatest, "no_unreads": noUnreads, "mpim_aware": mpimAware]
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
success?(response)
success?(response: response)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//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?(true)
success?(authenticated: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public static func oauthAccess(_ clientID: String, clientSecret: String, code: String, redirectURI: String? = nil, success: ((_ response: [String: Any])->Void)?, failure: ((SlackError)->Void)?) {
let parameters: [String: Any?] = ["client_id": clientID, "client_secret": clientSecret, "code": code, "redirect_uri": redirectURI]
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
success?(response)
success?(response:response)
}) {(error) -> Void in
failure?(error)
}
}
public static func oauthRevoke(_ token: String, test: Bool? = nil, success: ((_ revoked:Bool)->Void)?, failure: ((SlackError)->Void)?) {
let parameters: [String: Any?] = ["token": token, "test": test]
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
success?(true)
success?(revoked:true)
}) {(error) -> Void in
failure?(error)
}
}
//MARK: - Channels
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?) {
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?) {
history(.ChannelsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
(history) -> Void in
success?(history)
success?(history: history)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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)
success?(channel: channel)
}) { (error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func channelsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: Any]]?)->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)
success?(channels: channels)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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?(timestamp)
success?(ts:timestamp)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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)
success?(purposeSet: purposeSet)
}) { (error) -> Void in
failure?(error)
failure?(error: error)
}
}
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)
success?(topicSet: topicSet)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//MARK: - Messaging
public func deleteMessage(_ channel: String, ts: String, success: ((_ deleted: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["channel": channel, "ts": ts]
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?(true)
success?(deleted: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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: Any?] = ["channel": channel, "text": text.slackFormatEscaping, "as_user": asUser, "parse": parse?.rawValue, "link_names": linkNames, "unfurl_links": unfurlLinks, "unfurlMedia": unfurlMedia, "username": username, "icon_url": iconURL, "icon_emoji": iconEmoji, "attachments": encodeAttachments(attachments)]
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
success?((ts: response["ts"] as? String, response["channel"] as? String))
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func sendMeMessage(_ channel: String, text: String, success: (((ts: String?, channel: String?))->Void)?, failure: FailureClosure?) {
let parameters: [String: Any?] = ["channel": channel, "text": text.slackFormatEscaping]
networkInterface.request(.ChatMeMessage, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
success?((ts: response["ts"] as? String, response["channel"] as? String))
}) {(error) -> Void in
failure?(error)
}
}
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: Any?] = ["channel": channel, "ts": ts, "text": message.slackFormatEscaping, "parse": parse.rawValue, "link_names": linkNames, "attachments": encodeAttachments(attachments)]
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
success?(true)
success?(updated: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//MARK: - Do Not Disturb
public func dndInfo(_ user: String? = nil, success: ((_ status: DoNotDisturbStatus)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any?] = ["user": user]
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
success?(DoNotDisturbStatus(status: response))
success?(status: DoNotDisturbStatus(status: response))
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func dndTeamInfo(_ users: [String]? = nil, success: ((_ statuses: [String: DoNotDisturbStatus])->Void)?, failure: FailureClosure?) {
let parameters: [String: Any?] = ["users": users?.joined(separator: ",")]
public func dndTeamInfo(users: [String]? = nil, success: ((statuses: [String: DoNotDisturbStatus])->Void)?, failure: FailureClosure?) {
let parameters: [String: AnyObject?] = ["users":users?.joinWithSeparator(",")]
networkInterface.request(.DNDTeamInfo, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
guard let usersDictionary = response["users"] as? [String: Any] else {
success?([:])
guard let usersDictionary = response["users"] as? [String: AnyObject] else {
success?(statuses: [:])
return
}
success?(self.enumerateDNDStatuses(usersDictionary))
success?(statuses: self.enumerateDNDStatuses(usersDictionary))
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//MARK: - Emoji
public func emojiList(_ success: ((_ emojiList: [String: Any]?)->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?(response["emoji"] as? [String: Any])
success?(emojiList: response["emoji"] as? [String: AnyObject])
}) { (error) -> Void in
failure?(error)
failure?(error: error)
}
}
//MARK: - Files
public func deleteFile(_ fileID: String, success: ((_ deleted: Bool)->Void)?, failure: FailureClosure?) {
let parameters = ["file": fileID]
networkInterface.request(.FilesDelete, token: token, parameters: parameters as [String : Any]?, successClosure: {
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
success?(true)
success?(deleted: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func fileInfo(_ fileID: String, commentCount: Int = 100, totalPages: Int = 1, success: ((_ file: File)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["file": fileID, "count": commentCount, "totalPages": totalPages]
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
var file = File(file: response["file"] as? [String: Any])
(response["comments"] as? [[String: Any]])?.forEach { comment in
var file = File(file: response["file"] as? [String: AnyObject])
(response["comments"] as? [[String: AnyObject]])?.forEach { comment in
let comment = Comment(comment: comment)
if let id = comment.id {
file.comments[id] = comment
}
}
success?(file)
success?(file: file)
}) {(error) in
failure?(error)
failure?(error: error)
}
}
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: Any?] = ["file": file, "filename": filename, "filetype": filetype, "title": title, "initial_comment": initialComment, "channels": channels?.joined(separator: ",")]
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(",")]
networkInterface.uploadRequest(token, data: file, parameters: WebAPI.filterNilParameters(parameters), successClosure: {
(response) -> Void in
success?(File(file: response["file"] as? [String: Any]))
success?(file: File(file: response["file"] as? [String: AnyObject]))
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//MARK: - File Comments
public func addFileComment(_ fileID: String, comment: String, success: ((_ comment: Comment)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["file": fileID, "comment": comment.slackFormatEscaping]
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
success?(Comment(comment: response["comment"] as? [String: Any]))
success?(comment: Comment(comment: response["comment"] as? [String: AnyObject]))
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func editFileComment(_ fileID: String, commentID: String, comment: String, success: ((_ comment: Comment)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["file": fileID, "id": commentID, "comment": comment.slackFormatEscaping]
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
success?(Comment(comment: response["comment"] as? [String: Any]))
success?(comment: Comment(comment: response["comment"] as? [String: AnyObject]))
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func deleteFileComment(_ fileID: String, commentID: String, success: ((_ deleted: Bool?)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["file": fileID, "id": commentID]
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
success?(true)
success?(deleted: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//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)
success?(closed:closed)
}) {(error) -> Void in
failure?(error)
failure?(error:error)
}
}
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?) {
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?) {
history(.GroupsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
(history) -> Void in
success?(history)
success?(history: history)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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)
success?(channel: channel)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func groupsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: Any]]?)->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)
success?(channels: channels)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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?(timestamp)
success?(ts: timestamp)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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 as [String: Any]?, successClosure: {
networkInterface.request(.GroupsOpen, token: token, parameters: parameters, successClosure: {
(response) -> Void in
success?(true)
success?(opened: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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)
success?(purposeSet: purposeSet)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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)
success?(topicSet: topicSet)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//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)
success?(closed: closed)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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?) {
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?) {
history(.IMHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
(history) -> Void in
success?(history)
success?(history: history)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func imsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: Any]]?)->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)
success?(channels: channels)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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?(timestamp)
success?(ts: timestamp)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func openIM(_ userID: String, success: ((_ imID: String?)->Void)?, failure: FailureClosure?) {
let parameters = ["user": userID]
networkInterface.request(.IMOpen, token: token, parameters: parameters as [String: Any]?, successClosure: {
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
let group = response["channel"] as? [String: Any]
success?(group?["id"] as? String)
let group = response["channel"] as? [String: AnyObject]
success?(imID: group?["id"] as? String)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//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)
success?(closed: closed)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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?) {
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?) {
history(.MPIMHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: {
(history) -> Void in
success?(history)
success?(history: history)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func mpimsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: Any]]?)->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)
success?(channels: channels)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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?(timestamp)
success?(ts: timestamp)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func openMPIM(_ userIDs: [String], success: ((_ mpimID: String?)->Void)?, failure: FailureClosure?) {
let parameters = ["users": userIDs.joined(separator: ",")]
networkInterface.request(.MPIMOpen, token: token, parameters: parameters as [String: Any]?, successClosure: {
public func openMPIM(userIDs: [String], success: ((mpimID: String?)->Void)?, failure: FailureClosure?) {
let parameters = ["users":userIDs.joinWithSeparator(",")]
networkInterface.request(.MPIMOpen, token: token, parameters: parameters, successClosure: {
(response) -> Void in
let group = response["group"] as? [String: Any]
success?(group?["id"] as? String)
let group = response["group"] as? [String: AnyObject]
success?(mpimID: group?["id"] as? String)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//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?(ok)
success?(pinned: ok)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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?(ok)
success?(unpinned: ok)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
fileprivate func pin(_ endpoint: Endpoint, channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((_ ok: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any?] = ["channel": channel, "file": file, "file_comment": fileComment, "timestamp": timestamp]
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
success?(true)
success?(ok: true)
}){(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//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?(ok)
success?(reacted: ok)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
// 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?(ok)
success?(unreacted: ok)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
fileprivate 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: Any?] = ["name": name, "file": file, "file_comment": fileComment, "channel": channel, "timestamp": timestamp]
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
success?(true)
success?(ok: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//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?(ok)
success?(starred: ok)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
// 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?(ok)
success?(unstarred: ok)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
fileprivate func star(_ endpoint: Endpoint, file: String?, fileComment: String?, channel: String?, timestamp: String?, success: ((_ ok: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any?] = ["file": file, "file_comment": fileComment, "channel": channel, "timestamp": timestamp]
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
success?(true)
success?(ok: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//MARK: - Team
public func teamInfo(_ success: ((_ info: [String: Any]?)->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?(response["team"] as? [String: Any])
success?(info: response["team"] as? [String: AnyObject])
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//MARK: - Users
public func userPresence(_ user: String, success: ((_ presence: String?)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["user": user]
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
success?(response["presence"] as? String)
success?(presence: response["presence"] as? String)
}){(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func userInfo(_ id: String, success: ((_ user: User)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["user": id]
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
success?(User(user: response["user"] as? [String: Any]))
success?(user: User(user: response["user"] as? [String: AnyObject]))
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func usersList(_ includePresence: Bool = false, success: ((_ userList: [[String: Any]]?)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["presence": includePresence]
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
success?(response["members"] as? [[String: Any]])
success?(userList: response["members"] as? [[String: AnyObject]])
}){(error) -> Void in
failure?(error)
failure?(error: error)
}
}
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?(true)
success?(success: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
public func setUserPresence(_ presence: Presence, success: ((_ success: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["presence": presence.rawValue]
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
success?(true)
success?(success:true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//MARK: - Channel Utilities
fileprivate func close(_ endpoint: Endpoint, channelID: String, success: ((_ closed: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["channel": channelID]
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
success?(true)
success?(closed: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
fileprivate 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: Any] = ["channel": id, "latest": latest, "oldest": oldest, "inclusive": inclusive, "count": count, "unreads": unreads]
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?) {
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
success?(History(history: response))
success?(history: History(history: response))
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
fileprivate func info(_ endpoint: Endpoint, type: ChannelType, id: String, success: ((_ channel: Channel)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["channel": id]
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
success?(Channel(channel: response[type.rawValue] as? [String: Any]))
success?(channel: Channel(channel: response[type.rawValue] as? [String: AnyObject]))
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
fileprivate func list(_ endpoint: Endpoint, type: ChannelType, excludeArchived: Bool = false, success: ((_ channels: [[String: Any]]?)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["exclude_archived": excludeArchived]
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
success?(response[type.rawValue+"s"] as? [[String: Any]])
success?(channels: response[type.rawValue+"s"] as? [[String: AnyObject]])
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
fileprivate func mark(_ endpoint: Endpoint, channel: String, timestamp: String, success: ((_ ts: String)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["channel": channel, "ts": timestamp]
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
success?(timestamp)
success?(ts: timestamp)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
fileprivate func setInfo(_ endpoint: Endpoint, type: InfoType, channel: String, text: String, success: ((_ success: Bool)->Void)?, failure: FailureClosure?) {
let parameters: [String: Any] = ["channel": channel, type.rawValue: text]
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
success?(true)
success?(success: true)
}) {(error) -> Void in
failure?(error)
failure?(error: error)
}
}
//MARK: - Encode Attachments
fileprivate func encodeAttachments(_ attachments: [Attachment?]?) -> String? {
private func encodeAttachments(attachments: [Attachment?]?) -> NSString? {
if let attachments = attachments {
var attachmentArray: [[String: Any]] = []
var attachmentArray: [[String: AnyObject]] = []
for attachment in attachments {
if let attachment = attachment {
attachmentArray.append(attachment.dictionary)
attachmentArray.append(attachment.dictionary())
}
}
do {
let data = try JSONSerialization.data(withJSONObject: attachmentArray, options: [])
return String(data: data, encoding: String.Encoding.utf8)
let data = try NSJSONSerialization.dataWithJSONObject(attachmentArray, options: [])
let string = NSString(data: data, encoding: NSUTF8StringEncoding)
return string
} catch _ {
}
@@ -759,8 +748,8 @@ public final class WebAPI {
}
//MARK: - Filter Nil Parameters
internal static func filterNilParameters(_ parameters: [String: Any?]) -> [String: Any] {
var finalParameters = [String: Any]()
internal static func filterNilParameters(parameters: [String: AnyObject?]) -> [String: AnyObject] {
var finalParameters = [String: AnyObject]()
for (key, value) in parameters {
if let unwrapped = value {
finalParameters[key] = unwrapped
@@ -770,11 +759,12 @@ public final class WebAPI {
}
//MARK: - Enumerate Do Not Disturb Status
fileprivate func enumerateDNDStatuses(_ statuses: [String: Any]) -> [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: Any])
retVal[key] = DoNotDisturbStatus(status: statuses[key] as? [String: AnyObject])
}
return retVal
}
}
+2 -1
View File
@@ -34,7 +34,7 @@ internal struct WebhookRequest: Request {
let text: String
let responseURL: String
init(request: [String: Any]?) {
init(request: [String: AnyObject]?) {
token = request?["token"] as? String
teamID = request?["team_id"] as? String ?? ""
teamDomain = request?["team_domain"] as? String ?? ""
@@ -46,4 +46,5 @@ internal struct WebhookRequest: Request {
text = request?["text"] as? String ?? ""
responseURL = request?["response_url"] as? String ?? ""
}
}
+7 -6
View File
@@ -21,29 +21,30 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
open class WebhookServer: Server {
public class WebhookServer: Server {
public init(token: String, route: String, response: Response) {
super.init(token: token)
addRoute(route, response: response)
}
open 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."))
}
}
}
fileprivate 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)
}
}
}
+1 -1
View File
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.1.0</string>
<string>2.3.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
+1 -1
View File
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.1.0</string>
<string>2.3.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
+1 -1
View File
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>3.1.0</string>
<string>2.3.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>