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

Commit

Permalink
Merge branch 'master' of https://github.com/SlackKit/SKWebAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
pvzig committed Mar 15, 2018
2 parents 795e379 + 70a7346 commit fcf3f74
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/Endpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public enum Endpoint: String {
case chatPostMessage = "chat.postMessage"
case chatMeMessage = "chat.meMessage"
case chatUpdate = "chat.update"
case conversationsList = "conversations.list"
case dndInfo = "dnd.info"
case dndTeamInfo = "dnd.teamInfo"
case emojiList = "emoji.list"
Expand Down
32 changes: 32 additions & 0 deletions Sources/WebAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public final class WebAPI {
case channel, group, im
}

public enum ConversationType: String {
case public_channel, private_channel, mpim, im
}

fileprivate let networkInterface: NetworkInterface
fileprivate let token: String

Expand Down Expand Up @@ -1097,6 +1101,34 @@ extension WebAPI {
}
}

// MARK: - Conversations
extension WebAPI {
public func conversationsList(
excludeArchived: Bool = false,
cursor: String? = nil,
limit: Int? = nil,
types: [ConversationType]? = nil,
success: ((_ channels: [[String: Any]]?, _ nextCursor: String?) -> Void)?,
failure: FailureClosure?
) {
var parameters: [String: Any] = ["token": token, "exclude_archived": excludeArchived]
if let cursor = cursor {
parameters["cursor"] = cursor
}
if let limit = limit {
parameters["limit"] = limit
}
if let types = types {
parameters["types"] = types.map({ $0.rawValue }).joined(separator: ",")
}
networkInterface.request(.conversationsList, parameters: parameters, successClosure: {(response) in
success?(response["channels"] as? [[String: Any]], (response["response_metadata"] as? [String: Any])?["next_cursor"] as? String)
}) {(error) in
failure?(error)
}
}
}

// MARK: - Utilities
extension WebAPI {
fileprivate func encodeAttachments(_ attachments: [Attachment?]?) -> String? {
Expand Down

0 comments on commit fcf3f74

Please sign in to comment.