Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
Adding Blocks support
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Brown committed Jul 16, 2019
1 parent 7d20713 commit 7ba97e4
Show file tree
Hide file tree
Showing 5 changed files with 636 additions and 1 deletion.
96 changes: 96 additions & 0 deletions SKCore/Sources/BlockComposition.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/// Defined by https://api.slack.com/reference/messaging/composition-objects#text
public struct TextComposition {
/// The type of block. Can be one of plainText or markdown.
public let type: BlockType
public let text: String
public let emoji: Bool?
public let verbatim: Bool?

public init(type: BlockType,
text: String,
emoji: Bool? = nil,
verbatim: Bool? = nil) {
self.type = type
self.text = text
self.emoji = emoji
self.verbatim = verbatim
}

public var dictionary: [String: Any] {
var composition = [String: Any]()
composition["type"] = type.rawValue
composition["text"] = text
composition["emoji"] = emoji
composition["verbatim"] = verbatim
return composition
}
}

/// Defined by https://api.slack.com/reference/messaging/composition-objects#option
public struct OptionComposition {
public let text: TextComposition
public let value: String
public let url: String?

public init(text: TextComposition,
value: String,
url: String? = nil) {
self.text = text
self.value = value
self.url = url
}

public var dictionary: [String: Any] {
var composition = [String: Any]()
composition["text"] = text.dictionary
composition["value"] = value
composition["url"] = url
return composition
}
}

/// Defined by https://api.slack.com/reference/messaging/composition-objects#option-group
public struct OptionGroupComposition {
public let label: TextComposition
public let options: [OptionComposition]

public init(label: TextComposition,
options: [OptionComposition]) {
self.label = label
self.options = options
}

public var dictionary: [String: Any] {
var composition = [String: Any]()
composition["label"] = label.dictionary
composition["options"] = options.map { $0.dictionary }
return composition
}
}

/// Defined by https://api.slack.com/reference/messaging/composition-objects#confirm
public struct ConfirmComposition {
public let title: TextComposition
public let text: TextComposition
public let confirm: TextComposition
public let deny: TextComposition

public init(title: TextComposition,
text: TextComposition,
confirm: TextComposition,
deny: TextComposition) {
self.title = title
self.text = text
self.confirm = confirm
self.deny = deny
}

public var dictionary: [String: Any] {
var composition = [String: Any]()
composition["title"] = title.dictionary
composition["text"] = text.dictionary
composition["confirm"] = confirm.dictionary
composition["deny"] = deny.dictionary
return composition
}
}
Loading

0 comments on commit 7ba97e4

Please sign in to comment.