class PoringBackup::Notifiers::Slack
Attributes
channel_name[R]
on_envs[R]
webhook_uri[R]
Public Class Methods
new(setting, &block)
click to toggle source
Calls superclass method
PoringBackup::Notifier::new
# File lib/poring_backup/notifiers/slack.rb, line 8 def initialize setting, &block super instance_eval(&block) if block_given? end
Public Instance Methods
channel(name)
click to toggle source
# File lib/poring_backup/notifiers/slack.rb, line 23 def channel name @channel_name = name end
notify!()
click to toggle source
Calls superclass method
PoringBackup::Notifier#notify!
# File lib/poring_backup/notifiers/slack.rb, line 31 def notify! super return on_disabled unless on_envs.include?(Rails.env) or on_envs.empty? options = { :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, :body => URI.encode_www_form(:payload => JSON.dump(data)) } # options.merge!(:expects => 200) # raise error if unsuccessful response = Excon.post(webhook_uri, options) if (response.data[:body] == 'ok') PoringBackup.logger.info "Slack notify : #{on_success}" on_success else PoringBackup.logger.warn "Slack notify : #{on_failure(response.data[:body])}" on_failure(response.data[:body]) end end
notify_message()
click to toggle source
# File lib/poring_backup/notifiers/slack.rb, line 53 def notify_message @notify_message ||= channel_name end
only_env(envs=[])
click to toggle source
# File lib/poring_backup/notifiers/slack.rb, line 27 def only_env envs=[] @on_envs = envs.map(&:to_s) end
webhook(url)
click to toggle source
notifer :Slack do
webhook 'url' channel '#channel' only_env [:development, :production]
end
# File lib/poring_backup/notifiers/slack.rb, line 19 def webhook url @webhook_uri = url end
Private Instance Methods
data()
click to toggle source
# File lib/poring_backup/notifiers/slack.rb, line 58 def data @data = { :channel => channel_name, :username => 'Poring Backup', :icon_emoji => ":ghost:", :attachments => [ { :fallback => "more information at <https://github.com/piya23300/poring_backup|poring_backup gem>", :pretext => "backup at #{setting.created_at}", :title => "#{setting.app_name}", # :title_link => "https://groove.hq/path/to/ticket/1943", # :text => "Help! I tried to reset my password but nothing happened!", :color => "#7CD197", :fields => [ { :title => "Environment", :value => Rails.env, :short => true }, { :title => "Contect", :value => '<https://github.com/piya23300/poring_backup|poring_backup gem>', :short => true }, { :title => "Databases", :value => databases_list, :short => false }, { :title => "Storages", :value => storages_list, :short => false }, { :title => "Notifier", :value => notifiers_list, :short => false } ] } ] } end