Class: FDE::Slack::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/slack/message.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

BLUE =
'#BDE5F8'.freeze
GREEN =
'#DFF2BF'.freeze
YELLOW =
'#FEEFB3'.freeze
RED =
'#FFBABA'.freeze
RETRY_LIMIT =
1
TOO_MANY_REQUESTS_STATUS_CODE =
"429"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, fields, options = {}) ⇒ Message

Returns a new instance of Message.



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

def initialize(title, fields, options = {})
  @title = title
  @fields = fields
  if options[:title_link]
    @title_link = options[:title_link]
  end
  if options[:username]
    @username = options[:username] || 'FDE Slack Notifier'
  end
  if options[:author]
    @author = options[:author]
  end
  if options[:footer]
    @footer = options[:footer]
  end

  @retries = 0
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



16
17
18
# File 'lib/slack/message.rb', line 16

def author
  @author
end

#colorObject

Returns the value of attribute color.



16
17
18
# File 'lib/slack/message.rb', line 16

def color
  @color
end

#fieldsObject

Returns the value of attribute fields.



16
17
18
# File 'lib/slack/message.rb', line 16

def fields
  @fields
end

Returns the value of attribute footer.



16
17
18
# File 'lib/slack/message.rb', line 16

def footer
  @footer
end

#retriesObject (readonly)

Returns the value of attribute retries.



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

def retries
  @retries
end

#titleObject

Returns the value of attribute title.



16
17
18
# File 'lib/slack/message.rb', line 16

def title
  @title
end

#usernameObject

Returns the value of attribute username.



16
17
18
# File 'lib/slack/message.rb', line 16

def username
  @username
end

Instance Method Details

#add_field(field) ⇒ Object



68
69
70
# File 'lib/slack/message.rb', line 68

def add_field(field)
  @fields << field.to_h
end

#deliver(channel, level: :info) ⇒ Object



44
45
46
# File 'lib/slack/message.rb', line 44

def deliver(channel, level: :info)
  send(level, channel)
end

#error(channel) ⇒ Object



63
64
65
66
# File 'lib/slack/message.rb', line 63

def error(channel)
  @color = RED
  send_message(channel)
end

#info(channel) ⇒ Object



48
49
50
51
# File 'lib/slack/message.rb', line 48

def info(channel)
  @color = BLUE
  send_message(channel)
end

#success(channel) ⇒ Object



53
54
55
56
# File 'lib/slack/message.rb', line 53

def success(channel)
  @color = GREEN
  send_message(channel)
end

#warning(channel) ⇒ Object



58
59
60
61
# File 'lib/slack/message.rb', line 58

def warning(channel)
  @color = YELLOW
  send_message(channel)
end