Class: ExceptionNotifier::LineNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_notification_line_notify.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ LineNotifier



7
8
9
10
11
12
# File 'lib/exception_notification_line_notify.rb', line 7

def initialize args = {}
  args = args.symbolize_keys

  @line_notify_token = args.fetch(:line_notify_token, nil)

end

Instance Method Details

#call(exception, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/exception_notification_line_notify.rb', line 14

def call(exception, options={})
  
  @request = ActionDispatch::Request.new(options[:env])
  @backtrace = exception.backtrace.first
  @exception_message = exception.message

  @request_section = {
    parameters: @request.filtered_parameters.inspect,
    method: @request.request_method,
    ip: @request.remote_ip,
    root: Rails.root.to_s,
  }.map{|k, v| "[#{k}] \n#{v}"}.join("\n")

  @session_section = @request.session.to_hash.inspect
  

  @message = %Q(
    \n #{@request.url}
    \n #{@backtrace}
    \n======Request=====
    \n#{@request_section}
    \n======Session=====
    \n#{@session_section}
  )

  if @line_notify_token
    begin
      @response = RestClient.post 'https://notify-api.line.me/api/notify', {message: @message}, { :Authorization => "Bearer #{@line_notify_token}"}
    rescue => e
      puts e
    end
  end
end