Class: Pushpop::Slack
- Inherits:
-
Step
- Object
- Step
- Pushpop::Slack
- Defined in:
- lib/pushpop-slack.rb,
lib/pushpop-slack/version.rb
Constant Summary collapse
- PLUGIN_NAME =
'slack'
- VERSION =
'0.2.3'
Instance Attribute Summary collapse
-
#_attachments ⇒ Object
Returns the value of attribute _attachments.
-
#_channel ⇒ Object
Returns the value of attribute _channel.
-
#_icon ⇒ Object
Returns the value of attribute _icon.
-
#_icon_type ⇒ Object
Returns the value of attribute _icon_type.
-
#_message ⇒ Object
Returns the value of attribute _message.
-
#_unfurl ⇒ Object
Returns the value of attribute _unfurl.
-
#_username ⇒ Object
Returns the value of attribute _username.
Instance Method Summary collapse
- #attachment(attachment) ⇒ Object
- #channel(channel) ⇒ Object
- #clear_settings ⇒ Object
- #configure(last_response = nil, step_responses = nil) ⇒ Object
- #icon(icon) ⇒ Object
- #message(message) ⇒ Object
- #options ⇒ Object
- #run(last_response = nil, step_responses = nil) ⇒ Object
- #send_message ⇒ Object
- #unfurl(should = true) ⇒ Object
- #username(username) ⇒ Object
Instance Attribute Details
#_attachments ⇒ Object
Returns the value of attribute _attachments.
19 20 21 |
# File 'lib/pushpop-slack.rb', line 19 def @_attachments end |
#_channel ⇒ Object
Returns the value of attribute _channel.
14 15 16 |
# File 'lib/pushpop-slack.rb', line 14 def _channel @_channel end |
#_icon ⇒ Object
Returns the value of attribute _icon.
17 18 19 |
# File 'lib/pushpop-slack.rb', line 17 def _icon @_icon end |
#_icon_type ⇒ Object
Returns the value of attribute _icon_type.
18 19 20 |
# File 'lib/pushpop-slack.rb', line 18 def _icon_type @_icon_type end |
#_message ⇒ Object
Returns the value of attribute _message.
16 17 18 |
# File 'lib/pushpop-slack.rb', line 16 def @_message end |
#_unfurl ⇒ Object
Returns the value of attribute _unfurl.
20 21 22 |
# File 'lib/pushpop-slack.rb', line 20 def _unfurl @_unfurl end |
#_username ⇒ Object
Returns the value of attribute _username.
15 16 17 |
# File 'lib/pushpop-slack.rb', line 15 def _username @_username end |
Instance Method Details
#attachment(attachment) ⇒ Object
99 100 101 102 103 |
# File 'lib/pushpop-slack.rb', line 99 def () self. = [] unless self. self..push() end |
#channel(channel) ⇒ Object
87 88 89 |
# File 'lib/pushpop-slack.rb', line 87 def channel(channel) self._channel = channel end |
#clear_settings ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/pushpop-slack.rb', line 38 def clear_settings self._username = nil self. = nil self._icon = nil self._icon_type = nil self. = nil self._unfurl = nil end |
#configure(last_response = nil, step_responses = nil) ⇒ Object
130 131 132 |
# File 'lib/pushpop-slack.rb', line 130 def configure(last_response=nil, step_responses=nil) self.instance_exec(last_response, step_responses, &block) end |
#icon(icon) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/pushpop-slack.rb', line 105 def icon(icon) if icon[0..3] == 'http' self._icon_type = 'url' self._icon = icon else self._icon_type = 'emoji' self._icon = icon # Make sure the emoji is wrapped in colons if self._icon[0] != ':' self._icon = ":#{self._icon}" end if self._icon[self._icon.length - 1] != ':' self._icon = "#{self._icon}:" end end self._icon end |
#message(message) ⇒ Object
95 96 97 |
# File 'lib/pushpop-slack.rb', line 95 def () self. = ::Slack::Notifier::LinkFormatter.format() end |
#options ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pushpop-slack.rb', line 57 def opts = {} if _channel if _channel[0] == '#' opts['channel'] = _channel else opts['channel'] = "##{_channel}" end end if _username opts['username'] = _username end if _icon && _icon_type opts["icon_#{_icon_type}"] = _icon end if opts['attachments'] = end if _unfurl opts['unfurl_links'] = true end return opts end |
#run(last_response = nil, step_responses = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/pushpop-slack.rb', line 22 def run(last_response=nil, step_responses=nil) ret = configure(last_response, step_responses) if else Pushpop.logger.debug("No slack message sent - message was not set") end clear_settings ret end |
#send_message ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/pushpop-slack.rb', line 47 def unless WEBHOOK_URL.nil? || WEBHOOK_URL.empty? notifier = ::Slack::Notifier.new WEBHOOK_URL notifier.ping , else Pushpop.logger.debug("Could not send slack message - SLACK_WEBHOOK_URL is nil or empty") end end |
#unfurl(should = true) ⇒ Object
126 127 128 |
# File 'lib/pushpop-slack.rb', line 126 def unfurl(should = true) self._unfurl = should end |
#username(username) ⇒ Object
91 92 93 |
# File 'lib/pushpop-slack.rb', line 91 def username(username) self._username = username end |