Class: Slackened::Surface::Message

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, BlockKit::Blocks
Defined in:
lib/slackened/surface/message.rb

Overview

Class Method Summary collapse

Methods included from BlockKit::Blocks

actions, button, context, custom, divider, header, section, text

Class Method Details

.build {|builder| ... } ⇒ Object

Yields:



23
24
25
# File 'lib/slackened/surface/message.rb', line 23

def build
	yield builder
end

.builderObject



19
20
21
# File 'lib/slackened/surface/message.rb', line 19

def builder
	@builder ||= Slackened::BlockKit::Builder.new
end

.layoutObject

Raises:

  • (NotImplementedError)


52
53
54
# File 'lib/slackened/surface/message.rb', line 52

def layout
	raise NotImplementedError, 'You must define `self.layout` and build a layout'
end

.post(url: Slackened.configuration.webhook_url, **kwargs) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/slackened/surface/message.rb', line 27

def post(url: Slackened.configuration.webhook_url, **kwargs)
	layout(**kwargs)

	blocks = payload.dup

	response = Slackened::HTTP.post(
		blocks:,
		url:
	)

	# clear the blocks after each post
	@builder.setup!

	Slackened::Response.new(response:, blocks:)
end

.post!(url: Slackened.configuration.webhook_url, **kwargs) ⇒ Object

Raises:



43
44
45
46
47
48
49
50
# File 'lib/slackened/surface/message.rb', line 43

def post!(url: Slackened.configuration.webhook_url, **kwargs)
	response = post(url:, **kwargs)

	# https://api.slack.com/messaging/webhooks#handling_errors
	raise Slackened::Error, response unless response.ok?

	response
end