From b48f33fb723a1cdf15562661bd5da82d42ca4ea3 Mon Sep 17 00:00:00 2001 From: Peter Zignego Date: Sat, 19 Mar 2016 14:12:04 -0400 Subject: [PATCH] Add support for file comment web API calls --- SlackKit/Sources/SlackWebAPI.swift | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/SlackKit/Sources/SlackWebAPI.swift b/SlackKit/Sources/SlackWebAPI.swift index 0539aff..51c3588 100644 --- a/SlackKit/Sources/SlackWebAPI.swift +++ b/SlackKit/Sources/SlackWebAPI.swift @@ -38,6 +38,9 @@ internal enum SlackAPIEndpoint: String { 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 FilesUpload = "files.upload" case GroupsClose = "groups.close" @@ -263,6 +266,37 @@ public class SlackWebAPI { } } + //MARK: - File Comments + public func addFileComment(fileID: String, comment: String, success: ((comment: Comment?)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["file":fileID, "comment":comment.slackFormatEscaping()] + client.api.request(.FilesCommentsAdd, token: client.token, parameters: parameters, successClosure: { + (response) -> Void in + success?(comment: Comment(comment: response["comment"] as? [String: AnyObject])) + }) {(error) -> Void in + failure?(error: error) + } + } + + public func editFileComment(fileID: String, commentID: String, comment: String, success: ((comment: Comment?)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["file":fileID, "id":commentID, "comment":comment.slackFormatEscaping()] + client.api.request(.FilesCommentsEdit, token: client.token, parameters: parameters, successClosure: { + (response) -> Void in + success?(comment: Comment(comment: response["comment"] as? [String: AnyObject])) + }) {(error) -> Void in + failure?(error: error) + } + } + + public func deleteFileComment(fileID: String, commentID: String, success: ((deleted: Bool?)->Void)?, failure: FailureClosure?) { + let parameters: [String: AnyObject] = ["file":fileID, "id": commentID] + client.api.request(.FilesCommentsDelete, token: client.token, parameters: parameters, successClosure: { + (response) -> Void in + success?(deleted: true) + }) {(error) -> Void in + failure?(error: error) + } + } + //MARK: - Groups public func closeGroup(groupID: String, success: ((closed: Bool)->Void)?, failure: FailureClosure?) { close(.GroupsClose, channelID: groupID, success: {