diff --git a/.gitignore b/.gitignore index 3774cf3..5555180 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ DerivedData *.hmap *.ipa *.xcuserstate +*.DS_Store # SwiftPM Packages/ diff --git a/Cartfile b/Cartfile index 478e691..df9a817 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -github "https://github.com/pvzig/swifter.git" "master" -github "https://github.com/pvzig/Starscream.git" "swift3" \ No newline at end of file +git "/Users/pzignego/Repositories/swifter" "xcode8b6" +git "/Users/pzignego/Repositories/Starscream" "xcode8b6" \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved index 5825522..309979c 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -github "pvzig/Starscream" "2fde5c5eb9302439e634753c3aacc794ca2e42e8" -github "pvzig/swifter" "ddbebdde19360a2c9e4e01e5a0642dd12082cc92" +git "/Users/pzignego/Repositories/Starscream" "34ed78556478730252d77cab878ff5aa2fda7fe4" +git "/Users/pzignego/Repositories/swifter" "0b4fadaca0011da031730f225357f2b87f6e68fa" diff --git a/SlackKit/Sources/Action.swift b/SlackKit/Sources/Action.swift index 8435ab2..3f4ef14 100644 --- a/SlackKit/Sources/Action.swift +++ b/SlackKit/Sources/Action.swift @@ -50,12 +50,12 @@ public struct Action { 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["name"] = name as AnyObject? + dict["text"] = text as AnyObject? + dict["type"] = type as AnyObject? + dict["value"] = value as AnyObject? + dict["style"] = style?.rawValue as AnyObject? + dict["confirm"] = confirm?.dictionary() as AnyObject? return dict } @@ -82,10 +82,10 @@ public struct Action { internal func dictionary() -> [String: AnyObject] { var dict = [String: AnyObject]() - dict["title"] = title - dict["text"] = text - dict["ok_text"] = okText - dict["dismiss_text"] = dismissText + dict["title"] = title as AnyObject? + dict["text"] = text as AnyObject? + dict["ok_text"] = okText as AnyObject? + dict["dismiss_text"] = dismissText as AnyObject? return dict } diff --git a/SlackKit/Sources/Attachment.swift b/SlackKit/Sources/Attachment.swift index 3c85a77..a758b3e 100644 --- a/SlackKit/Sources/Attachment.swift +++ b/SlackKit/Sources/Attachment.swift @@ -86,24 +86,24 @@ public struct Attachment { internal func dictionary() -> [String: AnyObject] { var attachment = [String: AnyObject]() - attachment["fallback"] = fallback - attachment["callback_id"] = callbackID - attachment["attachment_type"] = type - attachment["color"] = color - attachment["pretext"] = pretext - attachment["authorName"] = authorName - attachment["author_link"] = authorLink - attachment["author_icon"] = authorIcon - attachment["title"] = title - attachment["title_link"] = titleLink - attachment["text"] = text - attachment["fields"] = fields?.map{$0.dictionary()} - attachment["actions"] = actions?.map{$0.dictionary()} - attachment["image_url"] = imageURL - attachment["thumb_url"] = thumbURL - attachment["footer"] = footer - attachment["footer_icon"] = footerIcon - attachment["ts"] = ts + attachment["fallback"] = fallback as AnyObject? + attachment["callback_id"] = callbackID as AnyObject? + attachment["attachment_type"] = type as AnyObject? + attachment["color"] = color as AnyObject? + attachment["pretext"] = pretext as AnyObject? + attachment["authorName"] = authorName as AnyObject? + attachment["author_link"] = authorLink as AnyObject? + attachment["author_icon"] = authorIcon as AnyObject? + attachment["title"] = title as AnyObject? + attachment["title_link"] = titleLink as AnyObject? + attachment["text"] = text as AnyObject? + attachment["fields"] = fields?.map{$0.dictionary()} as AnyObject? + attachment["actions"] = actions?.map{$0.dictionary()} as AnyObject? + attachment["image_url"] = imageURL as AnyObject? + attachment["thumb_url"] = thumbURL as AnyObject? + attachment["footer"] = footer as AnyObject? + attachment["footer_icon"] = footerIcon as AnyObject? + attachment["ts"] = ts as AnyObject? return attachment } diff --git a/SlackKit/Sources/AttachmentField.swift b/SlackKit/Sources/AttachmentField.swift index 45f3f10..3729098 100644 --- a/SlackKit/Sources/AttachmentField.swift +++ b/SlackKit/Sources/AttachmentField.swift @@ -41,9 +41,9 @@ public struct AttachmentField { internal func dictionary() -> [String: AnyObject] { var field = [String: AnyObject]() - field["title"] = title - field["value"] = value - field["short"] = short + field["title"] = title as AnyObject? + field["value"] = value as AnyObject? + field["short"] = short as AnyObject? return field } diff --git a/SlackKit/Sources/AuthorizeRequest.swift b/SlackKit/Sources/AuthorizeRequest.swift index 0e4c6d4..c73df5d 100644 --- a/SlackKit/Sources/AuthorizeRequest.swift +++ b/SlackKit/Sources/AuthorizeRequest.swift @@ -31,9 +31,9 @@ internal struct AuthorizeRequest { var parameters: [String: AnyObject] { var json = [String : AnyObject]() - json["scope"] = scope.map({$0.rawValue}).joined(separator: ",") - json["state"] = state - json["team"] = team + json["scope"] = scope.map({$0.rawValue}).joined(separator: ",") as AnyObject? + json["state"] = state as AnyObject? + json["team"] = team as AnyObject? return json } diff --git a/SlackKit/Sources/Client+EventDispatching.swift b/SlackKit/Sources/Client+EventDispatching.swift index b3d45d3..948cf3a 100644 --- a/SlackKit/Sources/Client+EventDispatching.swift +++ b/SlackKit/Sources/Client+EventDispatching.swift @@ -144,7 +144,7 @@ internal extension Client { // Other clients should ignore this event. break case .TeamMigrationStarted: - connect(options: options ?? ClientOptions()) + connect(options ?? ClientOptions()) case .ReconnectURL: // The reconnect_url event is currently unsupported and experimental. break diff --git a/SlackKit/Sources/Client+Utilities.swift b/SlackKit/Sources/Client+Utilities.swift index 0c8d118..1b2b22b 100644 --- a/SlackKit/Sources/Client+Utilities.swift +++ b/SlackKit/Sources/Client+Utilities.swift @@ -43,11 +43,11 @@ public extension Client { return id } - public func getImIDForUserWithID(_ id: String, success: (imID: String?)->Void, failure: (error: SlackError)->Void) { + public func getImIDForUserWithID(_ id: String, success: @escaping (_ imID: String?)->Void, failure: @escaping (SlackError)->Void) { let ims = channels.filter{$0.1.isIM == true} let channel = ims.filter{$0.1.user == id}.first if let channel = channel { - success(imID: channel.0) + success(channel.0) } else { webAPI.openIM(id, success: success, failure: failure) } diff --git a/SlackKit/Sources/Client.swift b/SlackKit/Sources/Client.swift index 457bb54..3544ada 100644 --- a/SlackKit/Sources/Client.swift +++ b/SlackKit/Sources/Client.swift @@ -44,7 +44,7 @@ public final class Client: WebSocketDelegate { } internal var webSocket: WebSocket? - private let pingPongQueue = DispatchQueue(label: "com.launchsoft.SlackKit") + fileprivate let pingPongQueue = DispatchQueue(label: "com.launchsoft.SlackKit") internal var ping: Double? internal var pong: Double? internal var options: ClientOptions? @@ -73,7 +73,7 @@ public final class Client: WebSocketDelegate { self.token = token } - public func connect(options: ClientOptions = ClientOptions()) { + public func connect(_ options: ClientOptions = ClientOptions()) { self.options = options webAPI.rtmStart(options.simpleLatest, noUnreads: options.noUnreads, mpimAware: options.mpimAware, success: { (response) -> Void in @@ -102,31 +102,31 @@ public final class Client: WebSocketDelegate { } } - private func formatMessageToSlackJsonString(_ message: (msg: String, channel: String)) throws -> Data { + fileprivate func formatMessageToSlackJsonString(_ message: (msg: String, channel: String)) throws -> Data { let json: [String: AnyObject] = [ - "id": Date().slackTimestamp(), - "type": "message", - "channel": message.channel, - "text": message.msg.slackFormatEscaping() + "id": Date().slackTimestamp() as AnyObject, + "type": "message" as AnyObject, + "channel": message.channel as AnyObject, + "text": message.msg.slackFormatEscaping() as AnyObject ] addSentMessage(json) return try JSONSerialization.data(withJSONObject: json, options: []) } - private func addSentMessage(_ dictionary: [String: AnyObject]) { + fileprivate func addSentMessage(_ dictionary: [String: AnyObject]) { var message = dictionary guard let id = message["id"] as? NSNumber else { return } - let ts = String(id) + let ts = String(describing: id) message.removeValue(forKey: "id") - message["ts"] = ts - message["user"] = self.authenticatedUser?.id + message["ts"] = ts as AnyObject? + message["user"] = self.authenticatedUser?.id as AnyObject? sentMessages[ts] = Message(message: message) } //MARK: - RTM Ping - private func pingRTMServerAtInterval(_ interval: TimeInterval) { + fileprivate func pingRTMServerAtInterval(_ interval: TimeInterval) { let delay = DispatchTime.now() + Double(Int64(interval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) pingPongQueue.asyncAfter(deadline: delay, execute: { guard self.connected && self.timeoutCheck() else { @@ -138,13 +138,13 @@ public final class Client: WebSocketDelegate { }) } - private func sendRTMPing() { + fileprivate func sendRTMPing() { guard connected else { return } let json: [String: AnyObject] = [ - "id": Date().slackTimestamp(), - "type": "ping", + "id": Date().slackTimestamp() as AnyObject, + "type": "ping" as AnyObject, ] guard let data = try? JSONSerialization.data(withJSONObject: json, options: []) else { return @@ -155,7 +155,7 @@ public final class Client: WebSocketDelegate { } } - private func timeoutCheck() -> Bool { + fileprivate func timeoutCheck() -> Bool { if let pong = pong, let ping = ping, let timeout = options?.timeout { if pong - ping < timeout { return true @@ -169,7 +169,7 @@ public final class Client: WebSocketDelegate { } //MARK: - Client setup - private func initialSetup(_ json: [String: AnyObject]) { + fileprivate 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]) @@ -182,28 +182,28 @@ public final class Client: WebSocketDelegate { enumerateSubteams(json["subteams"] as? [String: AnyObject]) } - private func addUser(_ aUser: [String: AnyObject]) { + fileprivate func addUser(_ aUser: [String: AnyObject]) { let user = User(user: aUser) if let id = user.id { users[id] = user } } - private func addChannel(_ aChannel: [String: AnyObject]) { + fileprivate func addChannel(_ aChannel: [String: AnyObject]) { let channel = Channel(channel: aChannel) if let id = channel.id { channels[id] = channel } } - private func addBot(_ aBot: [String: AnyObject]) { + fileprivate func addBot(_ aBot: [String: AnyObject]) { let bot = Bot(bot: aBot) if let id = bot.id { bots[id] = bot } } - private func enumerateSubteams(_ subteams: [String: AnyObject]?) { + fileprivate func enumerateSubteams(_ subteams: [String: AnyObject]?) { if let subteams = subteams { if let all = subteams["all"] as? [[String: AnyObject]] { for item in all { @@ -221,7 +221,7 @@ public final class Client: WebSocketDelegate { } // MARK: - Utilities - private func enumerateObjects(_ array: [AnyObject]?, initalizer: ([String: AnyObject])-> Void) { + fileprivate func enumerateObjects(_ array: [AnyObject]?, initalizer: ([String: AnyObject])-> Void) { if let array = array { for object in array { if let dictionary = object as? [String: AnyObject] { @@ -232,7 +232,7 @@ public final class Client: WebSocketDelegate { } // MARK: - WebSocketDelegate - public func websocketDidConnect(socket: WebSocket) { + public func websocketDidConnect(_ socket: WebSocket) { if let pingInterval = options?.pingInterval { pingRTMServerAtInterval(pingInterval) } @@ -244,7 +244,7 @@ public final class Client: WebSocketDelegate { authenticatedUser = nil connectionEventsDelegate?.clientDisconnected(self) if let options = options, options.reconnect == true { - connect(options: options) + connect(options) } } diff --git a/SlackKit/Sources/IncomingWebhook.swift b/SlackKit/Sources/IncomingWebhook.swift index 6fa8e30..c2f0ffe 100644 --- a/SlackKit/Sources/IncomingWebhook.swift +++ b/SlackKit/Sources/IncomingWebhook.swift @@ -60,12 +60,12 @@ public struct IncomingWebhook { } } - private func jsonBody(_ response: [String: AnyObject]) -> [String: AnyObject] { + fileprivate func jsonBody(_ response: [String: AnyObject]) -> [String: AnyObject] { var json = response - json["channel"] = channel - json["username"] = username - json["icon_emoji"] = iconEmoji - json["icon_url"] = iconURL + json["channel"] = channel as AnyObject? + json["username"] = username as AnyObject? + json["icon_emoji"] = iconEmoji as AnyObject? + json["icon_url"] = iconURL as AnyObject? return json } diff --git a/SlackKit/Sources/MessageActionServer.swift b/SlackKit/Sources/MessageActionServer.swift index 9a3670a..f974131 100644 --- a/SlackKit/Sources/MessageActionServer.swift +++ b/SlackKit/Sources/MessageActionServer.swift @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -public class MessageActionServer: Server { +open class MessageActionServer: Server { internal let responder: MessageActionResponder diff --git a/SlackKit/Sources/NetworkInterface.swift b/SlackKit/Sources/NetworkInterface.swift index 25f743f..9d39f39 100644 --- a/SlackKit/Sources/NetworkInterface.swift +++ b/SlackKit/Sources/NetworkInterface.swift @@ -27,7 +27,7 @@ internal struct NetworkInterface { private let apiUrl = "https://slack.com/api/" - internal func request(_ endpoint: Endpoint, token: String? = nil, parameters: [String: AnyObject]?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) { + internal func request(_ endpoint: Endpoint, token: String? = nil, parameters: [String: AnyObject]?, successClosure: @escaping ([String: AnyObject])->Void, errorClosure: @escaping (SlackError)->Void) { var requestString = "\(apiUrl)\(endpoint.rawValue)?" if let token = token { requestString += "token=\(token)" @@ -42,15 +42,15 @@ internal struct NetworkInterface { let request = URLRequest(url:url) URLSession.shared.dataTask(with: request) { (data, response, internalError) -> Void in - self.handleResponse(data, response: response, internalError: internalError, successClosure: {(json) in - successClosure(json) - }, errorClosure: {(error) in - errorClosure(error) - }) +// self.handleResponse(data, response: response, internalError: internalError, successClosure: {(json) in +// successClosure(json) +// }, errorClosure: {(error) in +// errorClosure(error) +// }) }.resume() } - internal func customRequest(_ url: String, data: Data, success: (Bool)->Void, errorClosure: (SlackError)->Void) { + internal func customRequest(_ url: String, data: Data, success: @escaping (Bool)->Void, errorClosure: @escaping (SlackError)->Void) { guard let url = URL(string: url.removePercentEncoding()) else { errorClosure(SlackError.ClientNetworkError) return @@ -71,7 +71,7 @@ internal struct NetworkInterface { }.resume() } - internal func uploadRequest(_ token: String, data: Data, parameters: [String: AnyObject]?, successClosure: ([String: AnyObject])->Void, errorClosure: (SlackError)->Void) { + internal func uploadRequest(_ token: String, data: Data, parameters: [String: AnyObject]?, successClosure: @escaping ([String: AnyObject])->Void, errorClosure: @escaping (SlackError)->Void) { var requestString = "\(apiUrl)\(Endpoint.FilesUpload.rawValue)?token=\(token)" if let params = parameters { requestString = requestString + params.requestStringFromParameters @@ -102,11 +102,11 @@ internal struct NetworkInterface { URLSession.shared.dataTask(with: request) { (data, response, internalError) -> Void in - self.handleResponse(data, response: response, internalError: internalError, successClosure: {(json) in - successClosure(json) - }, errorClosure: {(error) in - errorClosure(error) - }) +// self.handleResponse(data, response: response, internalError: internalError, successClosure: {(json) in +// successClosure(json) +// }, errorClosure: {(error) in +// errorClosure(error) +// }) }.resume() } diff --git a/SlackKit/Sources/OAuthServer.swift b/SlackKit/Sources/OAuthServer.swift index 83a6725..6660630 100644 --- a/SlackKit/Sources/OAuthServer.swift +++ b/SlackKit/Sources/OAuthServer.swift @@ -30,14 +30,14 @@ internal protocol OAuthDelegate { public struct OAuthServer { - private let oauthURL = "https://slack.com/oauth/authorize" + fileprivate let oauthURL = "https://slack.com/oauth/authorize" - private let http = HttpServer() - private let clientID: String - private let clientSecret: String - private let state: String? - private let redirectURI: String? - private var delegate: OAuthDelegate? + fileprivate let http = HttpServer() + fileprivate let clientID: String + fileprivate let clientSecret: String + fileprivate let state: String? + fileprivate let redirectURI: String? + fileprivate 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 @@ -61,7 +61,7 @@ public struct OAuthServer { http.stop() } - private func oauthRoute() { + fileprivate func oauthRoute() { http["/oauth"] = { request in guard let response = AuthorizeResponse(queryParameters: request.queryParams), response.state == self.state else { return .badRequest(.text("Bad request.")) @@ -78,7 +78,7 @@ public struct OAuthServer { } } - private func oauthURLRequest(_ authorize: AuthorizeRequest) -> URLRequest? { + fileprivate func oauthURLRequest(_ authorize: AuthorizeRequest) -> URLRequest? { var requestString = "\(oauthURL)?client_id=\(authorize.clientID)" requestString += authorize.parameters.requestStringFromParameters guard let url = URL(string: requestString) else { diff --git a/SlackKit/Sources/Response.swift b/SlackKit/Sources/Response.swift index 0c5d829..8bceafa 100644 --- a/SlackKit/Sources/Response.swift +++ b/SlackKit/Sources/Response.swift @@ -35,9 +35,9 @@ public struct Response { internal func json() -> [String: AnyObject] { var json = [String : AnyObject]() - json["text"] = text - json["response_type"] = responseType?.rawValue - json["attachments"] = attachments?.map({$0.dictionary()}) + json["text"] = text as AnyObject? + json["response_type"] = responseType?.rawValue as AnyObject? + json["attachments"] = attachments?.map({$0.dictionary()}) as AnyObject? return json } diff --git a/SlackKit/Sources/Server.swift b/SlackKit/Sources/Server.swift index ff542a7..4b4da5d 100644 --- a/SlackKit/Sources/Server.swift +++ b/SlackKit/Sources/Server.swift @@ -34,7 +34,7 @@ internal protocol Request { var responseURL: String { get } } -public class Server { +open class Server { internal let http = HttpServer() internal let token: String @@ -43,7 +43,7 @@ public class Server { self.token = token } - public func start(_ port: in_port_t = 8080, forceIPV4: Bool = false) { + open func start(_ port: in_port_t = 8080, forceIPV4: Bool = false) { do { try http.start(port, forceIPv4: forceIPV4) } catch let error as NSError { @@ -51,7 +51,7 @@ public class Server { } } - public func stop() { + open func stop() { http.stop() } @@ -73,7 +73,7 @@ public class Server { for argument in body { let kv = argument.components(separatedBy: "=") if let key = kv.first, let value = kv.last { - dict[key] = value + dict[key] = value as AnyObject? } } return dict diff --git a/SlackKit/Sources/SlackKit.swift b/SlackKit/Sources/SlackKit.swift index 709ec0d..3ec486e 100644 --- a/SlackKit/Sources/SlackKit.swift +++ b/SlackKit/Sources/SlackKit.swift @@ -27,7 +27,7 @@ public final class SlackKit: OAuthDelegate { internal(set) public var oauth: OAuthServer? internal(set) public var clients: [String: Client] = [:] - private let clientOptions: ClientOptions + fileprivate let clientOptions: ClientOptions // Initalization block public var onClientInitalization: ((Client) -> Void)? @@ -39,7 +39,7 @@ public final class SlackKit: OAuthDelegate { self.onClientInitalization?(client) }) clients[token] = client - client.connect(options: self.clientOptions) + client.connect(self.clientOptions) } // If you're going to be receiving and/or initiating OAuth requests, provide a client ID and secret @@ -60,7 +60,7 @@ public final class SlackKit: OAuthDelegate { let client = Client(apiToken: token) self.onClientInitalization?(client) clients[token] = client - client.connect(options: self.clientOptions) + client.connect(self.clientOptions) } } diff --git a/SlackKit/Sources/WebAPI.swift b/SlackKit/Sources/WebAPI.swift index fb780bc..9529954 100644 --- a/SlackKit/Sources/WebAPI.swift +++ b/SlackKit/Sources/WebAPI.swift @@ -83,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" @@ -100,14 +100,14 @@ public final class WebAPI { case Away = "away" } - private enum ChannelType: String { + fileprivate enum ChannelType: String { case Channel = "channel" case Group = "group" case IM = "im" } - private let networkInterface: NetworkInterface - private let token: String + fileprivate let networkInterface: NetworkInterface + fileprivate let token: String public init(token: String) { self.networkInterface = NetworkInterface() @@ -115,179 +115,179 @@ public final class WebAPI { } //MARK: - RTM - public func rtmStart(_ simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, success: ((response: [String: AnyObject])->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject?] = ["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 as Optional, "no_unreads": noUnreads as Optional, "mpim_aware": mpimAware as Optional] networkInterface.request(.RTMStart, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in - success?(response: response) + success?(response) }) {(error) -> Void in - failure?(error: error) + failure?(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?(authenticated: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - 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] + 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 as Optional, "client_secret": clientSecret as Optional, "code": code as Optional, "redirect_uri": redirectURI as Optional] NetworkInterface().request(.OAuthAccess, parameters: filterNilParameters(parameters), successClosure: { (response) -> Void in - success?(response:response) + success?(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: AnyObject?] = ["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 as Optional, "test": test as Optional] NetworkInterface().request(.AuthRevoke, parameters: filterNilParameters(parameters), successClosure: { (response) -> Void in - success?(revoked:true) + success?(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 = "\(Date().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((_ history: History)->Void)?, failure: FailureClosure?) { history(.ChannelsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: { (history) -> Void in - success?(history: history) + success?(history) }) {(error) -> Void in - failure?(error: error) + failure?(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: channel) + success?(channel) }) { (error) -> Void in - failure?(error: error) + failure?(error) } } - public func channelsList(_ excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { + public func channelsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { list(.ChannelsList, type:ChannelType.Channel, excludeArchived: excludeArchived, success: { (channels) -> Void in - success?(channels: channels) + success?(channels) }) {(error) -> Void in - failure?(error: error) + failure?(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?(ts:timestamp) + success?(timestamp) }) {(error) -> Void in - failure?(error: error) + failure?(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: purposeSet) + success?(purposeSet) }) { (error) -> Void in - failure?(error: error) + failure?(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: topicSet) + success?(topicSet) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } //MARK: - Messaging - public func deleteMessage(_ channel: String, ts: String, success: ((deleted: Bool)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["channel": channel, "ts": ts] + public func deleteMessage(_ channel: String, ts: String, success: ((_ deleted: Bool)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["channel": channel as AnyObject, "ts": ts as AnyObject] networkInterface.request(.ChatDelete, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(deleted: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(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: 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] + let parameters: [String: AnyObject?] = ["channel":channel as Optional, "text":text.slackFormatEscaping() as Optional, "as_user":asUser as Optional, "parse":parse?.rawValue as Optional, "link_names":linkNames as Optional, "unfurl_links":unfurlLinks as Optional, "unfurlMedia":unfurlMedia as Optional, "username":username as Optional, "icon_url":iconURL as Optional, "icon_emoji":iconEmoji as Optional, "attachments": encodeAttachments(attachments) as Optional] 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: error) + 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: AnyObject?] = ["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 as Optional, "ts": ts as Optional, "text": message.slackFormatEscaping() as Optional, "parse": parse.rawValue as Optional, "link_names": linkNames as Optional, "attachments":encodeAttachments(attachments) as Optional] networkInterface.request(.ChatUpdate, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in - success?(updated: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } //MARK: - Do Not Disturb - public func dndInfo(_ user: String? = nil, success: ((status: DoNotDisturbStatus)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject?] = ["user": user] + public func dndInfo(_ user: String? = nil, success: ((_ status: DoNotDisturbStatus)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject?] = ["user": user as Optional] networkInterface.request(.DNDInfo, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in - success?(status: DoNotDisturbStatus(status: response)) + success?(DoNotDisturbStatus(status: response)) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - public func dndTeamInfo(_ users: [String]? = nil, success: ((statuses: [String: DoNotDisturbStatus])->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject?] = ["users":users?.joined(separator: ",")] + public func dndTeamInfo(_ users: [String]? = nil, success: ((_ statuses: [String: DoNotDisturbStatus])->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject?] = ["users":users?.joined(separator: ",") as Optional] networkInterface.request(.DNDTeamInfo, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in guard let usersDictionary = response["users"] as? [String: AnyObject] else { - success?(statuses: [:]) + success?([:]) return } - success?(statuses: self.enumerateDNDStatuses(usersDictionary)) + success?(self.enumerateDNDStatuses(usersDictionary)) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } //MARK: - Emoji - public func emojiList(_ success: ((emojiList: [String: AnyObject]?)->Void)?, failure: FailureClosure?) { + public func emojiList(_ success: ((_ emojiList: [String: AnyObject]?)->Void)?, failure: FailureClosure?) { networkInterface.request(.EmojiList, token: token, parameters: nil, successClosure: { (response) -> Void in - success?(emojiList: response["emoji"] as? [String: AnyObject]) + success?(response["emoji"] as? [String: AnyObject]) }) { (error) -> Void in - failure?(error: error) + failure?(error) } } //MARK: - Files - public func deleteFile(_ fileID: String, success: ((deleted: Bool)->Void)?, failure: FailureClosure?) { + public func deleteFile(_ fileID: String, success: ((_ deleted: Bool)->Void)?, failure: FailureClosure?) { let parameters = ["file":fileID] - networkInterface.request(.FilesDelete, token: token, parameters: parameters, successClosure: { + networkInterface.request(.FilesDelete, token: token, parameters: parameters as [String : AnyObject]?, successClosure: { (response) -> Void in - success?(deleted: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - 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] + public func fileInfo(_ fileID: String, commentCount: Int = 100, totalPages: Int = 1, success: ((_ file: File)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["file":fileID as AnyObject, "count": commentCount as AnyObject, "totalPages":totalPages as AnyObject] networkInterface.request(.FilesInfo, token: token, parameters: parameters, successClosure: { (response) in var file = File(file: response["file"] as? [String: AnyObject]) @@ -297,438 +297,438 @@ public final class WebAPI { file.comments[id] = comment } } - success?(file: file) + success?(file) }) {(error) in - failure?(error: error) + failure?(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: AnyObject?] = ["file":file, "filename": filename, "filetype":filetype, "title":title, "initial_comment":initialComment, "channels":channels?.joined(separator: ",")] + public func uploadFile(_ file: Data, filename: String, filetype: String = "auto", title: String? = nil, initialComment: String? = nil, channels: [String]? = nil, success: ((_ file: File)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject?] = ["file":file as Optional, "filename": filename as Optional, "filetype":filetype as Optional, "title":title as Optional, "initial_comment":initialComment as Optional, "channels":channels?.joined(separator: ",") as Optional] networkInterface.uploadRequest(token, data: file, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in - success?(file: File(file: response["file"] as? [String: AnyObject])) + success?(File(file: response["file"] as? [String: AnyObject])) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } //MARK: - File Comments - public func addFileComment(_ fileID: String, comment: String, success: ((comment: Comment)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["file":fileID, "comment":comment.slackFormatEscaping()] + public func addFileComment(_ fileID: String, comment: String, success: ((_ comment: Comment)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["file":fileID as AnyObject, "comment":comment.slackFormatEscaping() as AnyObject] networkInterface.request(.FilesCommentsAdd, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(comment: Comment(comment: response["comment"] as? [String: AnyObject])) + success?(Comment(comment: response["comment"] as? [String: AnyObject])) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - 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()] + public func editFileComment(_ fileID: String, commentID: String, comment: String, success: ((_ comment: Comment)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["file":fileID as AnyObject, "id":commentID as AnyObject, "comment":comment.slackFormatEscaping() as AnyObject] networkInterface.request(.FilesCommentsEdit, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(comment: Comment(comment: response["comment"] as? [String: AnyObject])) + success?(Comment(comment: response["comment"] as? [String: AnyObject])) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - public func deleteFileComment(_ fileID: String, commentID: String, success: ((deleted: Bool?)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["file":fileID, "id": commentID] + public func deleteFileComment(_ fileID: String, commentID: String, success: ((_ deleted: Bool?)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["file":fileID as AnyObject, "id": commentID as AnyObject] networkInterface.request(.FilesCommentsDelete, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(deleted: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(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:closed) + success?(closed) }) {(error) -> Void in - failure?(error:error) + failure?(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 = "\(Date().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((_ history: History)->Void)?, failure: FailureClosure?) { history(.GroupsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: { (history) -> Void in - success?(history: history) + success?(history) }) {(error) -> Void in - failure?(error: error) + failure?(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: channel) + success?(channel) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - public func groupsList(_ excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { + public func groupsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { list(.GroupsList, type:ChannelType.Group, excludeArchived: excludeArchived, success: { (channels) -> Void in - success?(channels: channels) + success?(channels) }) {(error) -> Void in - failure?(error: error) + failure?(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?(ts: timestamp) + success?(timestamp) }) {(error) -> Void in - failure?(error: error) + failure?(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, successClosure: { + networkInterface.request(.GroupsOpen, token: token, parameters: parameters as [String : AnyObject]?, successClosure: { (response) -> Void in - success?(opened: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(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: purposeSet) + success?(purposeSet) }) {(error) -> Void in - failure?(error: error) + failure?(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: topicSet) + success?(topicSet) }) {(error) -> Void in - failure?(error: error) + failure?(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: closed) + success?(closed) }) {(error) -> Void in - failure?(error: error) + failure?(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 = "\(Date().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((_ history: History)->Void)?, failure: FailureClosure?) { history(.IMHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: { (history) -> Void in - success?(history: history) + success?(history) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - public func imsList(_ excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { + public func imsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { list(.IMList, type:ChannelType.IM, excludeArchived: excludeArchived, success: { (channels) -> Void in - success?(channels: channels) + success?(channels) }) {(error) -> Void in - failure?(error: error) + failure?(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?(ts: timestamp) + success?(timestamp) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - public func openIM(_ userID: String, success: ((imID: String?)->Void)?, failure: FailureClosure?) { + public func openIM(_ userID: String, success: ((_ imID: String?)->Void)?, failure: FailureClosure?) { let parameters = ["user":userID] - networkInterface.request(.IMOpen, token: token, parameters: parameters, successClosure: { + networkInterface.request(.IMOpen, token: token, parameters: parameters as [String : AnyObject]?, successClosure: { (response) -> Void in let group = response["channel"] as? [String: AnyObject] - success?(imID: group?["id"] as? String) + success?(group?["id"] as? String) }) {(error) -> Void in - failure?(error: error) + failure?(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: closed) + success?(closed) }) {(error) -> Void in - failure?(error: error) + failure?(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 = "\(Date().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((_ history: History)->Void)?, failure: FailureClosure?) { history(.MPIMHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: { (history) -> Void in - success?(history: history) + success?(history) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - public func mpimsList(_ excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { + public func mpimsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { list(.MPIMList, type:ChannelType.Group, excludeArchived: excludeArchived, success: { (channels) -> Void in - success?(channels: channels) + success?(channels) }) {(error) -> Void in - failure?(error: error) + failure?(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?(ts: timestamp) + success?(timestamp) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - public func openMPIM(_ userIDs: [String], success: ((mpimID: String?)->Void)?, failure: FailureClosure?) { + public func openMPIM(_ userIDs: [String], success: ((_ mpimID: String?)->Void)?, failure: FailureClosure?) { let parameters = ["users":userIDs.joined(separator: ",")] - networkInterface.request(.MPIMOpen, token: token, parameters: parameters, successClosure: { + networkInterface.request(.MPIMOpen, token: token, parameters: parameters as [String : AnyObject]?, successClosure: { (response) -> Void in let group = response["group"] as? [String: AnyObject] - success?(mpimID: group?["id"] as? String) + success?(group?["id"] as? String) }) {(error) -> Void in - failure?(error: error) + failure?(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?(pinned: ok) + success?(ok) }) {(error) -> Void in - failure?(error: error) + failure?(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?(unpinned: ok) + success?(ok) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - 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] + 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: AnyObject?] = ["channel":channel as Optional, "file":file as Optional, "file_comment":fileComment as Optional, "timestamp":timestamp as Optional] networkInterface.request(endpoint, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in - success?(ok: true) + success?(true) }){(error) -> Void in - failure?(error: error) + failure?(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?(reacted: ok) + success?(ok) }) {(error) -> Void in - failure?(error: error) + failure?(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?(unreacted: ok) + success?(ok) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - 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] + 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: AnyObject?] = ["name":name as Optional, "file":file as Optional, "file_comment":fileComment as Optional, "channel":channel as Optional, "timestamp":timestamp as Optional] networkInterface.request(endpoint, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in - success?(ok: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(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?(starred: ok) + success?(ok) }) {(error) -> Void in - failure?(error: error) + failure?(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?(unstarred: ok) + success?(ok) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - 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] + fileprivate func star(_ endpoint: Endpoint, file: String?, fileComment: String?, channel: String?, timestamp: String?, success: ((_ ok: Bool)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject?] = ["file":file as Optional, "file_comment":fileComment as Optional, "channel":channel as Optional, "timestamp":timestamp as Optional] networkInterface.request(endpoint, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in - success?(ok: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } //MARK: - Team - public func teamInfo(_ success: ((info: [String: AnyObject]?)->Void)?, failure: FailureClosure?) { + public func teamInfo(_ success: ((_ info: [String: AnyObject]?)->Void)?, failure: FailureClosure?) { networkInterface.request(.TeamInfo, token: token, parameters: nil, successClosure: { (response) -> Void in - success?(info: response["team"] as? [String: AnyObject]) + success?(response["team"] as? [String: AnyObject]) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } //MARK: - Users - public func userPresence(_ user: String, success: ((presence: String?)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["user":user] + public func userPresence(_ user: String, success: ((_ presence: String?)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["user":user as AnyObject] networkInterface.request(.UsersGetPresence, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(presence: response["presence"] as? String) + success?(response["presence"] as? String) }){(error) -> Void in - failure?(error: error) + failure?(error) } } - public func userInfo(_ id: String, success: ((user: User)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["user":id] + public func userInfo(_ id: String, success: ((_ user: User)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["user":id as AnyObject] networkInterface.request(.UsersInfo, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(user: User(user: response["user"] as? [String: AnyObject])) + success?(User(user: response["user"] as? [String: AnyObject])) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - public func usersList(_ includePresence: Bool = false, success: ((userList: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["presence":includePresence] + public func usersList(_ includePresence: Bool = false, success: ((_ userList: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["presence":includePresence as AnyObject] networkInterface.request(.UsersList, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(userList: response["members"] as? [[String: AnyObject]]) + success?(response["members"] as? [[String: AnyObject]]) }){(error) -> Void in - failure?(error: error) + failure?(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?(success: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - public func setUserPresence(_ presence: Presence, success: ((success: Bool)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["presence":presence.rawValue] + public func setUserPresence(_ presence: Presence, success: ((_ success: Bool)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["presence":presence.rawValue as AnyObject] networkInterface.request(.UsersSetPresence, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(success:true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } //MARK: - Channel Utilities - private func close(_ endpoint: Endpoint, channelID: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["channel":channelID] + fileprivate func close(_ endpoint: Endpoint, channelID: String, success: ((_ closed: Bool)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["channel":channelID as AnyObject] networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(closed: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - private func history(_ endpoint: Endpoint, id: String, latest: String = "\(Date().timeIntervalSince1970)", oldest: String = "0", inclusive: Bool = false, count: Int = 100, unreads: Bool = false, success: ((history: History)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["channel": id, "latest": latest, "oldest": oldest, "inclusive":inclusive, "count":count, "unreads":unreads] + 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: AnyObject] = ["channel": id as AnyObject, "latest": latest as AnyObject, "oldest": oldest as AnyObject, "inclusive":inclusive as AnyObject, "count":count as AnyObject, "unreads":unreads as AnyObject] networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(history: History(history: response)) + success?(History(history: response)) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - private func info(_ endpoint: Endpoint, type: ChannelType, id: String, success: ((channel: Channel)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["channel": id] + fileprivate func info(_ endpoint: Endpoint, type: ChannelType, id: String, success: ((_ channel: Channel)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["channel": id as AnyObject] networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(channel: Channel(channel: response[type.rawValue] as? [String: AnyObject])) + success?(Channel(channel: response[type.rawValue] as? [String: AnyObject])) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - private func list(_ endpoint: Endpoint, type: ChannelType, excludeArchived: Bool = false, success: ((channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["exclude_archived": excludeArchived] + fileprivate func list(_ endpoint: Endpoint, type: ChannelType, excludeArchived: Bool = false, success: ((_ channels: [[String: AnyObject]]?)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["exclude_archived": excludeArchived as AnyObject] networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(channels: response[type.rawValue+"s"] as? [[String: AnyObject]]) + success?(response[type.rawValue+"s"] as? [[String: AnyObject]]) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - private func mark(_ endpoint: Endpoint, channel: String, timestamp: String, success: ((ts: String)->Void)?, failure: FailureClosure?) { - let parameters: [String: AnyObject] = ["channel": channel, "ts": timestamp] + fileprivate func mark(_ endpoint: Endpoint, channel: String, timestamp: String, success: ((_ ts: String)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["channel": channel as AnyObject, "ts": timestamp as AnyObject] networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(ts: timestamp) + success?(timestamp) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } - 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] + fileprivate func setInfo(_ endpoint: Endpoint, type: InfoType, channel: String, text: String, success: ((_ success: Bool)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["channel": channel as AnyObject, type.rawValue: text as AnyObject] networkInterface.request(endpoint, token: token, parameters: parameters, successClosure: { (response) -> Void in - success?(success: true) + success?(true) }) {(error) -> Void in - failure?(error: error) + failure?(error) } } //MARK: - Encode Attachments - private func encodeAttachments(_ attachments: [Attachment?]?) -> String? { + fileprivate func encodeAttachments(_ attachments: [Attachment?]?) -> String? { if let attachments = attachments { var attachmentArray: [[String: AnyObject]] = [] for attachment in attachments { @@ -758,7 +758,7 @@ public final class WebAPI { } //MARK: - Enumerate Do Not Disturb Status - private func enumerateDNDStatuses(_ statuses: [String: AnyObject]) -> [String: DoNotDisturbStatus] { + fileprivate func enumerateDNDStatuses(_ statuses: [String: AnyObject]) -> [String: DoNotDisturbStatus] { var retVal = [String: DoNotDisturbStatus]() for key in statuses.keys { retVal[key] = DoNotDisturbStatus(status: statuses[key] as? [String: AnyObject]) diff --git a/SlackKit/Sources/WebhookServer.swift b/SlackKit/Sources/WebhookServer.swift index aaab571..cff939d 100644 --- a/SlackKit/Sources/WebhookServer.swift +++ b/SlackKit/Sources/WebhookServer.swift @@ -21,14 +21,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -public class WebhookServer: Server { +open class WebhookServer: Server { public init(token: String, route: String, response: Response) { super.init(token: token) addRoute(route, response: response) } - public func addRoute(_ route: String, response: Response) { + open func addRoute(_ route: String, response: Response) { http["/\(route)"] = { request in let webhookRequest = WebhookRequest(request: self.dictionaryFromRequest(request.body)) if webhookRequest.token == self.token { @@ -39,7 +39,7 @@ public class WebhookServer: Server { } } - private func replyForResponse(_ response: Response) -> Reply { + fileprivate func replyForResponse(_ response: Response) -> Reply { if response.attachments == nil && response.responseType == nil { return Reply.text(body: response.text) } else {