lib/pushpop-slack.rb in pushpop-slack-0.1.0 vs lib/pushpop-slack.rb in pushpop-slack-0.1.1
- old
+ new
@@ -12,10 +12,14 @@
Pushpop::Job.register_plugin(PLUGIN_NAME, self)
attr_accessor :_channel
attr_accessor :_username
attr_accessor :_message
+ attr_accessor :_icon
+ attr_accessor :_icon_type
+ attr_accessor :_attachments
+ attr_accessor :_unfurl
def run(last_response=nil, step_responses=nil)
configure(last_response, step_responses)
@@ -46,10 +50,22 @@
if _username
opts['username'] = _username
end
+ if _icon && _icon_type
+ opts["icon_#{_icon_type}"] = _icon
+ end
+
+ if _attachments
+ opts['attachments'] = _attachments
+ end
+
+ if _unfurl
+ opts['unfurl_links'] = true
+ end
+
return opts
end
def channel(channel)
self._channel = channel
@@ -58,10 +74,41 @@
def username(username)
self._username = username
end
def message(message)
- self._message = message
+ self._message = ::Slack::Notifier::LinkFormatter.format(message)
+ end
+
+ def attachment(attachment)
+ self._attachments = [] unless self._attachments
+
+ self._attachments.push(attachment)
+ end
+
+ 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
+
+ def unfurl(should = true)
+ self._unfurl = should
end
def configure(last_response=nil, step_responses=nil)
self.instance_exec(last_response, step_responses, &block)
end