From 1c476c77ad178c5845bceec30cd21b2cce2c6ea2 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Fri, 11 Nov 2016 14:59:43 -0500 Subject: [PATCH 01/10] Lowercase enums --- .../Sources/Client+EventDispatching.swift | 120 +++++------ SlackKit/Sources/Event.swift | 188 +++++++++--------- 2 files changed, 154 insertions(+), 154 deletions(-) diff --git a/SlackKit/Sources/Client+EventDispatching.swift b/SlackKit/Sources/Client+EventDispatching.swift index 085a045..6e21821 100644 --- a/SlackKit/Sources/Client+EventDispatching.swift +++ b/SlackKit/Sources/Client+EventDispatching.swift @@ -29,132 +29,132 @@ internal extension Client { return } switch type { - case .Hello: + case .hello: connected = true connectionEventsDelegate?.connected(self) - case .Ok: + case .ok: messageSent(event) - case .Message: + case .message: if (event.subtype != nil) { messageDispatcher(event) } else { messageReceived(event) } - case .UserTyping: + case .userTyping: userTyping(event) - case .ChannelMarked, .IMMarked, .GroupMarked: + case .channelMarked, .imMarked, .groupMarked: channelMarked(event) - case .ChannelCreated, .IMCreated: + case .channelCreated, .imCreated: channelCreated(event) - case .ChannelJoined, .GroupJoined: + case .channelJoined, .groupJoined: channelJoined(event) - case .ChannelLeft, .GroupLeft: + case .channelLeft, .groupLeft: channelLeft(event) - case .ChannelDeleted: + case .channelDeleted: channelDeleted(event) - case .ChannelRenamed, .GroupRename: + case .channelRenamed, .groupRename: channelRenamed(event) - case .ChannelArchive, .GroupArchive: + case .channelArchive, .groupArchive: channelArchived(event, archived: true) - case .ChannelUnarchive, .GroupUnarchive: + case .channelUnarchive, .groupUnarchive: channelArchived(event, archived: false) - case .ChannelHistoryChanged, .IMHistoryChanged, .GroupHistoryChanged: + case .channelHistoryChanged, .imHistoryChanged, .groupHistoryChanged: channelHistoryChanged(event) - case .DNDUpdated: + case .dndUpdated: doNotDisturbUpdated(event) - case .DNDUpatedUser: + case .dndUpatedUser: doNotDisturbUserUpdated(event) - case .IMOpen, .GroupOpen: + case .imOpen, .groupOpen: open(event, open: true) - case .IMClose, .GroupClose: + case .imClose, .groupClose: open(event, open: false) - case .FileCreated: + case .fileCreated: processFile(event) - case .FileShared: + case .fileShared: processFile(event) - case .FileUnshared: + case .fileUnshared: processFile(event) - case .FilePublic: + case .filePublic: processFile(event) - case .FilePrivate: + case .filePrivate: filePrivate(event) - case .FileChanged: + case .fileChanged: processFile(event) - case .FileDeleted: + case .fileDeleted: deleteFile(event) - case .FileCommentAdded: + case .fileCommentAdded: fileCommentAdded(event) - case .FileCommentEdited: + case .fileCommentEdited: fileCommentEdited(event) - case .FileCommentDeleted: + case .fileCommentDeleted: fileCommentDeleted(event) - case .PinAdded: + case .pinAdded: pinAdded(event) - case .PinRemoved: + case .pinRemoved: pinRemoved(event) - case .Pong: + case .pong: pong(event) - case .PresenceChange: + case .presenceChange: presenceChange(event) - case .ManualPresenceChange: + case .manualPresenceChange: manualPresenceChange(event) - case .PrefChange: + case .prefChange: changePreference(event) - case .UserChange: + case .userChange: userChange(event) - case .TeamJoin: + case .teamJoin: teamJoin(event) - case .StarAdded: + case .starAdded: itemStarred(event, star: true) - case .StarRemoved: + case .starRemoved: itemStarred(event, star: false) - case .ReactionAdded: + case .reactionAdded: addedReaction(event) - case .ReactionRemoved: + case .reactionRemoved: removedReaction(event) - case .EmojiChanged: + case .emojiChanged: emojiChanged(event) - case .CommandsChanged: + case .commandsChanged: // This functionality is only used by our web client. // The other APIs required to support slash command metadata are currently unstable. // Until they are released other clients should ignore this event. break - case .TeamPlanChange: + case .teamPlanChange: teamPlanChange(event) - case .TeamPrefChange: + case .teamPrefChange: teamPreferenceChange(event) - case .TeamRename: + case .teamRename: teamNameChange(event) - case .TeamDomainChange: + case .teamDomainChange: teamDomainChange(event) - case .EmailDomainChange: + case .emailDomainChange: emailDomainChange(event) - case .TeamProfileChange: + case .teamProfileChange: teamProfileChange(event) - case .TeamProfileDelete: + case .teamProfileDelete: teamProfileDeleted(event) - case .TeamProfileReorder: + case .teamProfileReorder: teamProfileReordered(event) - case .BotAdded: + case .botAdded: bot(event) - case .BotChanged: + case .botChanged: bot(event) - case .AccountsChanged: + case .accountsChanged: // The accounts_changed event is used by our web client to maintain a list of logged-in accounts. // Other clients should ignore this event. break - case .TeamMigrationStarted: + case .teamMigrationStarted: connect(options: options ?? ClientOptions()) - case .ReconnectURL: + case .reconnectURL: // The reconnect_url event is currently unsupported and experimental. break - case .SubteamCreated, .SubteamUpdated: + case .subteamCreated, .subteamUpdated: subteam(event) - case .SubteamSelfAdded: + case .subteamSelfAdded: subteamAddedSelf(event) - case.SubteamSelfRemoved: + case .subteamSelfRemoved: subteamRemovedSelf(event) - case .Error: + case .error: print("Error: \(event)") } } @@ -164,9 +164,9 @@ internal extension Client { return } switch subtype { - case .MessageChanged: + case .messageChanged: messageChanged(event) - case .MessageDeleted: + case .messageDeleted: messageDeleted(event) default: messageReceived(event) diff --git a/SlackKit/Sources/Event.swift b/SlackKit/Sources/Event.swift index d617218..60eb37c 100644 --- a/SlackKit/Sources/Event.swift +++ b/SlackKit/Sources/Event.swift @@ -23,104 +23,104 @@ internal enum EventType: String { - case Hello = "hello" - case Message = "message" - case UserTyping = "user_typing" - case ChannelMarked = "channel_marked" - case ChannelCreated = "channel_created" - case ChannelJoined = "channel_joined" - case ChannelLeft = "channel_left" - case ChannelDeleted = "channel_deleted" - case ChannelRenamed = "channel_rename" - case ChannelArchive = "channel_archive" - case ChannelUnarchive = "channel_unarchive" - case ChannelHistoryChanged = "channel_history_changed" - case DNDUpdated = "dnd_updated" - case DNDUpatedUser = "dnd_updated_user" - case IMCreated = "im_created" - case IMOpen = "im_open" - case IMClose = "im_close" - case IMMarked = "im_marked" - case IMHistoryChanged = "im_history_changed" - case GroupJoined = "group_joined" - case GroupLeft = "group_left" - case GroupOpen = "group_open" - case GroupClose = "group_close" - case GroupArchive = "group_archive" - case GroupUnarchive = "group_unarchive" - case GroupRename = "group_rename" - case GroupMarked = "group_marked" - case GroupHistoryChanged = "group_history_changed" - case FileCreated = "file_created" - case FileShared = "file_shared" - case FileUnshared = "file_unshared" - case FilePublic = "file_public" - case FilePrivate = "file_private" - case FileChanged = "file_change" - case FileDeleted = "file_deleted" - case FileCommentAdded = "file_comment_added" - case FileCommentEdited = "file_comment_edited" - case FileCommentDeleted = "file_comment_deleted" - case PinAdded = "pin_added" - case PinRemoved = "pin_removed" - case Pong = "pong" - case PresenceChange = "presence_change" - case ManualPresenceChange = "manual_presence_change" - case PrefChange = "pref_change" - case UserChange = "user_change" - case TeamJoin = "team_join" - case StarAdded = "star_added" - case StarRemoved = "star_removed" - case ReactionAdded = "reaction_added" - case ReactionRemoved = "reaction_removed" - case EmojiChanged = "emoji_changed" - case CommandsChanged = "commands_changed" - case TeamPlanChange = "team_plan_change" - case TeamPrefChange = "team_pref_change" - case TeamRename = "team_rename" - case TeamDomainChange = "team_domain_change" - case EmailDomainChange = "email_domain_change" - case TeamProfileChange = "team_profile_change" - case TeamProfileDelete = "team_profile_delete" - case TeamProfileReorder = "team_profile_reorder" - case BotAdded = "bot_added" - case BotChanged = "bot_changed" - case AccountsChanged = "accounts_changed" - case TeamMigrationStarted = "team_migration_started" - case ReconnectURL = "reconnect_url" - case SubteamCreated = "subteam_created" - case SubteamUpdated = "subteam_updated" - case SubteamSelfAdded = "subteam_self_added" - case SubteamSelfRemoved = "subteam_self_removed" - case Ok = "ok" - case Error = "error" + case hello = "hello" + case message = "message" + case userTyping = "user_typing" + case channelMarked = "channel_marked" + case channelCreated = "channel_created" + case channelJoined = "channel_joined" + case channelLeft = "channel_left" + case channelDeleted = "channel_deleted" + case channelRenamed = "channel_rename" + case channelArchive = "channel_archive" + case channelUnarchive = "channel_unarchive" + case channelHistoryChanged = "channel_history_changed" + case dndUpdated = "dnd_updated" + case dndUpatedUser = "dnd_updated_user" + case imCreated = "im_created" + case imOpen = "im_open" + case imClose = "im_close" + case imMarked = "im_marked" + case imHistoryChanged = "im_history_changed" + case groupJoined = "group_joined" + case groupLeft = "group_left" + case groupOpen = "group_open" + case groupClose = "group_close" + case groupArchive = "group_archive" + case groupUnarchive = "group_unarchive" + case groupRename = "group_rename" + case groupMarked = "group_marked" + case groupHistoryChanged = "group_history_changed" + case fileCreated = "file_created" + case fileShared = "file_shared" + case fileUnshared = "file_unshared" + case filePublic = "file_public" + case filePrivate = "file_private" + case fileChanged = "file_change" + case fileDeleted = "file_deleted" + case fileCommentAdded = "file_comment_added" + case fileCommentEdited = "file_comment_edited" + case fileCommentDeleted = "file_comment_deleted" + case pinAdded = "pin_added" + case pinRemoved = "pin_removed" + case pong = "pong" + case presenceChange = "presence_change" + case manualPresenceChange = "manual_presence_change" + case prefChange = "pref_change" + case userChange = "user_change" + case teamJoin = "team_join" + case starAdded = "star_added" + case starRemoved = "star_removed" + case reactionAdded = "reaction_added" + case reactionRemoved = "reaction_removed" + case emojiChanged = "emoji_changed" + case commandsChanged = "commands_changed" + case teamPlanChange = "team_plan_change" + case teamPrefChange = "team_pref_change" + case teamRename = "team_rename" + case teamDomainChange = "team_domain_change" + case emailDomainChange = "email_domain_change" + case teamProfileChange = "team_profile_change" + case teamProfileDelete = "team_profile_delete" + case teamProfileReorder = "team_profile_reorder" + case botAdded = "bot_added" + case botChanged = "bot_changed" + case accountsChanged = "accounts_changed" + case teamMigrationStarted = "team_migration_started" + case reconnectURL = "reconnect_url" + case subteamCreated = "subteam_created" + case subteamUpdated = "subteam_updated" + case subteamSelfAdded = "subteam_self_added" + case subteamSelfRemoved = "subteam_self_removed" + case ok = "ok" + case error = "error" } internal enum MessageSubtype: String { - case BotMessage = "bot_message" - case MeMessage = "me_message" - case MessageChanged = "message_changed" - case MessageDeleted = "message_deleted" - case ChannelJoin = "channel_join" - case ChannelLeave = "channel_leave" - case ChannelTopic = "channel_topic" - case ChannelPurpose = "channel_purpose" - case ChannelName = "channel_name" - case ChannelArchive = "channel_archive" - case ChannelUnarchive = "channel_unarchive" - case GroupJoin = "group_join" - case GroupLeave = "group_leave" - case GroupTopic = "group_topic" - case GroupPurpose = "group_purpose" - case GroupName = "group_name" - case GroupArchive = "group_archive" - case GroupUnarchive = "group_unarchive" - case FileShare = "file_share" - case FileComment = "file_comment" - case FileMention = "file_mention" - case PinnedItem = "pinned_item" - case UnpinnedItem = "unpinned_item" + case botMessage = "bot_message" + case meMessage = "me_message" + case messageChanged = "message_changed" + case messageDeleted = "message_deleted" + case channelJoin = "channel_join" + case channelLeave = "channel_leave" + case channelTopic = "channel_topic" + case channelPurpose = "channel_purpose" + case channelName = "channel_name" + case channelArchive = "channel_archive" + case channelUnarchive = "channel_unarchive" + case groupJoin = "group_join" + case groupLeave = "group_leave" + case groupTopic = "group_topic" + case groupPurpose = "group_purpose" + case groupName = "group_name" + case groupArchive = "group_archive" + case groupUnarchive = "group_unarchive" + case fileShare = "file_share" + case fileComment = "file_comment" + case fileMention = "file_mention" + case pinnedItem = "pinned_item" + case unpinnedItem = "unpinned_item" } internal struct Event { From 992f94e870f2b4e0956af7112c22e7630043db64 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 13 Nov 2016 15:32:50 -0500 Subject: [PATCH 02/10] Lowercase error enums --- SlackKit/Sources/SlackError.swift | 189 +++++++++++++++--------------- 1 file changed, 94 insertions(+), 95 deletions(-) diff --git a/SlackKit/Sources/SlackError.swift b/SlackKit/Sources/SlackError.swift index 26a6604..3ba038e 100644 --- a/SlackKit/Sources/SlackError.swift +++ b/SlackKit/Sources/SlackError.swift @@ -22,101 +22,100 @@ // THE SOFTWARE. public enum SlackError: String, Error { - - case AccountInactive = "account_inactive" - case AlreadyArchived = "already_archived" - case AlreadyInChannel = "already_in_channel" - case AlreadyPinned = "already_pinned" - case AlreadyReacted = "already_reacted" - case AlreadyStarred = "already_starred" - case BadClientSecret = "bad_client_secret" - case BadRedirectURI = "bad_redirect_uri" - case BadTimeStamp = "bad_timestamp" - case CantArchiveGeneral = "cant_archive_general" - case CantDelete = "cant_delete" - case CantDeleteFile = "cant_delete_file" - case CantDeleteMessage = "cant_delete_message" - case CantInvite = "cant_invite" - case CantInviteSelf = "cant_invite_self" - case CantKickFromGeneral = "cant_kick_from_general" - case CantKickFromLastChannel = "cant_kick_from_last_channel" - case CantKickSelf = "cant_kick_self" - case CantLeaveGeneral = "cant_leave_general" - case CantLeaveLastChannel = "cant_leave_last_channel" - case CantUpdateMessage = "cant_update_message" - case ChannelNotFound = "channel_not_found" - case ComplianceExportsPreventDeletion = "compliance_exports_prevent_deletion" - case EditWindowClosed = "edit_window_closed" - case FileCommentNotFound = "file_comment_not_found" - case FileDeleted = "file_deleted" - case FileNotFound = "file_not_found" - case FileNotShared = "file_not_shared" - case GroupContainsOthers = "group_contains_others" - case InvalidArgName = "invalid_arg_name" - case InvalidArrayArg = "invalid_array_arg" - case InvalidAuth = "invalid_auth" - case InvalidChannel = "invalid_channel" - case InvalidCharSet = "invalid_charset" - case InvalidClientID = "invalid_client_id" - case InvalidCode = "invalid_code" - case InvalidFormData = "invalid_form_data" - case InvalidName = "invalid_name" - case InvalidPostType = "invalid_post_type" - case InvalidPresence = "invalid_presence" - case InvalidTS = "invalid_timestamp" - case InvalidTSLatest = "invalid_ts_latest" - case InvalidTSOldest = "invalid_ts_oldest" - case IsArchived = "is_archived" - case LastMember = "last_member" - case LastRAChannel = "last_ra_channel" - case MessageNotFound = "message_not_found" - case MessageTooLong = "msg_too_long" - case MigrationInProgress = "migration_in_progress" - case MissingDuration = "missing_duration" - case MissingPostType = "missing_post_type" - case MissingScope = "missing_scope" - case NameTaken = "name_taken" - case NoChannel = "no_channel" - case NoComment = "no_comment" - case NoItemSpecified = "no_item_specified" - case NoReaction = "no_reaction" - case NoText = "no_text" - case NotArchived = "not_archived" - case NotAuthed = "not_authed" - case NotEnoughUsers = "not_enough_users" - case NotInChannel = "not_in_channel" - case NotInGroup = "not_in_group" - case NotPinned = "not_pinned" - case NotStarred = "not_starred" - case OverPaginationLimit = "over_pagination_limit" - case PaidOnly = "paid_only" - case PermissionDenied = "perimssion_denied" - case PostingToGeneralChannelDenied = "posting_to_general_channel_denied" - case RateLimited = "rate_limited" - case RequestTimeout = "request_timeout" - case RestrictedAction = "restricted_action" - case SnoozeEndFailed = "snooze_end_failed" - case SnoozeFailed = "snooze_failed" - case SnoozeNotActive = "snooze_not_active" - case TooLong = "too_long" - case TooManyEmoji = "too_many_emoji" - case TooManyReactions = "too_many_reactions" - case TooManyUsers = "too_many_users" - case UnknownError - case UnknownType = "unknown_type" - case UserDisabled = "user_disabled" - case UserDoesNotOwnChannel = "user_does_not_own_channel" - case UserIsBot = "user_is_bot" - case UserIsRestricted = "user_is_restricted" - case UserIsUltraRestricted = "user_is_ultra_restricted" - case UserListNotSupplied = "user_list_not_supplied" - case UserNotFound = "user_not_found" - case UserNotVisible = "user_not_visible" + case accountInactive = "account_inactive" + case alreadyArchived = "already_archived" + case alreadyInChannel = "already_in_channel" + case alreadyPinned = "already_pinned" + case alreadyReacted = "already_reacted" + case alreadyStarred = "already_starred" + case badClientSecret = "bad_client_secret" + case badRedirectURI = "bad_redirect_uri" + case badTimeStamp = "bad_timestamp" + case cantArchiveGeneral = "cant_archive_general" + case cantDelete = "cant_delete" + case cantDeleteFile = "cant_delete_file" + case cantDeleteMessage = "cant_delete_message" + case cantInvite = "cant_invite" + case cantInviteSelf = "cant_invite_self" + case cantKickFromGeneral = "cant_kick_from_general" + case cantKickFromLastChannel = "cant_kick_from_last_channel" + case cantKickSelf = "cant_kick_self" + case cantLeaveGeneral = "cant_leave_general" + case cantLeaveLastChannel = "cant_leave_last_channel" + case cantUpdateMessage = "cant_update_message" + case channelNotFound = "channel_not_found" + case complianceExportsPreventDeletion = "compliance_exports_prevent_deletion" + case editWindowClosed = "edit_window_closed" + case fileCommentNotFound = "file_comment_not_found" + case fileDeleted = "file_deleted" + case fileNotFound = "file_not_found" + case fileNotShared = "file_not_shared" + case groupContainsOthers = "group_contains_others" + case invalidArgName = "invalid_arg_name" + case invalidArrayArg = "invalid_array_arg" + case invalidAuth = "invalid_auth" + case invalidChannel = "invalid_channel" + case invalidCharSet = "invalid_charset" + case invalidClientID = "invalid_client_id" + case invalidCode = "invalid_code" + case invalidFormData = "invalid_form_data" + case invalidName = "invalid_name" + case invalidPostType = "invalid_post_type" + case invalidPresence = "invalid_presence" + case invalidTS = "invalid_timestamp" + case invalidTSLatest = "invalid_ts_latest" + case invalidTSOldest = "invalid_ts_oldest" + case isArchived = "is_archived" + case lastMember = "last_member" + case lastRAChannel = "last_ra_channel" + case messageNotFound = "message_not_found" + case messageTooLong = "msg_too_long" + case migrationInProgress = "migration_in_progress" + case missingDuration = "missing_duration" + case missingPostType = "missing_post_type" + case missingScope = "missing_scope" + case nameTaken = "name_taken" + case noChannel = "no_channel" + case noComment = "no_comment" + case noItemSpecified = "no_item_specified" + case noReaction = "no_reaction" + case noText = "no_text" + case notArchived = "not_archived" + case notAuthed = "not_authed" + case notEnoughUsers = "not_enough_users" + case notInChannel = "not_in_channel" + case notInGroup = "not_in_group" + case notPinned = "not_pinned" + case notStarred = "not_starred" + case overPaginationLimit = "over_pagination_limit" + case paidOnly = "paid_only" + case permissionDenied = "perimssion_denied" + case postingToGeneralChannelDenied = "posting_to_general_channel_denied" + case rateLimited = "rate_limited" + case requestTimeout = "request_timeout" + case restrictedAction = "restricted_action" + case snoozeEndFailed = "snooze_end_failed" + case snoozeFailed = "snooze_failed" + case snoozeNotActive = "snooze_not_active" + case tooLong = "too_long" + case tooManyEmoji = "too_many_emoji" + case tooManyReactions = "too_many_reactions" + case tooManyUsers = "too_many_users" + case unknownError + case unknownType = "unknown_type" + case userDisabled = "user_disabled" + case userDoesNotOwnChannel = "user_does_not_own_channel" + case userIsBot = "user_is_bot" + case userIsRestricted = "user_is_restricted" + case userIsUltraRestricted = "user_is_ultra_restricted" + case userListNotSupplied = "user_list_not_supplied" + case userNotFound = "user_not_found" + case userNotVisible = "user_not_visible" // Client - case ClientNetworkError - case ClientJSONError - case ClientOAuthError + case clientNetworkError + case clientJSONError + case clientOAuthError // HTTP - case TooManyRequests - case UnknownHTTPError + case tooManyRequests + case unknownHTTPError } From 63a8ae7f08258672d6158418a352c16b9f21521a Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 13 Nov 2016 15:34:27 -0500 Subject: [PATCH 03/10] Lowercase enums --- SlackKit/Sources/NetworkInterface.swift | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/SlackKit/Sources/NetworkInterface.swift b/SlackKit/Sources/NetworkInterface.swift index 0c6f2b6..40b4304 100644 --- a/SlackKit/Sources/NetworkInterface.swift +++ b/SlackKit/Sources/NetworkInterface.swift @@ -36,7 +36,7 @@ internal struct NetworkInterface { requestString += params.requestStringFromParameters } guard let url = URL(string: requestString) else { - errorClosure(SlackError.ClientNetworkError) + errorClosure(SlackError.clientNetworkError) return } let request = URLRequest(url:url) @@ -53,7 +53,7 @@ internal struct NetworkInterface { 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) + errorClosure(SlackError.clientNetworkError) return } var request = URLRequest(url:url) @@ -67,7 +67,7 @@ internal struct NetworkInterface { if internalError == nil { success(true) } else { - errorClosure(SlackError.ClientNetworkError) + errorClosure(SlackError.clientNetworkError) } }.resume() } @@ -78,7 +78,7 @@ internal struct NetworkInterface { requestString = requestString + params.requestStringFromParameters } guard let url = URL(string: requestString) else { - errorClosure(SlackError.ClientNetworkError) + errorClosure(SlackError.clientNetworkError) return } var request = URLRequest(url:url) @@ -113,12 +113,12 @@ internal struct NetworkInterface { private func handleResponse(_ data: Data?, response:URLResponse?, internalError:Error?, successClosure: ([String: Any])->Void, errorClosure: (SlackError)->Void) { guard let data = data, let response = response as? HTTPURLResponse else { - errorClosure(SlackError.ClientNetworkError) + errorClosure(SlackError.clientNetworkError) return } do { guard let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else { - errorClosure(SlackError.ClientJSONError) + errorClosure(SlackError.clientJSONError) return } @@ -128,21 +128,21 @@ internal struct NetworkInterface { successClosure(json) } else { if let errorString = json["error"] as? String { - throw SlackError(rawValue: errorString) ?? .UnknownError + throw SlackError(rawValue: errorString) ?? .unknownError } else { - throw SlackError.UnknownError + throw SlackError.unknownError } } case 429: - throw SlackError.TooManyRequests + throw SlackError.tooManyRequests default: - throw SlackError.ClientNetworkError + throw SlackError.clientNetworkError } } catch let error { if let slackError = error as? SlackError { errorClosure(slackError) } else { - errorClosure(SlackError.UnknownError) + errorClosure(SlackError.unknownError) } } } From 9ebd8182a675ac0ff285585cd492282819e771b0 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 13 Nov 2016 17:26:32 -0500 Subject: [PATCH 04/10] Lowercase enums --- SlackKit/Sources/NetworkInterface.swift | 2 +- SlackKit/Sources/WebAPI.swift | 232 ++++++++++++------------ 2 files changed, 117 insertions(+), 117 deletions(-) diff --git a/SlackKit/Sources/NetworkInterface.swift b/SlackKit/Sources/NetworkInterface.swift index 40b4304..e0eff57 100644 --- a/SlackKit/Sources/NetworkInterface.swift +++ b/SlackKit/Sources/NetworkInterface.swift @@ -73,7 +73,7 @@ internal struct NetworkInterface { } internal func uploadRequest(_ token: String, data: Data, parameters: [String: Any]?, successClosure: @escaping ([String: Any])->Void, errorClosure: @escaping (SlackError)->Void) { - var requestString = "\(apiUrl)\(Endpoint.FilesUpload.rawValue)?token=\(token)" + var requestString = "\(apiUrl)\(Endpoint.filesUpload.rawValue)?token=\(token)" if let params = parameters { requestString = requestString + params.requestStringFromParameters } diff --git a/SlackKit/Sources/WebAPI.swift b/SlackKit/Sources/WebAPI.swift index b58bae4..73898b4 100644 --- a/SlackKit/Sources/WebAPI.swift +++ b/SlackKit/Sources/WebAPI.swift @@ -25,61 +25,61 @@ import Foundation internal enum Endpoint: String { - case APITest = "api.test" - case AuthRevoke = "auth.revoke" - case AuthTest = "auth.test" - case ChannelsHistory = "channels.history" - case ChannelsInfo = "channels.info" - case ChannelsList = "channels.list" - case ChannelsMark = "channels.mark" - case ChannelsSetPurpose = "channels.setPurpose" - case ChannelsSetTopic = "channels.setTopic" - case ChatDelete = "chat.delete" - case ChatPostMessage = "chat.postMessage" - case ChatUpdate = "chat.update" - case DNDInfo = "dnd.info" - case DNDTeamInfo = "dnd.teamInfo" - case EmojiList = "emoji.list" - case FilesCommentsAdd = "files.comments.add" - case FilesCommentsEdit = "files.comments.edit" - case FilesCommentsDelete = "files.comments.delete" - case FilesDelete = "files.delete" - case FilesInfo = "files.info" - case FilesUpload = "files.upload" - case GroupsClose = "groups.close" - case GroupsHistory = "groups.history" - case GroupsInfo = "groups.info" - case GroupsList = "groups.list" - case GroupsMark = "groups.mark" - case GroupsOpen = "groups.open" - case GroupsSetPurpose = "groups.setPurpose" - case GroupsSetTopic = "groups.setTopic" - case IMClose = "im.close" - case IMHistory = "im.history" - case IMList = "im.list" - case IMMark = "im.mark" - case IMOpen = "im.open" - case MPIMClose = "mpim.close" - case MPIMHistory = "mpim.history" - case MPIMList = "mpim.list" - case MPIMMark = "mpim.mark" - case MPIMOpen = "mpim.open" - case OAuthAccess = "oauth.access" - case PinsAdd = "pins.add" - case PinsRemove = "pins.remove" - case ReactionsAdd = "reactions.add" - case ReactionsGet = "reactions.get" - case ReactionsList = "reactions.list" - case ReactionsRemove = "reactions.remove" - case RTMStart = "rtm.start" - case StarsAdd = "stars.add" - case StarsRemove = "stars.remove" - case TeamInfo = "team.info" - case UsersGetPresence = "users.getPresence" - case UsersInfo = "users.info" - case UsersList = "users.list" - case UsersSetActive = "users.setActive" - case UsersSetPresence = "users.setPresence" + case apiTest = "api.test" + case authRevoke = "auth.revoke" + case authTest = "auth.test" + case channelsHistory = "channels.history" + case channelsInfo = "channels.info" + case channelsList = "channels.list" + case channelsMark = "channels.mark" + case channelsSetPurpose = "channels.setPurpose" + case channelsSetTopic = "channels.setTopic" + case chatDelete = "chat.delete" + case chatPostMessage = "chat.postMessage" + case chatUpdate = "chat.update" + case dndInfo = "dnd.info" + case dndTeamInfo = "dnd.teamInfo" + case emojiList = "emoji.list" + case filesCommentsAdd = "files.comments.add" + case filesCommentsEdit = "files.comments.edit" + case filesCommentsDelete = "files.comments.delete" + case filesDelete = "files.delete" + case filesInfo = "files.info" + case filesUpload = "files.upload" + case groupsClose = "groups.close" + case groupsHistory = "groups.history" + case groupsInfo = "groups.info" + case groupsList = "groups.list" + case groupsMark = "groups.mark" + case groupsOpen = "groups.open" + case groupsSetPurpose = "groups.setPurpose" + case groupsSetTopic = "groups.setTopic" + case imClose = "im.close" + case imHistory = "im.history" + case imList = "im.list" + case imMark = "im.mark" + case imOpen = "im.open" + case mpimClose = "mpim.close" + case mpimHistory = "mpim.history" + case mpimList = "mpim.list" + case mpimMark = "mpim.mark" + case mpimOpen = "mpim.open" + case oauthAccess = "oauth.access" + case pinsAdd = "pins.add" + case pinsRemove = "pins.remove" + case reactionsAdd = "reactions.add" + case reactionsGet = "reactions.get" + case reactionsList = "reactions.list" + case reactionsRemove = "reactions.remove" + case rtmStart = "rtm.start" + case starsAdd = "stars.add" + case starsRemove = "stars.remove" + case teamInfo = "team.info" + case usersGetPresence = "users.getPresence" + case usersInfo = "users.info" + case usersList = "users.list" + case usersSetActive = "users.setActive" + case usersSetPresence = "users.setPresence" } public final class WebAPI { @@ -87,24 +87,24 @@ public final class WebAPI { public typealias FailureClosure = (_ error: SlackError)->Void public enum InfoType: String { - case Purpose = "purpose" - case Topic = "topic" + case purpose = "purpose" + case topic = "topic" } public enum ParseMode: String { - case Full = "full" - case None = "none" + case full = "full" + case none = "none" } public enum Presence: String { - case Auto = "auto" - case Away = "away" + case auto = "auto" + case away = "away" } fileprivate enum ChannelType: String { - case Channel = "channel" - case Group = "group" - case IM = "im" + case channel = "channel" + case group = "group" + case im = "im" } fileprivate let networkInterface: NetworkInterface @@ -118,7 +118,7 @@ public final class WebAPI { //MARK: - RTM public func rtmStart(_ simpleLatest: Bool? = nil, noUnreads: Bool? = nil, mpimAware: Bool? = nil, success: ((_ response: [String: Any])->Void)?, failure: FailureClosure?) { let parameters: [String: Any?] = ["simple_latest": simpleLatest, "no_unreads": noUnreads, "mpim_aware": mpimAware] - networkInterface.request(.RTMStart, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { + networkInterface.request(.rtmStart, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in success?(response) }) {(error) -> Void in @@ -128,7 +128,7 @@ public final class WebAPI { //MARK: - Auth public func authenticationTest(_ success: ((_ authenticated: Bool)->Void)?, failure: FailureClosure?) { - networkInterface.request(.AuthTest, token: token, parameters: nil, successClosure: { + networkInterface.request(.authTest, token: token, parameters: nil, successClosure: { (response) -> Void in success?(true) }) {(error) -> Void in @@ -138,7 +138,7 @@ public final class WebAPI { public static func oauthAccess(_ clientID: String, clientSecret: String, code: String, redirectURI: String? = nil, success: ((_ response: [String: Any])->Void)?, failure: ((SlackError)->Void)?) { let parameters: [String: Any?] = ["client_id": clientID, "client_secret": clientSecret, "code": code, "redirect_uri": redirectURI] - NetworkInterface().request(.OAuthAccess, parameters: filterNilParameters(parameters), successClosure: { + NetworkInterface().request(.oauthAccess, parameters: filterNilParameters(parameters), successClosure: { (response) -> Void in success?(response) }) {(error) -> Void in @@ -148,7 +148,7 @@ public final class WebAPI { public static func oauthRevoke(_ token: String, test: Bool? = nil, success: ((_ revoked:Bool)->Void)?, failure: ((SlackError)->Void)?) { let parameters: [String: Any?] = ["token": token, "test": test] - NetworkInterface().request(.AuthRevoke, parameters: filterNilParameters(parameters), successClosure: { + NetworkInterface().request(.authRevoke, parameters: filterNilParameters(parameters), successClosure: { (response) -> Void in success?(true) }) {(error) -> Void in @@ -158,7 +158,7 @@ public final class WebAPI { //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?) { - history(.ChannelsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: { + history(.channelsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: { (history) -> Void in success?(history) }) {(error) -> Void in @@ -167,7 +167,7 @@ public final class WebAPI { } public func channelInfo(_ id: String, success: ((_ channel: Channel)->Void)?, failure: FailureClosure?) { - info(.ChannelsInfo, type:ChannelType.Channel, id: id, success: { + info(.channelsInfo, type:.channel, id: id, success: { (channel) -> Void in success?(channel) }) { (error) -> Void in @@ -176,7 +176,7 @@ public final class WebAPI { } public func channelsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: Any]]?)->Void)?, failure: FailureClosure?) { - list(.ChannelsList, type:ChannelType.Channel, excludeArchived: excludeArchived, success: { + list(.channelsList, type:.channel, excludeArchived: excludeArchived, success: { (channels) -> Void in success?(channels) }) {(error) -> Void in @@ -185,7 +185,7 @@ public final class WebAPI { } public func markChannel(_ channel: String, timestamp: String, success: ((_ ts: String)->Void)?, failure: FailureClosure?) { - mark(.ChannelsMark, channel: channel, timestamp: timestamp, success: { + mark(.channelsMark, channel: channel, timestamp: timestamp, success: { (ts) -> Void in success?(timestamp) }) {(error) -> Void in @@ -194,7 +194,7 @@ public final class WebAPI { } public func setChannelPurpose(_ channel: String, purpose: String, success: ((_ purposeSet: Bool)->Void)?, failure: FailureClosure?) { - setInfo(.ChannelsSetPurpose, type: .Purpose, channel: channel, text: purpose, success: { + setInfo(.channelsSetPurpose, type: .purpose, channel: channel, text: purpose, success: { (purposeSet) -> Void in success?(purposeSet) }) { (error) -> Void in @@ -203,7 +203,7 @@ public final class WebAPI { } public func setChannelTopic(_ channel: String, topic: String, success: ((_ topicSet: Bool)->Void)?, failure: FailureClosure?) { - setInfo(.ChannelsSetTopic, type: .Topic, channel: channel, text: topic, success: { + setInfo(.channelsSetTopic, type: .topic, channel: channel, text: topic, success: { (topicSet) -> Void in success?(topicSet) }) {(error) -> Void in @@ -214,7 +214,7 @@ public final class WebAPI { //MARK: - Messaging public func deleteMessage(_ channel: String, ts: String, success: ((_ deleted: Bool)->Void)?, failure: FailureClosure?) { let parameters: [String: Any] = ["channel": channel, "ts": ts] - networkInterface.request(.ChatDelete, token: token, parameters: parameters, successClosure: { (response) -> Void in + networkInterface.request(.chatDelete, token: token, parameters: parameters, successClosure: { (response) -> Void in success?(true) }) {(error) -> Void in failure?(error) @@ -223,7 +223,7 @@ public final class WebAPI { public func sendMessage(_ channel: String, text: String, username: String? = nil, asUser: Bool? = nil, parse: ParseMode? = nil, linkNames: Bool? = nil, attachments: [Attachment?]? = nil, unfurlLinks: Bool? = nil, unfurlMedia: Bool? = nil, iconURL: String? = nil, iconEmoji: String? = nil, success: (((ts: String?, channel: String?))->Void)?, failure: FailureClosure?) { let parameters: [String: Any?] = ["channel": channel, "text": text.slackFormatEscaping, "as_user": asUser, "parse": parse?.rawValue, "link_names": linkNames, "unfurl_links": unfurlLinks, "unfurlMedia": unfurlMedia, "username": username, "icon_url": iconURL, "icon_emoji": iconEmoji, "attachments": encodeAttachments(attachments)] - networkInterface.request(.ChatPostMessage, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { + 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 @@ -231,9 +231,9 @@ public final class WebAPI { } } - public func updateMessage(_ channel: String, ts: String, message: String, attachments: [Attachment?]? = nil, parse:ParseMode = .None, linkNames: Bool = false, success: ((_ updated: Bool)->Void)?, failure: FailureClosure?) { + public func updateMessage(_ channel: String, ts: String, message: String, attachments: [Attachment?]? = nil, parse:ParseMode = .none, linkNames: Bool = false, success: ((_ updated: Bool)->Void)?, failure: FailureClosure?) { let parameters: [String: Any?] = ["channel": channel, "ts": ts, "text": message.slackFormatEscaping, "parse": parse.rawValue, "link_names": linkNames, "attachments": encodeAttachments(attachments)] - networkInterface.request(.ChatUpdate, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { + networkInterface.request(.chatUpdate, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in success?(true) }) {(error) -> Void in @@ -244,7 +244,7 @@ public final class WebAPI { //MARK: - Do Not Disturb public func dndInfo(_ user: String? = nil, success: ((_ status: DoNotDisturbStatus)->Void)?, failure: FailureClosure?) { let parameters: [String: Any?] = ["user": user] - networkInterface.request(.DNDInfo, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { + networkInterface.request(.dndInfo, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in success?(DoNotDisturbStatus(status: response)) }) {(error) -> Void in @@ -254,7 +254,7 @@ public final class WebAPI { public func dndTeamInfo(_ users: [String]? = nil, success: ((_ statuses: [String: DoNotDisturbStatus])->Void)?, failure: FailureClosure?) { let parameters: [String: Any?] = ["users": users?.joined(separator: ",")] - networkInterface.request(.DNDTeamInfo, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { + networkInterface.request(.dndTeamInfo, token: token, parameters: WebAPI.filterNilParameters(parameters), successClosure: { (response) -> Void in guard let usersDictionary = response["users"] as? [String: Any] else { success?([:]) @@ -268,7 +268,7 @@ public final class WebAPI { //MARK: - Emoji public func emojiList(_ success: ((_ emojiList: [String: Any]?)->Void)?, failure: FailureClosure?) { - networkInterface.request(.EmojiList, token: token, parameters: nil, successClosure: { + networkInterface.request(.emojiList, token: token, parameters: nil, successClosure: { (response) -> Void in success?(response["emoji"] as? [String: Any]) }) { (error) -> Void in @@ -279,7 +279,7 @@ public final class WebAPI { //MARK: - Files public func deleteFile(_ fileID: String, success: ((_ deleted: Bool)->Void)?, failure: FailureClosure?) { let parameters = ["file": fileID] - networkInterface.request(.FilesDelete, token: token, parameters: parameters as [String : Any]?, successClosure: { + networkInterface.request(.filesDelete, token: token, parameters: parameters as [String : Any]?, successClosure: { (response) -> Void in success?(true) }) {(error) -> Void in @@ -289,7 +289,7 @@ public final class WebAPI { public func fileInfo(_ fileID: String, commentCount: Int = 100, totalPages: Int = 1, success: ((_ file: File)->Void)?, failure: FailureClosure?) { let parameters: [String: Any] = ["file": fileID, "count": commentCount, "totalPages": totalPages] - networkInterface.request(.FilesInfo, token: token, parameters: parameters, successClosure: { + networkInterface.request(.filesInfo, token: token, parameters: parameters, successClosure: { (response) in var file = File(file: response["file"] as? [String: Any]) (response["comments"] as? [[String: Any]])?.forEach { comment in @@ -317,7 +317,7 @@ public final class WebAPI { //MARK: - File Comments public func addFileComment(_ fileID: String, comment: String, success: ((_ comment: Comment)->Void)?, failure: FailureClosure?) { let parameters: [String: Any] = ["file": fileID, "comment": comment.slackFormatEscaping] - networkInterface.request(.FilesCommentsAdd, token: token, parameters: parameters, successClosure: { + networkInterface.request(.filesCommentsAdd, token: token, parameters: parameters, successClosure: { (response) -> Void in success?(Comment(comment: response["comment"] as? [String: Any])) }) {(error) -> Void in @@ -327,7 +327,7 @@ public final class WebAPI { public func editFileComment(_ fileID: String, commentID: String, comment: String, success: ((_ comment: Comment)->Void)?, failure: FailureClosure?) { let parameters: [String: Any] = ["file": fileID, "id": commentID, "comment": comment.slackFormatEscaping] - networkInterface.request(.FilesCommentsEdit, token: token, parameters: parameters, successClosure: { + networkInterface.request(.filesCommentsEdit, token: token, parameters: parameters, successClosure: { (response) -> Void in success?(Comment(comment: response["comment"] as? [String: Any])) }) {(error) -> Void in @@ -337,7 +337,7 @@ public final class WebAPI { public func deleteFileComment(_ fileID: String, commentID: String, success: ((_ deleted: Bool?)->Void)?, failure: FailureClosure?) { let parameters: [String: Any] = ["file": fileID, "id": commentID] - networkInterface.request(.FilesCommentsDelete, token: token, parameters: parameters, successClosure: { + networkInterface.request(.filesCommentsDelete, token: token, parameters: parameters, successClosure: { (response) -> Void in success?(true) }) {(error) -> Void in @@ -347,7 +347,7 @@ public final class WebAPI { //MARK: - Groups public func closeGroup(_ groupID: String, success: ((_ closed: Bool)->Void)?, failure: FailureClosure?) { - close(.GroupsClose, channelID: groupID, success: { + close(.groupsClose, channelID: groupID, success: { (closed) -> Void in success?(closed) }) {(error) -> Void in @@ -356,7 +356,7 @@ public final class WebAPI { } 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(.groupsHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: { (history) -> Void in success?(history) }) {(error) -> Void in @@ -365,7 +365,7 @@ public final class WebAPI { } public func groupInfo(_ id: String, success: ((_ channel: Channel)->Void)?, failure: FailureClosure?) { - info(.GroupsInfo, type:ChannelType.Group, id: id, success: { + info(.groupsInfo, type:.group, id: id, success: { (channel) -> Void in success?(channel) }) {(error) -> Void in @@ -374,7 +374,7 @@ public final class WebAPI { } public func groupsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: Any]]?)->Void)?, failure: FailureClosure?) { - list(.GroupsList, type:ChannelType.Group, excludeArchived: excludeArchived, success: { + list(.groupsList, type:.group, excludeArchived: excludeArchived, success: { (channels) -> Void in success?(channels) }) {(error) -> Void in @@ -383,7 +383,7 @@ public final class WebAPI { } public func markGroup(_ channel: String, timestamp: String, success: ((_ ts: String)->Void)?, failure: FailureClosure?) { - mark(.GroupsMark, channel: channel, timestamp: timestamp, success: { + mark(.groupsMark, channel: channel, timestamp: timestamp, success: { (ts) -> Void in success?(timestamp) }) {(error) -> Void in @@ -393,7 +393,7 @@ public final class WebAPI { public func openGroup(_ channel: String, success: ((_ opened: Bool)->Void)?, failure: FailureClosure?) { let parameters = ["channel":channel] - networkInterface.request(.GroupsOpen, token: token, parameters: parameters as [String: Any]?, successClosure: { + networkInterface.request(.groupsOpen, token: token, parameters: parameters as [String: Any]?, successClosure: { (response) -> Void in success?(true) }) {(error) -> Void in @@ -402,7 +402,7 @@ public final class WebAPI { } public func setGroupPurpose(_ channel: String, purpose: String, success: ((_ purposeSet: Bool)->Void)?, failure: FailureClosure?) { - setInfo(.GroupsSetPurpose, type: .Purpose, channel: channel, text: purpose, success: { + setInfo(.groupsSetPurpose, type: .purpose, channel: channel, text: purpose, success: { (purposeSet) -> Void in success?(purposeSet) }) {(error) -> Void in @@ -411,7 +411,7 @@ public final class WebAPI { } public func setGroupTopic(_ channel: String, topic: String, success: ((_ topicSet: Bool)->Void)?, failure: FailureClosure?) { - setInfo(.GroupsSetTopic, type: .Topic, channel: channel, text: topic, success: { + setInfo(.groupsSetTopic, type: .topic, channel: channel, text: topic, success: { (topicSet) -> Void in success?(topicSet) }) {(error) -> Void in @@ -421,7 +421,7 @@ public final class WebAPI { //MARK: - IM public func closeIM(_ channel: String, success: ((_ closed: Bool)->Void)?, failure: FailureClosure?) { - close(.IMClose, channelID: channel, success: { + close(.imClose, channelID: channel, success: { (closed) -> Void in success?(closed) }) {(error) -> Void in @@ -430,7 +430,7 @@ public final class WebAPI { } 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(.imHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: { (history) -> Void in success?(history) }) {(error) -> Void in @@ -439,7 +439,7 @@ public final class WebAPI { } public func imsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: Any]]?)->Void)?, failure: FailureClosure?) { - list(.IMList, type:ChannelType.IM, excludeArchived: excludeArchived, success: { + list(.imList, type:.im, excludeArchived: excludeArchived, success: { (channels) -> Void in success?(channels) }) {(error) -> Void in @@ -448,7 +448,7 @@ public final class WebAPI { } public func markIM(_ channel: String, timestamp: String, success: ((_ ts: String)->Void)?, failure: FailureClosure?) { - mark(.IMMark, channel: channel, timestamp: timestamp, success: { + mark(.imMark, channel: channel, timestamp: timestamp, success: { (ts) -> Void in success?(timestamp) }) {(error) -> Void in @@ -458,7 +458,7 @@ public final class WebAPI { public func openIM(_ userID: String, success: ((_ imID: String?)->Void)?, failure: FailureClosure?) { let parameters = ["user": userID] - networkInterface.request(.IMOpen, token: token, parameters: parameters as [String: Any]?, successClosure: { + networkInterface.request(.imOpen, token: token, parameters: parameters as [String: Any]?, successClosure: { (response) -> Void in let group = response["channel"] as? [String: Any] success?(group?["id"] as? String) @@ -469,7 +469,7 @@ public final class WebAPI { //MARK: - MPIM public func closeMPIM(_ channel: String, success: ((_ closed: Bool)->Void)?, failure: FailureClosure?) { - close(.MPIMClose, channelID: channel, success: { + close(.mpimClose, channelID: channel, success: { (closed) -> Void in success?(closed) }) {(error) -> Void in @@ -478,7 +478,7 @@ public final class WebAPI { } 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(.mpimHistory, id: id, latest: latest, oldest: oldest, inclusive: inclusive, count: count, unreads: unreads, success: { (history) -> Void in success?(history) }) {(error) -> Void in @@ -487,7 +487,7 @@ public final class WebAPI { } public func mpimsList(_ excludeArchived: Bool = false, success: ((_ channels: [[String: Any]]?)->Void)?, failure: FailureClosure?) { - list(.MPIMList, type:ChannelType.Group, excludeArchived: excludeArchived, success: { + list(.mpimList, type:.group, excludeArchived: excludeArchived, success: { (channels) -> Void in success?(channels) }) {(error) -> Void in @@ -496,7 +496,7 @@ public final class WebAPI { } public func markMPIM(_ channel: String, timestamp: String, success: ((_ ts: String)->Void)?, failure: FailureClosure?) { - mark(.MPIMMark, channel: channel, timestamp: timestamp, success: { + mark(.mpimMark, channel: channel, timestamp: timestamp, success: { (ts) -> Void in success?(timestamp) }) {(error) -> Void in @@ -506,7 +506,7 @@ public final class WebAPI { public func openMPIM(_ userIDs: [String], success: ((_ mpimID: String?)->Void)?, failure: FailureClosure?) { let parameters = ["users": userIDs.joined(separator: ",")] - networkInterface.request(.MPIMOpen, token: token, parameters: parameters as [String: Any]?, successClosure: { + networkInterface.request(.mpimOpen, token: token, parameters: parameters as [String: Any]?, successClosure: { (response) -> Void in let group = response["group"] as? [String: Any] success?(group?["id"] as? String) @@ -517,7 +517,7 @@ public final class WebAPI { //MARK: - Pins public func pinItem(_ channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((_ pinned: Bool)->Void)?, failure: FailureClosure?) { - pin(.PinsAdd, channel: channel, file: file, fileComment: fileComment, timestamp: timestamp, success: { + pin(.pinsAdd, channel: channel, file: file, fileComment: fileComment, timestamp: timestamp, success: { (ok) -> Void in success?(ok) }) {(error) -> Void in @@ -526,7 +526,7 @@ public final class WebAPI { } public func unpinItem(_ channel: String, file: String? = nil, fileComment: String? = nil, timestamp: String? = nil, success: ((_ unpinned: Bool)->Void)?, failure: FailureClosure?) { - pin(.PinsRemove, channel: channel, file: file, fileComment: fileComment, timestamp: timestamp, success: { + pin(.pinsRemove, channel: channel, file: file, fileComment: fileComment, timestamp: timestamp, success: { (ok) -> Void in success?(ok) }) {(error) -> Void in @@ -547,7 +547,7 @@ public final class WebAPI { //MARK: - Reactions // One of file, file_comment, or the combination of channel and timestamp must be specified. public func addReaction(_ name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((_ reacted: Bool)->Void)?, failure: FailureClosure?) { - react(.ReactionsAdd, name: name, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: { + react(.reactionsAdd, name: name, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: { (ok) -> Void in success?(ok) }) {(error) -> Void in @@ -557,7 +557,7 @@ public final class WebAPI { // One of file, file_comment, or the combination of channel and timestamp must be specified. public func removeReaction(_ name: String, file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((_ unreacted: Bool)->Void)?, failure: FailureClosure?) { - react(.ReactionsRemove, name: name, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: { + react(.reactionsRemove, name: name, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: { (ok) -> Void in success?(ok) }) {(error) -> Void in @@ -578,7 +578,7 @@ public final class WebAPI { //MARK: - Stars // One of file, file_comment, channel, or the combination of channel and timestamp must be specified. public func addStar(_ file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((_ starred: Bool)->Void)?, failure: FailureClosure?) { - star(.StarsAdd, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: { + star(.starsAdd, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: { (ok) -> Void in success?(ok) }) {(error) -> Void in @@ -588,7 +588,7 @@ public final class WebAPI { // One of file, file_comment, channel, or the combination of channel and timestamp must be specified. public func removeStar(_ file: String? = nil, fileComment: String? = nil, channel: String? = nil, timestamp: String? = nil, success: ((_ unstarred: Bool)->Void)?, failure: FailureClosure?) { - star(.StarsRemove, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: { + star(.starsRemove, file: file, fileComment: fileComment, channel: channel, timestamp: timestamp, success: { (ok) -> Void in success?(ok) }) {(error) -> Void in @@ -609,7 +609,7 @@ public final class WebAPI { //MARK: - Team public func teamInfo(_ success: ((_ info: [String: Any]?)->Void)?, failure: FailureClosure?) { - networkInterface.request(.TeamInfo, token: token, parameters: nil, successClosure: { + networkInterface.request(.teamInfo, token: token, parameters: nil, successClosure: { (response) -> Void in success?(response["team"] as? [String: Any]) }) {(error) -> Void in @@ -620,7 +620,7 @@ public final class WebAPI { //MARK: - Users public func userPresence(_ user: String, success: ((_ presence: String?)->Void)?, failure: FailureClosure?) { let parameters: [String: Any] = ["user": user] - networkInterface.request(.UsersGetPresence, token: token, parameters: parameters, successClosure: { + networkInterface.request(.usersGetPresence, token: token, parameters: parameters, successClosure: { (response) -> Void in success?(response["presence"] as? String) }){(error) -> Void in @@ -630,7 +630,7 @@ public final class WebAPI { public func userInfo(_ id: String, success: ((_ user: User)->Void)?, failure: FailureClosure?) { let parameters: [String: Any] = ["user": id] - networkInterface.request(.UsersInfo, token: token, parameters: parameters, successClosure: { + networkInterface.request(.usersInfo, token: token, parameters: parameters, successClosure: { (response) -> Void in success?(User(user: response["user"] as? [String: Any])) }) {(error) -> Void in @@ -640,7 +640,7 @@ public final class WebAPI { public func usersList(_ includePresence: Bool = false, success: ((_ userList: [[String: Any]]?)->Void)?, failure: FailureClosure?) { let parameters: [String: Any] = ["presence": includePresence] - networkInterface.request(.UsersList, token: token, parameters: parameters, successClosure: { + networkInterface.request(.usersList, token: token, parameters: parameters, successClosure: { (response) -> Void in success?(response["members"] as? [[String: Any]]) }){(error) -> Void in @@ -649,7 +649,7 @@ public final class WebAPI { } public func setUserActive(_ success: ((_ success: Bool)->Void)?, failure: FailureClosure?) { - networkInterface.request(.UsersSetActive, token: token, parameters: nil, successClosure: { + networkInterface.request(.usersSetActive, token: token, parameters: nil, successClosure: { (response) -> Void in success?(true) }) {(error) -> Void in @@ -659,7 +659,7 @@ public final class WebAPI { public func setUserPresence(_ presence: Presence, success: ((_ success: Bool)->Void)?, failure: FailureClosure?) { let parameters: [String: Any] = ["presence": presence.rawValue] - networkInterface.request(.UsersSetPresence, token: token, parameters: parameters, successClosure: { + networkInterface.request(.usersSetPresence, token: token, parameters: parameters, successClosure: { (response) -> Void in success?(true) }) {(error) -> Void in From 24b2292cbaec5fc05e99b9a43fde201f0b418e05 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Thu, 17 Nov 2016 16:48:00 -0500 Subject: [PATCH 05/10] Request string bugfix --- SlackKit/Sources/Extensions.swift | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/SlackKit/Sources/Extensions.swift b/SlackKit/Sources/Extensions.swift index 37b0518..80f27f7 100644 --- a/SlackKit/Sources/Extensions.swift +++ b/SlackKit/Sources/Extensions.swift @@ -41,17 +41,16 @@ internal extension String { } internal extension Dictionary where Key: ExpressibleByStringLiteral, Value: Any { - + var requestStringFromParameters: String { var requestString = "" for key in self.keys { if let value = self[key] as? String, let encodedValue = value.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlHostAllowed) { requestString += "&\(key)=\(encodedValue)" - } else if let value = self[key] as? Int { + } else if let value = self[key] { requestString += "&\(key)=\(value)" } } - return requestString } } From 21ec3cb2a1c8704badc28713c0eae047d330acf3 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 20 Nov 2016 22:04:50 -0500 Subject: [PATCH 06/10] Fix iOS crash --- SlackKit/Sources/Client+EventDispatching.swift | 6 ++---- SlackKit/Sources/Event.swift | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/SlackKit/Sources/Client+EventDispatching.swift b/SlackKit/Sources/Client+EventDispatching.swift index 6e21821..2b9ae0d 100644 --- a/SlackKit/Sources/Client+EventDispatching.swift +++ b/SlackKit/Sources/Client+EventDispatching.swift @@ -24,10 +24,8 @@ internal extension Client { func dispatch(_ event: [String: Any]) { - let event = Event(event: event) - guard let type = event.type else { - return - } + let event = Event(event) + let type = event.type ?? .error switch type { case .hello: connected = true diff --git a/SlackKit/Sources/Event.swift b/SlackKit/Sources/Event.swift index 60eb37c..beaa3fb 100644 --- a/SlackKit/Sources/Event.swift +++ b/SlackKit/Sources/Event.swift @@ -123,8 +123,7 @@ internal enum MessageSubtype: String { case unpinnedItem = "unpinned_item" } -internal struct Event { - +internal class Event { let type: EventType? let ts: String? let subtype: String? @@ -162,7 +161,7 @@ internal struct Event { let subteamID: String? var profile: CustomProfile? - init(event:[String: Any]) { + init(_ event:[String: Any]) { type = EventType(rawValue: event["type"] as? String ?? "ok") ts = event["ts"] as? String subtype = event["subtype"] as? String From 2d6e19baee0a12b2caa35e5a2005e3fbbe6bf692 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 20 Nov 2016 22:07:06 -0500 Subject: [PATCH 07/10] Bump starscream version --- Cartfile | 4 ++-- Podfile | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cartfile b/Cartfile index 0b67c44..7fca9a3 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -git "https://github.com/daltoniam/Starscream" == 2.0.0 -git "https://github.com/pvzig/swifter.git" == 3.0.4 \ No newline at end of file +github "https://github.com/daltoniam/Starscream" == 2.0.2 +github "https://github.com/pvzig/swifter.git" == 3.0.4 \ No newline at end of file diff --git a/Podfile b/Podfile index c776359..57fbbc7 100644 --- a/Podfile +++ b/Podfile @@ -3,16 +3,16 @@ source 'https://github.com/CocoaPods/Specs.git' use_frameworks! target 'SlackKit OS X' do - pod 'Starscream', '~> 2.0.0' + pod 'Starscream', '~> 2.0.2' pod 'Swifter', '~> 1.3.2' end target 'SlackKit iOS' do - pod 'Starscream', '~> 2.0.0' + pod 'Starscream', '~> 2.0.2' pod 'Swifter', '~> 1.3.2' end target 'SlackKit tvOS' do - pod 'Starscream', '~> 2.0.0' + pod 'Starscream', '~> 2.0.2' pod 'Swifter', '~> 1.3.2' end \ No newline at end of file From a0de46e3c756d55cc81463c827680f7c879d6a97 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sun, 20 Nov 2016 22:10:44 -0500 Subject: [PATCH 08/10] Code quality improvements --- SlackKit/Sources/NetworkInterface.swift | 36 ++++++++++++------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/SlackKit/Sources/NetworkInterface.swift b/SlackKit/Sources/NetworkInterface.swift index e0eff57..c62f065 100644 --- a/SlackKit/Sources/NetworkInterface.swift +++ b/SlackKit/Sources/NetworkInterface.swift @@ -40,14 +40,14 @@ internal struct NetworkInterface { return } 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) - }) + do { + successClosure(try self.handleResponse(data, response: response, internalError: internalError)) + } catch let error { + errorClosure(error as? SlackError ?? SlackError.unknownError) + } }.resume() } @@ -103,29 +103,27 @@ 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) - }) + do { + successClosure(try self.handleResponse(data, response: response, internalError: internalError)) + } catch let error { + errorClosure(error as? SlackError ?? SlackError.unknownError) + } }.resume() } - private func handleResponse(_ data: Data?, response:URLResponse?, internalError:Error?, successClosure: ([String: Any])->Void, errorClosure: (SlackError)->Void) { + private func handleResponse(_ data: Data?, response:URLResponse?, internalError:Error?) throws -> [String: Any] { guard let data = data, let response = response as? HTTPURLResponse else { - errorClosure(SlackError.clientNetworkError) - return + throw SlackError.clientNetworkError } do { guard let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else { - errorClosure(SlackError.clientJSONError) - return + throw SlackError.clientJSONError } switch response.statusCode { case 200: if (json["ok"] as! Bool == true) { - successClosure(json) + return json } else { if let errorString = json["error"] as? String { throw SlackError(rawValue: errorString) ?? .unknownError @@ -140,9 +138,9 @@ internal struct NetworkInterface { } } catch let error { if let slackError = error as? SlackError { - errorClosure(slackError) + throw slackError } else { - errorClosure(SlackError.unknownError) + throw SlackError.unknownError } } } From d02768ddad9110fdfdbc05f4552f0ca1b7eca3e0 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Thu, 24 Nov 2016 12:01:54 -0500 Subject: [PATCH 09/10] Bump starscream version --- Cartfile.resolved | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index 638ab9e..3c4e009 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -git "https://github.com/daltoniam/Starscream" "2.0.0" -git "https://github.com/pvzig/swifter.git" "3.0.4" +github "daltoniam/Starscream" "2.0.2" +github "pvzig/swifter" "3.0.4" From 5d7064ee13fbae5f84bd7f861dc2850dedd68bd6 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Thu, 24 Nov 2016 12:16:53 -0500 Subject: [PATCH 10/10] Podfile + versioning --- Podfile | 6 +++--- Podfile.lock | 20 +++++++++++++++----- SlackKit/Supporting Files/Info-iOS.plist | 2 +- SlackKit/Supporting Files/Info-tvOS.plist | 2 +- SlackKit/Supporting Files/Info.plist | 2 +- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Podfile b/Podfile index 57fbbc7..03a67bb 100644 --- a/Podfile +++ b/Podfile @@ -4,15 +4,15 @@ use_frameworks! target 'SlackKit OS X' do pod 'Starscream', '~> 2.0.2' - pod 'Swifter', '~> 1.3.2' + pod 'Swifter', :git => 'https://github.com/pvzig/swifter.git', :tag => '3.0.4' end target 'SlackKit iOS' do pod 'Starscream', '~> 2.0.2' - pod 'Swifter', '~> 1.3.2' + pod 'Swifter', :git => 'https://github.com/pvzig/swifter.git', :tag => '3.0.4' end target 'SlackKit tvOS' do pod 'Starscream', '~> 2.0.2' - pod 'Swifter', '~> 1.3.2' + pod 'Swifter', :git => 'https://github.com/pvzig/swifter.git', :tag => '3.0.4' end \ No newline at end of file diff --git a/Podfile.lock b/Podfile.lock index e9d034e..b5b4c9a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,15 +1,25 @@ PODS: - - Starscream (2.0.0) + - Starscream (2.0.2) - Swifter (1.3.2) DEPENDENCIES: - - Starscream (~> 2.0.0) - - Swifter (~> 1.3.2) + - Starscream (~> 2.0.2) + - Swifter (from `https://github.com/pvzig/swifter.git`, tag `3.0.4`) + +EXTERNAL SOURCES: + Swifter: + :git: https://github.com/pvzig/swifter.git + :tag: 3.0.4 + +CHECKOUT OPTIONS: + Swifter: + :git: https://github.com/pvzig/swifter.git + :tag: 3.0.4 SPEC CHECKSUMS: - Starscream: 947c865596f0d6bb3f0203fee23228ed2d471468 + Starscream: 6c135a34e0a6e60cedaa0b30db67a4c05cf7cd38 Swifter: dd1800ba8eb3e28b22b8bd20f91a8561a0110fac -PODFILE CHECKSUM: 3d4e92bde92fd20d6fe672ad26f677fcbfafda1f +PODFILE CHECKSUM: cd86ea0f8422027c9d5fa3c40243ae7a816fb79a COCOAPODS: 1.1.0.rc.3 diff --git a/SlackKit/Supporting Files/Info-iOS.plist b/SlackKit/Supporting Files/Info-iOS.plist index 0491eac..4309c13 100644 --- a/SlackKit/Supporting Files/Info-iOS.plist +++ b/SlackKit/Supporting Files/Info-iOS.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.1.0 + 3.1.5 CFBundleSignature ???? CFBundleVersion diff --git a/SlackKit/Supporting Files/Info-tvOS.plist b/SlackKit/Supporting Files/Info-tvOS.plist index 0491eac..4309c13 100644 --- a/SlackKit/Supporting Files/Info-tvOS.plist +++ b/SlackKit/Supporting Files/Info-tvOS.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.1.0 + 3.1.5 CFBundleSignature ???? CFBundleVersion diff --git a/SlackKit/Supporting Files/Info.plist b/SlackKit/Supporting Files/Info.plist index 0491eac..4309c13 100644 --- a/SlackKit/Supporting Files/Info.plist +++ b/SlackKit/Supporting Files/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 3.1.0 + 3.1.5 CFBundleSignature ???? CFBundleVersion