Module: FeishuNotifier::Card
- Defined in:
- lib/feishu_notifier/card.rb
Constant Summary collapse
- LEVELS =
{ "info" => { title: "Info", template: "blue" }, "debug" => { title: "Debug", template: "grey" }, "error" => { title: "Error", template: "red" } }.freeze
Class Method Summary collapse
- .by_id(card_id) ⇒ Object
- .custom(title: nil, text:, level: "info") ⇒ Object
- .simple(title:, text:) ⇒ Object
- .template(template_id, variables: {}) ⇒ Object
Class Method Details
.by_id(card_id) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/feishu_notifier/card.rb', line 20 def by_id(card_id) { type: "card", data: { card_id: card_id } } end |
.custom(title: nil, text:, level: "info") ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/feishu_notifier/card.rb', line 39 def custom(title: nil, text:, level: "info") style = LEVELS.fetch(level) do raise ArgumentError, "Unsupported card level: #{level}. Expected one of: #{LEVELS.keys.join(", ")}" end { config: { wide_screen_mode: true }, header: { template: style.fetch(:template), title: { tag: "plain_text", content: title.to_s.empty? ? style.fetch(:title) : title } }, elements: [ { tag: "div", text: { tag: "lark_md", content: text } } ] } end |
.simple(title:, text:) ⇒ Object
67 68 69 |
# File 'lib/feishu_notifier/card.rb', line 67 def simple(title:, text:) custom(title: title, text: text, level: "info") end |
.template(template_id, variables: {}) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/feishu_notifier/card.rb', line 29 def template(template_id, variables: {}) { type: "template", data: { template_id: template_id, template_variable: variables } } end |