diff --git a/Sources/App/Services/HelloBot.swift b/Sources/App/Services/HelloBot.swift index 0cc64cf..e772c10 100644 --- a/Sources/App/Services/HelloBot.swift +++ b/Sources/App/Services/HelloBot.swift @@ -1,6 +1,6 @@ // // HelloBot.swift -// Slack +// Chameleon // // Created by Ian Keen on 4/06/2016. // diff --git a/Sources/App/Services/KarmaBot.swift b/Sources/App/Services/KarmaBot.swift index 119e388..2bd31ba 100644 --- a/Sources/App/Services/KarmaBot.swift +++ b/Sources/App/Services/KarmaBot.swift @@ -1,6 +1,6 @@ // // KarmaBot.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/App/main.swift b/Sources/App/main.swift index 9155b3a..8011f40 100644 --- a/Sources/App/main.swift +++ b/Sources/App/main.swift @@ -1,6 +1,6 @@ // // main.swift -// Slack +// Chameleon // // Created by Ian Keen on 28/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Bot/Adaptors/MessageAdaptor.swift b/Sources/Bot/Adaptors/MessageAdaptor.swift index 0fea1e4..771e9c2 100644 --- a/Sources/Bot/Adaptors/MessageAdaptor.swift +++ b/Sources/Bot/Adaptors/MessageAdaptor.swift @@ -1,6 +1,6 @@ // // MessageAdaptor.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -73,7 +73,7 @@ public struct MessageAdaptor { } //MARK: - Lifecycle - internal init(message: Message, slackModels: SlackBot.SlackModelClosure) { + init(message: Message, slackModels: SlackBot.SlackModelClosure) { self.message = message self.slackModels = slackModels } @@ -84,7 +84,7 @@ extension MessageAdaptor { public let link: String public let displayText: String - internal init?(link: String) { + init?(link: String) { let components = link.components(separatedBy: "|") guard @@ -98,7 +98,7 @@ extension MessageAdaptor { } extension Message { - internal func toAdaptor(slackModels: SlackBot.SlackModelClosure) -> MessageAdaptor { + func toAdaptor(slackModels: SlackBot.SlackModelClosure) -> MessageAdaptor { return MessageAdaptor(message: self, slackModels: slackModels) } } diff --git a/Sources/Bot/Builders/SlackMessageBuilder+Operators.swift b/Sources/Bot/Builders/SlackMessageBuilder+Operators.swift index 994a810..2b41029 100644 --- a/Sources/Bot/Builders/SlackMessageBuilder+Operators.swift +++ b/Sources/Bot/Builders/SlackMessageBuilder+Operators.swift @@ -1,6 +1,6 @@ // // SlackMessageBuilder+Operators.swift -// Slack +// Chameleon // // Created by Ian Keen on 6/06/2016. // diff --git a/Sources/Bot/Builders/SlackMessageBuilder.swift b/Sources/Bot/Builders/SlackMessageBuilder.swift index b7eca16..f025be4 100644 --- a/Sources/Bot/Builders/SlackMessageBuilder.swift +++ b/Sources/Bot/Builders/SlackMessageBuilder.swift @@ -1,6 +1,6 @@ // // SlackMessageBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 6/06/2016. // diff --git a/Sources/Bot/Services/Storage/MemoryStorage.swift b/Sources/Bot/Services/Storage/MemoryStorage.swift index 0d241c5..2337fa1 100644 --- a/Sources/Bot/Services/Storage/MemoryStorage.swift +++ b/Sources/Bot/Services/Storage/MemoryStorage.swift @@ -1,6 +1,6 @@ // // MemoryStorage.swift -// Slack +// Chameleon // // Created by Ian Keen on 24/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Bot/Services/Storage/PlistStorage.swift b/Sources/Bot/Services/Storage/PlistStorage.swift index 6ec2fd6..f375eb8 100644 --- a/Sources/Bot/Services/Storage/PlistStorage.swift +++ b/Sources/Bot/Services/Storage/PlistStorage.swift @@ -1,6 +1,6 @@ //// //// PlistStorage.swift -//// Slack +//// Chameleon //// //// Created by Ian Keen on 23/05/2016. //// Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Bot/Services/Storage/Storage.swift b/Sources/Bot/Services/Storage/Storage.swift index 5bf2436..904ff7b 100644 --- a/Sources/Bot/Services/Storage/Storage.swift +++ b/Sources/Bot/Services/Storage/Storage.swift @@ -1,6 +1,6 @@ // // Storage.swift -// Slack +// Chameleon // // Created by Ian Keen on 23/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Bot/SlackBot+API.swift b/Sources/Bot/SlackBot+API.swift index 8d81987..ddd473b 100644 --- a/Sources/Bot/SlackBot+API.swift +++ b/Sources/Bot/SlackBot+API.swift @@ -1,6 +1,6 @@ // // SlackBot+API.swift -// Slack +// Chameleon // // Created by Ian Keen on 19/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Bot/SlackBot+Config.swift b/Sources/Bot/SlackBot+Config.swift index aec2862..6383948 100644 --- a/Sources/Bot/SlackBot+Config.swift +++ b/Sources/Bot/SlackBot+Config.swift @@ -1,6 +1,6 @@ // // SlackBot+Config.swift -// Slack +// Chameleon // // Created by Ian Keen on 19/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Bot/SlackBot+Convenience.swift b/Sources/Bot/SlackBot+Convenience.swift index 66c8fbf..abcfa50 100644 --- a/Sources/Bot/SlackBot+Convenience.swift +++ b/Sources/Bot/SlackBot+Convenience.swift @@ -1,6 +1,6 @@ // // SlackBot+Convenience.swift -// Slack +// Chameleon // // Created by Ian Keen on 7/06/2016. // diff --git a/Sources/Bot/SlackBot+Interaction.swift b/Sources/Bot/SlackBot+Interaction.swift index 021228c..ae63735 100644 --- a/Sources/Bot/SlackBot+Interaction.swift +++ b/Sources/Bot/SlackBot+Interaction.swift @@ -1,6 +1,6 @@ // // SlackBot+Interaction.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Bot/SlackBot.swift b/Sources/Bot/SlackBot.swift index 9dbae3e..78b45eb 100644 --- a/Sources/Bot/SlackBot.swift +++ b/Sources/Bot/SlackBot.swift @@ -1,6 +1,6 @@ // // SlackBot.swift -// Slack +// Chameleon // // Created by Ian Keen on 19/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -37,16 +37,16 @@ public class SlackBot { } } - //MARK: - Internal Properties - internal let webAPI: WebAPI - internal let rtmAPI: RTMAPI - internal private(set) var botUser: BotUser? - internal private(set) var team: Team? - internal private(set) var users: [User] = [] - internal private(set) var channels: [Channel] = [] - internal private(set) var groups: [Group] = [] - internal private(set) var ims: [IM] = [] - //internal private(set) var mpims: [MPIM] = [] + //MARK: - Properties + let webAPI: WebAPI + let rtmAPI: RTMAPI + private(set) var botUser: BotUser? + private(set) var team: Team? + private(set) var users: [User] = [] + private(set) var channels: [Channel] = [] + private(set) var groups: [Group] = [] + private(set) var ims: [IM] = [] + //private(set) var mpims: [MPIM] = [] //MARK: - Public Properties public private(set) var storage: Storage @@ -189,7 +189,7 @@ extension SlackBot { guard self.state.ready else { return } self.apis.forEach { $0.event(slackBot: self, event: event, webApi: self.webAPI) } } - internal func notify(error: ErrorProtocol) { + func notify(error: ErrorProtocol) { guard self.state.ready else { return } self.apis.forEach { $0.error(slackBot: self, error: error) } } @@ -257,7 +257,7 @@ extension SlackBot { //MARK: - Model Helpers extension SlackBot { - internal typealias SlackModelClosure = WebAPI.SlackModelClosure + typealias SlackModelClosure = WebAPI.SlackModelClosure private func slackModels() -> SlackModelClosure { return { diff --git a/Sources/Common/Box.swift b/Sources/Common/Box.swift index f71d960..b1c5544 100644 --- a/Sources/Common/Box.swift +++ b/Sources/Common/Box.swift @@ -1,6 +1,6 @@ // // Box.swift -// Slack +// Chameleon // // Created by Ian Keen on 22/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Common/Dictionary+Extensions.swift b/Sources/Common/Dictionary+Extensions.swift index aec0909..5033408 100644 --- a/Sources/Common/Dictionary+Extensions.swift +++ b/Sources/Common/Dictionary+Extensions.swift @@ -1,6 +1,6 @@ // // Dictionary+Extensions.swift -// Slack +// Chameleon // // Created by Ian Keen on 11/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Common/Int+Extensions.swift b/Sources/Common/Int+Extensions.swift index b156ed6..8204dab 100644 --- a/Sources/Common/Int+Extensions.swift +++ b/Sources/Common/Int+Extensions.swift @@ -1,6 +1,6 @@ // // Int+Extensions.swift -// Slack +// Chameleon // // Created by Ian Keen on 8/06/2016. // diff --git a/Sources/Common/JSON+KeyPath.swift b/Sources/Common/JSON+KeyPath.swift index 18131f0..4d8f6a1 100644 --- a/Sources/Common/JSON+KeyPath.swift +++ b/Sources/Common/JSON+KeyPath.swift @@ -1,6 +1,6 @@ // // JSON+KeyPath.swift -// Slack +// Chameleon // // Created by Ian Keen on 8/06/2016. // diff --git a/Sources/Common/Sequence+Extensions.swift b/Sources/Common/Sequence+Extensions.swift index 137b6d4..3cac045 100644 --- a/Sources/Common/Sequence+Extensions.swift +++ b/Sources/Common/Sequence+Extensions.swift @@ -1,6 +1,6 @@ // // Sequence+Extensions.swift -// Slack +// Chameleon // // Created by Ian Keen on 10/06/2016. // diff --git a/Sources/Models/BotUser.swift b/Sources/Models/BotUser.swift index 4b127d0..39b54ac 100644 --- a/Sources/Models/BotUser.swift +++ b/Sources/Models/BotUser.swift @@ -1,6 +1,6 @@ // // BotUser.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Channel.swift b/Sources/Models/Channel.swift index b7117a3..03df139 100644 --- a/Sources/Models/Channel.swift +++ b/Sources/Models/Channel.swift @@ -1,6 +1,6 @@ // // Channel.swift -// Slack +// Chameleon // // Created by Ian Keen on 25/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/CustomEmoji.swift b/Sources/Models/CustomEmoji.swift index b462e0c..b27fe41 100644 --- a/Sources/Models/CustomEmoji.swift +++ b/Sources/Models/CustomEmoji.swift @@ -1,6 +1,6 @@ // // CustomEmoji.swift -// Slack +// Chameleon // // Created by Ian Keen on 6/06/2016. // diff --git a/Sources/Models/DefaultValueType.swift b/Sources/Models/DefaultValueType.swift index 46cc355..43dd8fb 100644 --- a/Sources/Models/DefaultValueType.swift +++ b/Sources/Models/DefaultValueType.swift @@ -1,6 +1,6 @@ // // DefaultValueType.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Emoji.swift b/Sources/Models/Emoji.swift index 92b9c59..c93fc15 100644 --- a/Sources/Models/Emoji.swift +++ b/Sources/Models/Emoji.swift @@ -1,6 +1,6 @@ // // Emoji.swift -// Slack +// Chameleon // // Created by Ian Keen on 6/06/2016. // diff --git a/Sources/Models/Extensions/User+Extensions.swift b/Sources/Models/Extensions/User+Extensions.swift index de45f5a..910ce36 100644 --- a/Sources/Models/Extensions/User+Extensions.swift +++ b/Sources/Models/Extensions/User+Extensions.swift @@ -1,6 +1,6 @@ // // User+Extensions.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Group.swift b/Sources/Models/Group.swift index 63cf293..5db4f76 100644 --- a/Sources/Models/Group.swift +++ b/Sources/Models/Group.swift @@ -1,6 +1,6 @@ // // Group.swift -// Slack +// Chameleon // // Created by Ian Keen on 25/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/IM.swift b/Sources/Models/IM.swift index 0fe3e54..8ed6b53 100644 --- a/Sources/Models/IM.swift +++ b/Sources/Models/IM.swift @@ -1,6 +1,6 @@ // // IM.swift -// Slack +// Chameleon // // Created by Ian Keen on 25/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/IdentifiableType.swift b/Sources/Models/IdentifiableType.swift index 799825c..f6aca2d 100644 --- a/Sources/Models/IdentifiableType.swift +++ b/Sources/Models/IdentifiableType.swift @@ -1,6 +1,6 @@ // // IdentifiableType.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Message+Attachment.swift b/Sources/Models/Message+Attachment.swift index c34f514..60f920b 100644 --- a/Sources/Models/Message+Attachment.swift +++ b/Sources/Models/Message+Attachment.swift @@ -1,6 +1,6 @@ // // Message+Attachment.swift -// Slack +// Chameleon // // Created by Ian Keen on 23/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Message+Edit.swift b/Sources/Models/Message+Edit.swift index ed7c06f..f895ad4 100644 --- a/Sources/Models/Message+Edit.swift +++ b/Sources/Models/Message+Edit.swift @@ -1,6 +1,6 @@ // // Message+Edit.swift -// Slack +// Chameleon // // Created by Ian Keen on 23/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Message+ItemType.swift b/Sources/Models/Message+ItemType.swift index 5676827..31a2124 100644 --- a/Sources/Models/Message+ItemType.swift +++ b/Sources/Models/Message+ItemType.swift @@ -1,6 +1,6 @@ // // Message+ItemType.swift -// Slack +// Chameleon // // Created by Ian Keen on 23/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Message+Reaction.swift b/Sources/Models/Message+Reaction.swift index 15e2a90..a076793 100644 --- a/Sources/Models/Message+Reaction.swift +++ b/Sources/Models/Message+Reaction.swift @@ -1,6 +1,6 @@ // // Message+Reaction.swift -// Slack +// Chameleon // // Created by Ian Keen on 23/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Message+SubType.swift b/Sources/Models/Message+SubType.swift index eb819a0..1c8776d 100644 --- a/Sources/Models/Message+SubType.swift +++ b/Sources/Models/Message+SubType.swift @@ -1,6 +1,6 @@ // // Message+SubType.swift -// Slack +// Chameleon // // Created by Ian Keen on 23/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Message.swift b/Sources/Models/Message.swift index 22e964c..7f94049 100644 --- a/Sources/Models/Message.swift +++ b/Sources/Models/Message.swift @@ -1,6 +1,6 @@ // // Message.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Purpose.swift b/Sources/Models/Purpose.swift index 2c3bc2e..1088bb9 100644 --- a/Sources/Models/Purpose.swift +++ b/Sources/Models/Purpose.swift @@ -1,6 +1,6 @@ // // Purpose.swift -// Slack +// Chameleon // // Created by Ian Keen on 23/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/SlackModelBuilder.swift b/Sources/Models/SlackModelBuilder.swift index 17264fa..88c41db 100644 --- a/Sources/Models/SlackModelBuilder.swift +++ b/Sources/Models/SlackModelBuilder.swift @@ -1,6 +1,6 @@ // // SlackModelBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/SlackModelType.swift b/Sources/Models/SlackModelType.swift index da1b841..b6956af 100644 --- a/Sources/Models/SlackModelType.swift +++ b/Sources/Models/SlackModelType.swift @@ -1,6 +1,6 @@ // // SlackModelType.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -14,7 +14,7 @@ public protocol SlackModelType { static func make(builder: SlackModelBuilder) throws -> Self } -internal func tryMake(_ op: @autoclosure () throws -> T) throws -> T { +func tryMake(_ op: @autoclosure () throws -> T) throws -> T { do { return try op() } catch let error { throw SlackModelTypeError.BuildError(type: T.self, error: error) } } diff --git a/Sources/Models/SlackModelTypeIdentifiable.swift b/Sources/Models/SlackModelTypeIdentifiable.swift index e2dbfdd..ef12051 100644 --- a/Sources/Models/SlackModelTypeIdentifiable.swift +++ b/Sources/Models/SlackModelTypeIdentifiable.swift @@ -1,6 +1,6 @@ // // SlackModelTypeIdentifiable.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Target.swift b/Sources/Models/Target.swift index d1e6a97..44cf4b0 100644 --- a/Sources/Models/Target.swift +++ b/Sources/Models/Target.swift @@ -1,6 +1,6 @@ // // Target.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Team.swift b/Sources/Models/Team.swift index ab988ec..6bacbe8 100644 --- a/Sources/Models/Team.swift +++ b/Sources/Models/Team.swift @@ -1,6 +1,6 @@ // // Team.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/Topic.swift b/Sources/Models/Topic.swift index d160aa9..f379652 100644 --- a/Sources/Models/Topic.swift +++ b/Sources/Models/Topic.swift @@ -1,6 +1,6 @@ // // Topic.swift -// Slack +// Chameleon // // Created by Ian Keen on 23/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Models/User.swift b/Sources/Models/User.swift index 6adbe71..015858c 100644 --- a/Sources/Models/User.swift +++ b/Sources/Models/User.swift @@ -1,6 +1,6 @@ // // User.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/RTMAPI/Events/ErrorBuilder.swift b/Sources/RTMAPI/Events/ErrorBuilder.swift index 3f7aadc..fbabefb 100644 --- a/Sources/RTMAPI/Events/ErrorBuilder.swift +++ b/Sources/RTMAPI/Events/ErrorBuilder.swift @@ -1,6 +1,6 @@ // // ErrorBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 24/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,11 +9,12 @@ import Models import Jay -internal struct ErrorBuilder: RTMAPIEventBuilder { +/// Handler for the `error` event +struct ErrorBuilder: RTMAPIEventBuilder { static var eventType: String { return "error" } - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { - guard self.canMake(json: json) else { throw RTMAPIEventBuilderError.InvalidBuilder } + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { + guard self.canMake(fromJson: json) else { throw RTMAPIEventBuilderError.invalidBuilder(builder: self) } let builder = builderFactory(json: json) diff --git a/Sources/RTMAPI/Events/HelloBuilder.swift b/Sources/RTMAPI/Events/HelloBuilder.swift index 9a7e3f7..ab6cff9 100644 --- a/Sources/RTMAPI/Events/HelloBuilder.swift +++ b/Sources/RTMAPI/Events/HelloBuilder.swift @@ -1,6 +1,6 @@ // // HelloBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,11 +9,12 @@ import Models import Jay -internal struct HelloBuilder: RTMAPIEventBuilder { +/// Handler for the `hello` event +struct HelloBuilder: RTMAPIEventBuilder { static var eventType: String { return "hello" } - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { - guard self.canMake(json: json) else { throw RTMAPIEventBuilderError.InvalidBuilder } + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { + guard self.canMake(fromJson: json) else { throw RTMAPIEventBuilderError.invalidBuilder(builder: self) } return .hello } } diff --git a/Sources/RTMAPI/Events/MessageBuilder.swift b/Sources/RTMAPI/Events/MessageBuilder.swift index 7fde4c6..2f4565e 100644 --- a/Sources/RTMAPI/Events/MessageBuilder.swift +++ b/Sources/RTMAPI/Events/MessageBuilder.swift @@ -1,6 +1,6 @@ // // MessageBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,11 +9,12 @@ import Models import Jay -internal struct MessageBuilder: RTMAPIEventBuilder { +/// Handler for the `message` event +struct MessageBuilder: RTMAPIEventBuilder { static var eventType: String { return "message" } - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { - guard self.canMake(json: json) else { throw RTMAPIEventBuilderError.InvalidBuilder } + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { + guard self.canMake(fromJson: json) else { throw RTMAPIEventBuilderError.invalidBuilder(builder: self) } //edits contain the message as a nested item :\ let previousMessageJson = json["message"] diff --git a/Sources/RTMAPI/Events/PingPongBuilder.swift b/Sources/RTMAPI/Events/PingPongBuilder.swift index 7907d0e..82b8f2e 100644 --- a/Sources/RTMAPI/Events/PingPongBuilder.swift +++ b/Sources/RTMAPI/Events/PingPongBuilder.swift @@ -1,6 +1,6 @@ // // PingPongBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 23/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,11 +9,13 @@ import Models import Jay -internal struct PingPongBuilder: RTMAPIEventBuilder { +/// Handler for the `pong` event +struct PingPongBuilder: RTMAPIEventBuilder { static var eventType: String { return "pong" } - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { - guard self.canMake(json: json) else { throw RTMAPIEventBuilderError.InvalidBuilder } + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { + guard self.canMake(fromJson: json) else { throw RTMAPIEventBuilderError.invalidBuilder(builder: self) } + return .pong(response: json) } } diff --git a/Sources/RTMAPI/Events/PresenceChangeBuilder.swift b/Sources/RTMAPI/Events/PresenceChangeBuilder.swift index 10fcf75..faa336e 100644 --- a/Sources/RTMAPI/Events/PresenceChangeBuilder.swift +++ b/Sources/RTMAPI/Events/PresenceChangeBuilder.swift @@ -1,6 +1,6 @@ // // PresenceChangeBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,11 +9,12 @@ import Models import Jay -internal struct PresenceChangeBuilder: RTMAPIEventBuilder { +/// Handler for the `presence_change` event +struct PresenceChangeBuilder: RTMAPIEventBuilder { static var eventType: String { return "presence_change" } - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { - guard self.canMake(json: json) else { throw RTMAPIEventBuilderError.InvalidBuilder } + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { + guard self.canMake(fromJson: json) else { throw RTMAPIEventBuilderError.invalidBuilder(builder: self) } let builder = builderFactory(json: json) diff --git a/Sources/RTMAPI/Events/RTMAPIEvent+Builders.swift b/Sources/RTMAPI/Events/RTMAPIEvent+Builders.swift deleted file mode 100644 index 235839b..0000000 --- a/Sources/RTMAPI/Events/RTMAPIEvent+Builders.swift +++ /dev/null @@ -1,64 +0,0 @@ -// -// RTMAPIEvent+Builders.swift -// Slack -// -// Created by Ian Keen on 20/05/2016. -// Copyright © 2016 Mustard. All rights reserved. -// - -import Models -import Jay - -internal enum RTMAPIEventBuilderError: ErrorProtocol { - case NoAvailableBuilder(type: String) - case InvalidBuilder -} - -internal protocol RTMAPIEventBuilder { - static var eventType: String { get } - static func canMake(json: JSON) -> Bool - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent -} - -extension RTMAPIEventBuilder { - static func canMake(json: JSON) -> Bool { - guard let event = json["type"]?.string else { return false } - return (event == self.eventType) - } -} - -internal extension RTMAPIEvent { - static func builder(json: JSON) throws -> RTMAPIEventBuilder.Type { - - //Add builders here: - // - //The idea here is to break out the 'building' of all the slack events - //in an attempt to manage their creation a little easier - //rather than a single `init(json:)` on `RTMAPIEvent` with a ton of - //if/else clauses depending on the `type` of event - // - - let builders: [String: RTMAPIEventBuilder.Type] = [ - ErrorBuilder.eventType: ErrorBuilder.self, - PingPongBuilder.eventType: PingPongBuilder.self, - ReconnectURLBuilder.eventType: ReconnectURLBuilder.self, - PresenceChangeBuilder.eventType: PresenceChangeBuilder.self, - HelloBuilder.eventType: HelloBuilder.self, - UserTypingBuilder.eventType: UserTypingBuilder.self, - MessageBuilder.eventType: MessageBuilder.self, - ReactionAddedBuilder.eventType: ReactionAddedBuilder.self, - ReactionRemovedBuilder.eventType: ReactionRemovedBuilder.self, - UserChangeBuilder.eventType: UserChangeBuilder.self, - ] - - guard - let type = json["type"]?.string, - let builder = builders[type] - else { - print(json) //TODO remove once all builders are built - throw RTMAPIEventBuilderError.NoAvailableBuilder(type: json["type"]?.string ?? "no_type") - } - - return builder - } -} diff --git a/Sources/RTMAPI/Events/ReactionAddedBuilder.swift b/Sources/RTMAPI/Events/ReactionAddedBuilder.swift index 816c1c7..9057500 100644 --- a/Sources/RTMAPI/Events/ReactionAddedBuilder.swift +++ b/Sources/RTMAPI/Events/ReactionAddedBuilder.swift @@ -1,6 +1,6 @@ // // ReactionAddedBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,11 +9,12 @@ import Models import Jay -internal struct ReactionAddedBuilder: RTMAPIEventBuilder { +/// Handler for the `reaction_added` event +struct ReactionAddedBuilder: RTMAPIEventBuilder { static var eventType: String { return "reaction_added" } - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { - guard self.canMake(json: json) else { throw RTMAPIEventBuilderError.InvalidBuilder } + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { + guard self.canMake(fromJson: json) else { throw RTMAPIEventBuilderError.invalidBuilder(builder: self) } let builder = builderFactory(json: json) diff --git a/Sources/RTMAPI/Events/ReactionRemovedBuilder.swift b/Sources/RTMAPI/Events/ReactionRemovedBuilder.swift index b1468c8..e1003f8 100644 --- a/Sources/RTMAPI/Events/ReactionRemovedBuilder.swift +++ b/Sources/RTMAPI/Events/ReactionRemovedBuilder.swift @@ -1,6 +1,6 @@ // // ReactionRemovedBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 22/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,11 +9,12 @@ import Models import Jay -internal struct ReactionRemovedBuilder: RTMAPIEventBuilder { +/// Handler for the `reaction_removed` event +struct ReactionRemovedBuilder: RTMAPIEventBuilder { static var eventType: String { return "reaction_removed" } - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { - guard self.canMake(json: json) else { throw RTMAPIEventBuilderError.InvalidBuilder } + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { + guard self.canMake(fromJson: json) else { throw RTMAPIEventBuilderError.invalidBuilder(builder: self) } let builder = builderFactory(json: json) diff --git a/Sources/RTMAPI/Events/ReconnectURLBuilder.swift b/Sources/RTMAPI/Events/ReconnectURLBuilder.swift index 3022d3f..a55ba8b 100644 --- a/Sources/RTMAPI/Events/ReconnectURLBuilder.swift +++ b/Sources/RTMAPI/Events/ReconnectURLBuilder.swift @@ -1,6 +1,6 @@ // // ReconnectURLBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,12 +9,13 @@ import Models import Jay -internal struct ReconnectURLBuilder: RTMAPIEventBuilder { +/// Handler for the `reconnect_url` event +struct ReconnectURLBuilder: RTMAPIEventBuilder { static var eventType: String { return "reconnect_url" } - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { - guard self.canMake(json: json) else { throw RTMAPIEventBuilderError.InvalidBuilder } + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { + guard self.canMake(fromJson: json) else { throw RTMAPIEventBuilderError.invalidBuilder(builder: self) } return .reconnect_url(url: json["url"]?.string ?? "") } -} \ No newline at end of file +} diff --git a/Sources/RTMAPI/Events/UserChangeBuilder.swift b/Sources/RTMAPI/Events/UserChangeBuilder.swift index 658a2b3..19529e5 100644 --- a/Sources/RTMAPI/Events/UserChangeBuilder.swift +++ b/Sources/RTMAPI/Events/UserChangeBuilder.swift @@ -1,6 +1,6 @@ // // UserChangeBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 25/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,11 +9,12 @@ import Models import Jay -internal struct UserChangeBuilder: RTMAPIEventBuilder { +/// Handler for the `user_change` event +struct UserChangeBuilder: RTMAPIEventBuilder { static var eventType: String { return "user_change" } - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { - guard self.canMake(json: json) else { throw RTMAPIEventBuilderError.InvalidBuilder } + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { + guard self.canMake(fromJson: json) else { throw RTMAPIEventBuilderError.invalidBuilder(builder: self) } let builder = builderFactory(json: json) diff --git a/Sources/RTMAPI/Events/UserTypingBuilder.swift b/Sources/RTMAPI/Events/UserTypingBuilder.swift index 5faea84..0c3c7b0 100644 --- a/Sources/RTMAPI/Events/UserTypingBuilder.swift +++ b/Sources/RTMAPI/Events/UserTypingBuilder.swift @@ -1,6 +1,6 @@ // // UserTypingBuilder.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,11 +9,12 @@ import Models import Jay -internal struct UserTypingBuilder: RTMAPIEventBuilder { +/// Handler for the `user_typing` event +struct UserTypingBuilder: RTMAPIEventBuilder { static var eventType: String { return "user_typing" } - static func make(json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { - guard self.canMake(json: json) else { throw RTMAPIEventBuilderError.InvalidBuilder } + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent { + guard self.canMake(fromJson: json) else { throw RTMAPIEventBuilderError.invalidBuilder(builder: self) } let builder = builderFactory(json: json) return .user_typing( diff --git a/Sources/RTMAPI/RTMAPI+Events.swift b/Sources/RTMAPI/RTMAPI+Events.swift index 5f4fa50..c41898a 100644 --- a/Sources/RTMAPI/RTMAPI+Events.swift +++ b/Sources/RTMAPI/RTMAPI+Events.swift @@ -1,6 +1,6 @@ // // RTMAPI+Events.swift -// Slack +// Chameleon // // Created by Ian Keen on 20/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -9,6 +9,15 @@ import Models import Jay +//TODO: have a conversation regarding these cases - i.e. `user_typing` vs userTyping +// the former is a 1:1 match for the api, it arguably easier to read +// however it breaks consistency with the rest of the frameworks +// +// the latter is in line with naming conventions +// +// am I just being lazy? :P (I think I am) + +/// Defines the events available from the realtime messaging api public enum RTMAPIEvent { case error(code: Int, message: String) case pong(response: JSON) //TODO: does this need a struct model? diff --git a/Sources/RTMAPI/RTMAPI.swift b/Sources/RTMAPI/RTMAPI.swift index 7db820c..97d591e 100644 --- a/Sources/RTMAPI/RTMAPI.swift +++ b/Sources/RTMAPI/RTMAPI.swift @@ -1,6 +1,6 @@ // // RTMAPI.swift -// Slack +// Chameleon // // Created by Ian Keen on 19/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -13,11 +13,7 @@ import Common import Strand import Jay -public enum RTMAPIError: ErrorProtocol { - case InvalidResponse(String) - case UnknownError(String?) -} - +/// Provides access to the Slack realtime messaging api public final class RTMAPI { //MARK: - Typealiases public typealias SlackModelClosure = () -> (users: [User], channels: [Channel], groups: [Group], ims: [IM]) @@ -28,26 +24,54 @@ public final class RTMAPI { private var pingPongTimer: Strand? //MARK: - Public Events + /// Closure that is called when a websocket connection is made public var onConnected: (() -> Void)? + + /// Closure that is called when a websocket connection is closed with an error when applicable public var onDisconnected: ((error: ErrorProtocol?) -> Void)? + + /// Closure that is called when an error occurs public var onError: ((error: ErrorProtocol) -> Void)? + + /// Closure that is fired when a realtime messaging event occurs public var onEvent: ((event: RTMAPIEvent) -> Void)? //MARK: - Public Properties + /// A closure that needs to be set before the rtmapi can correctly serialise and build responses. public var slackModels: SlackModelClosure? //MARK: - Lifecycle + /** + Create a new `RTMAPI` instance. + + - parameter websocket: A `WebSocketService` that will be used for the websocket connection + - returns: New `RTMAPI` instance. + */ public init(websocket: WebSocketService) { self.websocket = websocket self.bindToSocketEvents() } //MARK: - Public + /** + Attempt a connection to a slack websocket url. + + - parameter url: The url to attempt a connection to + - parameter pingPongInterval: The number of seconds between sending each ping + - throws: A `WebSocketServiceError` with failure details + */ public func connect(url: String, pingPongInterval: NSTimeInterval) throws { self.pingPongInterval = pingPongInterval try self.websocket.connect(url: url) } - public func disconnect(error: ErrorProtocol? = nil) { + + /** + Disconnect the websocket. + */ + public func disconnect() { + self.disconnect(error: nil) + } + private func disconnect(error: ErrorProtocol? = nil) { self.websocket.disconnect() self.onDisconnected?(error: error) } @@ -117,8 +141,8 @@ extension RTMAPI { do { let json = try Jay().typesafeJsonFromData(Array(text.utf8)) - let eventBuilder = try RTMAPIEvent.builder(json: json) - let event = try eventBuilder.make(json: json, builderFactory: self.builder) + let eventBuilder = try RTMAPIEvent.makeEventBuilder(withJson: json) + let event = try eventBuilder.make(withJson: json, builderFactory: self.makeBuilder) if case .hello = event { self.startPingPong() } @@ -139,12 +163,12 @@ extension RTMAPI { //MARK: - Helpers extension RTMAPI { - private func builder(data: JSON) -> SlackModelBuilder { + private func makeBuilder(withJson json: JSON) -> SlackModelBuilder { guard let slackModels = self.slackModels else { fatalError("Please set `slackModels`") } let models = slackModels() return SlackModelBuilder( - json: data, + json: json, users: models.users, channels: models.channels, groups: models.groups, @@ -152,3 +176,12 @@ extension RTMAPI { ) } } + +//MARK: - Errors +extension RTMAPI { + /// Describes a range of errors that can occur when attempting to use the the realtime messaging api + public enum Error: ErrorProtocol { + /// The response was invalid or the data was unexpected + case invalidResponse(json: JSON) + } +} diff --git a/Sources/RTMAPI/RTMAPIEvent+Builders.swift b/Sources/RTMAPI/RTMAPIEvent+Builders.swift new file mode 100644 index 0000000..70fed59 --- /dev/null +++ b/Sources/RTMAPI/RTMAPIEvent+Builders.swift @@ -0,0 +1,100 @@ +// +// RTMAPIEvent+Builders.swift +// Chameleon +// +// Created by Ian Keen on 20/05/2016. +// Copyright © 2016 Mustard. All rights reserved. +// + +import Models +import Jay + +//MARK: - Protocol +/// An abstraction representing an object capable of building a realtime messaging api event +protocol RTMAPIEventBuilder { + /// The name of the event `type` this object builds + static var eventType: String { get } + + /** + Defines if this object is capable of creating a `RTMAPIEvent` from the provided `JSON` + + - parameter json: The `JSON` to handle + - returns: If the object can build a `RTMAPIEvent` `true`, otherwise `false` + */ + static func canMake(fromJson json: JSON) -> Bool + + /** + Creates a `RTMAPIEvent` from the provided `JSON` + + - parameter json: The `JSON` used to build the `RTMAPIEvent` + - parameter builderFactory: A function that can be called to create a `SlackModelBuilder` to obtain model objects needed for the event + - throws: A `RTMAPIEventBuilderError` with failure details + - returns: A new `RTMAPIEvent` instance + */ + static func make(withJson json: JSON, builderFactory: (json: JSON) -> SlackModelBuilder) throws -> RTMAPIEvent +} + +//MARK: - Default Implementation +extension RTMAPIEventBuilder { + static func canMake(fromJson json: JSON) -> Bool { + guard let event = json["type"]?.string else { return false } + return (event == self.eventType) + } +} + +//MARK: - Errors +/// Describes a range of errors that can occur when attempting to build models from `JSON` +enum RTMAPIEventBuilderError: ErrorProtocol { + /// No builder for the provided type exists + case noAvailableBuilder(type: String) + + /// The builder in not capable of handling the provided `JSON` + case invalidBuilder(builder: RTMAPIEventBuilder.Type) + + /// The response was invalid or the data was unexpected + case invalidResponse(json: JSON) +} + +//MARK: - Helpers +extension RTMAPIEvent { + /** + Finds a `RTMAPIEventBuilder` that can be used to create a `RTMAPIEvent` from the provided `JSON` + + - parameter json: The `JSON` representing the event + - throws: A `RTMAPIEventBuilderError` with failure details + - returns: A `RTMAPIEventBuilder` to build the event + */ + static func makeEventBuilder(withJson json: JSON) throws -> RTMAPIEventBuilder.Type { + + //Add builders here: + // + //The idea here is to break out the 'building' of all the slack events + //in an attempt to manage their creation a little easier + //rather than a single `init(json:)` on `RTMAPIEvent` with a ton of + //if/else clauses depending on the `type` of event + // + + let builders: [String: RTMAPIEventBuilder.Type] = [ + ErrorBuilder.eventType: ErrorBuilder.self, + PingPongBuilder.eventType: PingPongBuilder.self, + ReconnectURLBuilder.eventType: ReconnectURLBuilder.self, + PresenceChangeBuilder.eventType: PresenceChangeBuilder.self, + HelloBuilder.eventType: HelloBuilder.self, + UserTypingBuilder.eventType: UserTypingBuilder.self, + MessageBuilder.eventType: MessageBuilder.self, + ReactionAddedBuilder.eventType: ReactionAddedBuilder.self, + ReactionRemovedBuilder.eventType: ReactionRemovedBuilder.self, + UserChangeBuilder.eventType: UserChangeBuilder.self, + ] + + guard + let type = json["type"]?.string, + let builder = builders[type] + else { + print(json) //TODO remove once all builders are built + throw RTMAPIEventBuilderError.noAvailableBuilder(type: json["type"]?.string ?? "no type provided") + } + + return builder + } +} diff --git a/Sources/Services/HTTP/HTTPProvider.swift b/Sources/Services/HTTP/HTTPProvider.swift index 2511f2e..46dc856 100644 --- a/Sources/Services/HTTP/HTTPProvider.swift +++ b/Sources/Services/HTTP/HTTPProvider.swift @@ -1,6 +1,6 @@ // // HTTPProvider.swift -// Slack +// Chameleon // // Created by Ian Keen on 31/01/2016. // Copyright © 2016 HitchPlanet. All rights reserved. @@ -21,7 +21,8 @@ final public class HTTPProvider: HTTPService { // (╯°□°)╯︵ ┻━┻ //On Heroku scheme was coming through as Optional even though the API says String let urlScheme: String? = request.url.scheme - guard let scheme = urlScheme, let host = request.url.host else { throw HTTPServiceError.invalidURL } + guard let scheme = urlScheme, let host = request.url.host + else { throw HTTPServiceError.invalidURL(url: request.url.absoluteString) } let response: Response diff --git a/Sources/Services/HTTP/HTTPRequest.swift b/Sources/Services/HTTP/HTTPRequest.swift index f57faea..3731bda 100644 --- a/Sources/Services/HTTP/HTTPRequest.swift +++ b/Sources/Services/HTTP/HTTPRequest.swift @@ -1,6 +1,6 @@ // // HTTPRequest.swift -// Slack +// Chameleon // // Created by Ian Keen on 26/09/2015. // Copyright © 2015 Mustard. All rights reserved. diff --git a/Sources/Services/HTTP/HTTPService.swift b/Sources/Services/HTTP/HTTPService.swift index f2dc0c9..a788078 100644 --- a/Sources/Services/HTTP/HTTPService.swift +++ b/Sources/Services/HTTP/HTTPService.swift @@ -1,6 +1,6 @@ // // HTTPService.swift -// Slack +// Chameleon // // Created by Ian Keen on 26/09/2015. // Copyright © 2015 Mustard. All rights reserved. @@ -23,7 +23,7 @@ public protocol HTTPService: class { /// Describes a range of errors that can occur when attempting to use the service public enum HTTPServiceError: ErrorProtocol, Equatable { /// The provided URL was invalid - case invalidURL + case invalidURL(url: String) /// Something was wrong with the request data case clientError(code: Int, data: JSON?) @@ -34,7 +34,7 @@ public enum HTTPServiceError: ErrorProtocol, Equatable { /// The response was invalid or the data was unexpected case invalidResponse(data: Any) - /// Something went wrong with an internal dependency + /// Something went wrong with an dependency case internalError(error: ErrorProtocol) } diff --git a/Sources/Services/WebSocket/WebSocketProvider.swift b/Sources/Services/WebSocket/WebSocketProvider.swift index 8f7fd55..e882300 100644 --- a/Sources/Services/WebSocket/WebSocketProvider.swift +++ b/Sources/Services/WebSocket/WebSocketProvider.swift @@ -1,6 +1,6 @@ // // WebSocketProvider.swift -// Slack +// Chameleon // // Created by Ian Keen on 3/06/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/Services/WebSocket/WebSocketService.swift b/Sources/Services/WebSocket/WebSocketService.swift index 95c846e..cb4bba5 100644 --- a/Sources/Services/WebSocket/WebSocketService.swift +++ b/Sources/Services/WebSocket/WebSocketService.swift @@ -1,6 +1,6 @@ // // WebSocketService.swift -// Slack +// Chameleon // // Created by Ian Keen on 10/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -11,19 +11,19 @@ import Jay /// An abstraction representing an object capable of synchronous web sockets public protocol WebSocketService: class { - /// Closure that is fired when a connection is opened + /// Closure that is called when a connection is opened var onConnect: (() -> Void)? { get set } - /// Closure that is fired when a connection is closed with an error when applicable + /// Closure that is called when a connection is closed with an error when applicable var onDisconnect: ((ErrorProtocol?) -> Void)? { get set } - /// Closure that is fired when receiving text data + /// Closure that is called when receiving text data var onText: ((String) -> Void)? { get set } - /// Closure that is fired when receiving byte data + /// Closure that is called when receiving byte data var onData: ((NSData) -> Void)? { get set } - /// Closure that is fired when an error occurs + /// Closure that is called when an error occurs var onError: ((ErrorProtocol) -> Void)? { get set } /** @@ -66,6 +66,6 @@ public enum WebSocketServiceError: ErrorProtocol { /// The provided URL was invalid case invalidURL(url: String) - /// Something went wrong with an internal dependency + /// Something went wrong with an dependency case internalError(error: ErrorProtocol) } diff --git a/Sources/WebAPI/Methods/ChatPostMessage+Options.swift b/Sources/WebAPI/Methods/ChatPostMessage+Options.swift index f538791..f8397c0 100644 --- a/Sources/WebAPI/Methods/ChatPostMessage+Options.swift +++ b/Sources/WebAPI/Methods/ChatPostMessage+Options.swift @@ -1,6 +1,6 @@ // // ChatPostMessage+Options.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/WebAPI/Methods/ChatPostMessage.swift b/Sources/WebAPI/Methods/ChatPostMessage.swift index 91f076f..7594948 100644 --- a/Sources/WebAPI/Methods/ChatPostMessage.swift +++ b/Sources/WebAPI/Methods/ChatPostMessage.swift @@ -1,6 +1,6 @@ // // ChatPostMessage.swift -// Slack +// Chameleon // // Created by Ian Keen on 21/05/2016. // Copyright © 2016 Mustard. All rights reserved. diff --git a/Sources/WebAPI/Methods/EmojiList.swift b/Sources/WebAPI/Methods/EmojiList.swift index fc2c3e5..42eb3cd 100644 --- a/Sources/WebAPI/Methods/EmojiList.swift +++ b/Sources/WebAPI/Methods/EmojiList.swift @@ -1,6 +1,6 @@ // // EmojiList.swift -// Slack +// Chameleon // // Created by Ian Keen on 6/06/2016. // diff --git a/Sources/WebAPI/Methods/RTMStart.swift b/Sources/WebAPI/Methods/RTMStart.swift index a1be469..2843abf 100644 --- a/Sources/WebAPI/Methods/RTMStart.swift +++ b/Sources/WebAPI/Methods/RTMStart.swift @@ -1,6 +1,6 @@ // // RTMStart.swift -// Slack +// Chameleon // // Created by Ian Keen on 19/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -51,7 +51,7 @@ public struct RTMStart: WebAPIMethod { ) } public func handle(json: JSON, slackModels: SlackModels) throws -> SuccessParameters { - guard let socketUrl = json["url"]?.string else { throw WebAPI.Error.invalidResponse(data: json) } + guard let socketUrl = json["url"]?.string else { throw WebAPI.Error.invalidResponse(json: json) } _ = try Strand { guard @@ -61,7 +61,7 @@ public struct RTMStart: WebAPIMethod { let channelJson = json["channels"]?.array, let groupJson = json["groups"]?.array, let imJson = json["ims"]?.array - else { return self.dataReady(serializedData: { throw WebAPI.Error.invalidResponse(data: json) }) } + else { return self.dataReady(serializedData: { throw WebAPI.Error.invalidResponse(json: json) }) } do { print("Deserializing \(userJson.count) Users") diff --git a/Sources/WebAPI/WebAPI.swift b/Sources/WebAPI/WebAPI.swift index 3ba9c7d..be41362 100644 --- a/Sources/WebAPI/WebAPI.swift +++ b/Sources/WebAPI/WebAPI.swift @@ -1,6 +1,6 @@ // // WebAPI.swift -// Slack +// Chameleon // // Created by Ian Keen on 19/05/2016. // Copyright © 2016 Mustard. All rights reserved. @@ -41,7 +41,7 @@ public final class WebAPI { //MARK: - Lifecycle /** - Create a new `WebAPI` instance.s + Create a new `WebAPI` instance. - parameter token: The token to use in authenticated webapi requests - parameter http: The `HTTPService` to use when making requests @@ -72,8 +72,10 @@ public final class WebAPI { return try method.handle(json: json, slackModels: slackModels()) } - - //MARK: - Private Helpers +} + +//MARK: - Helpers +extension WebAPI { private func request(for method: Method) -> HTTPRequest { guard method.requiresAuthentication else { return method.networkRequest } @@ -94,6 +96,7 @@ public final class WebAPI { } } +//MARK: - Errors extension WebAPI { /// Describes a range of errors that can occur when attempting to use the the webapi public enum Error: ErrorProtocol { @@ -101,6 +104,6 @@ extension WebAPI { case apiError(reason: String) /// The response was invalid or the data was unexpected - case invalidResponse(data: Any) + case invalidResponse(json: JSON) } } diff --git a/Sources/WebAPI/WebAPIMethod.swift b/Sources/WebAPI/WebAPIMethod.swift index c68fe9d..f15aa65 100644 --- a/Sources/WebAPI/WebAPIMethod.swift +++ b/Sources/WebAPI/WebAPIMethod.swift @@ -1,6 +1,6 @@ // // WebAPIMethod.swift -// Slack +// Chameleon // // Created by Ian Keen on 19/05/2016. // Copyright © 2016 Mustard. All rights reserved.