9
10
11
12
13
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
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/erorr/cli.rb', line 9
def run
program :name, 'erorr'
program :version, Erorr::VERSION
program :description, 'Ruby/Rails client for erorr.app'
never_trace!
command 'setup' do |c|
c.syntax = 'erorr setup API-KEY'
c.description = 'Creates erorr.app\'s configuration file config/erorr.yml and populates it with the provided API-KEY.'
c.action do |args, _options|
api_key = args[0]
if File.exist? config_file_path
say_error 'Erorr config file already exists.'
exit(0)
end
unless api_key
say_error 'Please provide an API KEY.'
exit(0)
end
configuration_file = <<~YAML
---
api_key: #{api_key}
YAML
File.open(config_file_path, 'w') { |file| file.write(configuration_file) }
say_success <<~MSG
erorr.app client configured successfully!
Test the integration by sending a test notification:
bundle exec erorr test-notify
If all is well, you'll see the test notification in https://erorr.app.
MSG
end
end
command 'test-notify' do |c|
c.syntax = 'erorr test-notify'
c.description = 'Send a test notification to erorr.app'
c.action do |args, _options|
require File.expand_path('config/environment')
Erorr.configure do |config|
config.enabled_for << 'development'
end
begin
raise ErorrTestException.new('Test message')
rescue ErorrTestException => e
if Erorr.notify e, location: 'erorr test-notify'
say_success 'Test notification sent successfully.'
else
say_error 'Test notification could not be delivered.'
end
Erorr::Transport::HTTPAsync.shut_down
end
end
end
run!
end
|