Class: Sinatra::Slack::Helpers::SlackResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/slack/helpers/slack_response.rb

Overview

Represents a message sent to the Slack Channel.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback_id) ⇒ SlackResponse

Returns a new instance of SlackResponse.



12
13
14
15
16
17
18
# File 'lib/sinatra/slack/helpers/slack_response.rb', line 12

def initialize(callback_id)
  @callback_id = callback_id
  @text = nil
  @attachments = []
  @replace_original = true
  @mrkdwn = false
end

Instance Attribute Details

#mrkdwnObject

Returns the value of attribute mrkdwn.



10
11
12
# File 'lib/sinatra/slack/helpers/slack_response.rb', line 10

def mrkdwn
  @mrkdwn
end

#replace_originalObject

Returns the value of attribute replace_original.



10
11
12
# File 'lib/sinatra/slack/helpers/slack_response.rb', line 10

def replace_original
  @replace_original
end

#textObject

Returns the value of attribute text.



10
11
12
# File 'lib/sinatra/slack/helpers/slack_response.rb', line 10

def text
  @text
end

Instance Method Details

#attachment {|attachment| ... } ⇒ Object

Yields:



20
21
22
23
24
25
26
# File 'lib/sinatra/slack/helpers/slack_response.rb', line 20

def attachment
  return unless block_given?

  attachment = Helpers::Attachment.new(@callback_id)
  yield attachment
  @attachments << attachment
end

#to_jsonObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sinatra/slack/helpers/slack_response.rb', line 28

def to_json
  response = {}

  response[:text] = @text if @text
  response[:mrkdwn] = @mrkdwn
  response[:replace_original] = @replace_original

  response[:attachments] = @attachments.map(&:to_json) unless @attachments.empty?

  response.to_json
end