Sha256: 79be7a89d4b05029a7a9325ff0c40574f49ab90f7018797c4c64b5898709507b

Contents?: true

Size: 1.77 KB

Versions: 9

Compression:

Stored size: 1.77 KB

Contents

require 'digest'
require 'forwardable'
require 'honeybadger/cli/main'
require 'honeybadger/util/http'
require 'honeybadger/util/stats'

module Honeybadger
  module CLI
    class Notify
      extend Forwardable

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

      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?

        http = Util::HTTP.new(config)
        result = http.post('/v1/notices', payload)
        if result.code == '201'
          say("Error notification complete.", :green)
        else
          say("Invalid response from server: #{result.code}", :red)
          exit(1)
        end
      end

      private

      attr_reader :options, :args, :config

      def_delegator :@shell, :say

      def option?(key)
        options.has_key?(key) && options[key] != key
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
honeybadger-3.0.2 lib/honeybadger/cli/notify.rb
honeybadger-3.0.1 lib/honeybadger/cli/notify.rb
honeybadger-3.0.0 lib/honeybadger/cli/notify.rb
honeybadger-3.0.0.beta6 lib/honeybadger/cli/notify.rb
honeybadger-3.0.0.beta5 lib/honeybadger/cli/notify.rb
honeybadger-3.0.0.beta4 lib/honeybadger/cli/notify.rb
honeybadger-3.0.0.beta3 lib/honeybadger/cli/notify.rb
honeybadger-3.0.0.beta2 lib/honeybadger/cli/notify.rb
honeybadger-3.0.0.beta1 lib/honeybadger/cli/notify.rb