Skip to content
This repository was archived by the owner on Jan 28, 2019. It is now read-only.

Commit fcf3f74

Browse files
committed
Merge branch 'master' of https://github.com/SlackKit/SKWebAPI
2 parents 795e379 + 70a7346 commit fcf3f74

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

Sources/Endpoint.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public enum Endpoint: String {
3737
case chatPostMessage = "chat.postMessage"
3838
case chatMeMessage = "chat.meMessage"
3939
case chatUpdate = "chat.update"
40+
case conversationsList = "conversations.list"
4041
case dndInfo = "dnd.info"
4142
case dndTeamInfo = "dnd.teamInfo"
4243
case emojiList = "emoji.list"

Sources/WebAPI.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public final class WebAPI {
5353
case channel, group, im
5454
}
5555

56+
public enum ConversationType: String {
57+
case public_channel, private_channel, mpim, im
58+
}
59+
5660
fileprivate let networkInterface: NetworkInterface
5761
fileprivate let token: String
5862

@@ -1097,6 +1101,34 @@ extension WebAPI {
10971101
}
10981102
}
10991103

1104+
// MARK: - Conversations
1105+
extension WebAPI {
1106+
public func conversationsList(
1107+
excludeArchived: Bool = false,
1108+
cursor: String? = nil,
1109+
limit: Int? = nil,
1110+
types: [ConversationType]? = nil,
1111+
success: ((_ channels: [[String: Any]]?, _ nextCursor: String?) -> Void)?,
1112+
failure: FailureClosure?
1113+
) {
1114+
var parameters: [String: Any] = ["token": token, "exclude_archived": excludeArchived]
1115+
if let cursor = cursor {
1116+
parameters["cursor"] = cursor
1117+
}
1118+
if let limit = limit {
1119+
parameters["limit"] = limit
1120+
}
1121+
if let types = types {
1122+
parameters["types"] = types.map({ $0.rawValue }).joined(separator: ",")
1123+
}
1124+
networkInterface.request(.conversationsList, parameters: parameters, successClosure: {(response) in
1125+
success?(response["channels"] as? [[String: Any]], (response["response_metadata"] as? [String: Any])?["next_cursor"] as? String)
1126+
}) {(error) in
1127+
failure?(error)
1128+
}
1129+
}
1130+
}
1131+
11001132
// MARK: - Utilities
11011133
extension WebAPI {
11021134
fileprivate func encodeAttachments(_ attachments: [Attachment?]?) -> String? {

0 commit comments

Comments
 (0)