Class: Honeybadger::CLI::Notify Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Helpers::BackendCmd
Defined in:
lib/honeybadger/cli/notify.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Methods included from Helpers::BackendCmd

#error_message

Constructor Details

#initialize(options, args, config) ⇒ Notify

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Notify.



14
15
16
17
18
19
# File 'lib/honeybadger/cli/notify.rb', line 14

def initialize(options, args, config)
  @options = options
  @args = args
  @config = config
  @shell = ::Thor::Base.shell.new
end

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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
47
48
49
50
51
52
53
54
# File 'lib/honeybadger/cli/notify.rb', line 21

def run
  payload = {
    api_key: config.get(:api_key),
    notifier: NOTIFIER,
    error: {
      class: options['class'],
      message: options['message']
    },
    request: {},
    server: {
      project_root: Dir.pwd,
      environment_name: config.get(:env),
      time: Time.now,
      stats: Util::Stats.all
    }
  }

  payload[:error][:fingerprint] = Digest::SHA1.hexdigest(options['fingerprint']) if option?('fingerprint')
  payload[:error][:tags] = options['tags'].to_s.strip.split(',').map(&:strip) if option?('tags')

  payload[:request][:component] = options['component'] if option?('component')
  payload[:request][:action] = options['action'] if option?('action')
  payload[:request][:url] = options['url'] if option?('url')

  payload.delete(:request) if payload[:request].empty?

  response = config.backend.notify(:notices, payload)
  if response.success?
    say("Error notification complete.", :green)
  else
    say(error_message(response), :red)
    exit(1)
  end
end