Module: Slack500

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

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.3"
@@pretext =
nil
@@title =
nil
@@color =
nil
nil
@@webhook_url =
nil

Class Method Summary collapse

Class Method Details

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



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/slack_500.rb', line 27

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



8
9
10
# File 'lib/slack_500.rb', line 8

def self.setup
  yield self
end