Module: Slack500

Defined in:
lib/slack_500.rb,
lib/slack_500/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

ROOT_PATH =
File.expand_path "../../", __FILE__
VERSION =
"0.1.5"
@@pretext =
nil
@@title =
nil
@@color =
nil
nil
@@webhook_url =
nil

Class Method Summary collapse

Class Method Details

.post(request, exception, params = {}) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/slack_500.rb', line 41

def self.post (request, exception, params = {})
  url = self.webhook_url
  begin
    uri = URI.parse(url)
  rescue
    Rails.logger.error '** Slack500:: invalid Webhook URL.'
    return
  end

  text = "#{request.method} #{request.url} (#{request.user_agent}) : #{request.query_parameters}\n#{exception.message}\n#{exception.backtrace.map {|s| s.gsub(Rails.root.to_s, '')}.join("\n")}"

  default_params = {
      pretext: self.pretext,
      title: self.pretext,
      color: self.color,
      footer: self.footer
  }

  attachments = default_params.merge(params)
  attachments[:text] = text
  attachments[:title] = "#{request.parameters[:controller]}##{request.parameters[:action]} - #{attachments[:title]}"

  params = {
      attachments: [attachments]
  }

  begin
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.start do
      request = Net::HTTP::Post.new(uri.path)
      request.set_form_data(payload: params.to_json)
      http.request(request)
    end
  rescue => e
    Rails.logger.error "** Slack500:: #{e.full_message}."
  end
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Slack500)

    the object that the method was called on



22
23
24
# File 'lib/slack_500.rb', line 22

def self.setup
  yield self
end