nine_one_one 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc1d95a66273659ccfaac813c2324de176a55e5b
4
- data.tar.gz: 9d32c8fcf3095ff38f665af3b9ed540b8d2a542a
3
+ metadata.gz: 776f59439067b38ac22ab874e2353f77a7022a56
4
+ data.tar.gz: 9bf0a5b2a23a317d6fffe9f43da635be80b90238
5
5
  SHA512:
6
- metadata.gz: 8e95ffe1c79216decaace3931588d690365fe1ca98a47eae7f5a5496f52c65ec97382a457acde2dc9e20dfce6a5e8efe793e51ba2b02c06bf34e4a0697859f01
7
- data.tar.gz: 08b510ec8a4af089217c21092c502396c95d6923ef2051c0b671521e23518bdf05658677860f7b26bbbc9116b983519d4b3c1faef06e40b292c238092961afed
6
+ metadata.gz: 30af137d4bdd8fb9cc9b34d2273e8f2a30933db66ec47ef75951d20cd95dea9d2b374fc8565653271a25f9f221e2b6bdaefb5b7203907ae1660e3d90e709826a
7
+ data.tar.gz: 9b2690b1b38ac8a95ba9b9d9909bfdbc882fc27fae1c1fc5d923110ebee523f9b5cd7cb68f3c0cee835c53bc5e998803b32d6c10a9e2d6070b9915dc7e4863ae
data/README.md CHANGED
@@ -40,6 +40,12 @@ NineOneOne.configure do |config|
40
40
  config.slack_enabled = true
41
41
  config.slack_webhook_url = 'https://hooks.slack.com/services/XXX/YYY/ZZZ'
42
42
 
43
+ # Customize Slack username. If left blank NineOneOne will use the username specified in the Slack webkhook integration
44
+ config.slack_username = 'NineOneOne'
45
+
46
+ # Customize Slack channel. If left blank NineOneOne will use the channel specified in the Slack webkhook integration
47
+ config.slack_channel = '#my-notifications'
48
+
43
49
  # Use custom logger - it must implement .info(string) and .error(string) methods
44
50
  # Defaults to Logger.new(STDOUT)
45
51
  config.logger = Logger.new('incidents.log')
@@ -2,7 +2,9 @@ require 'logger'
2
2
 
3
3
  module NineOneOne
4
4
  class Configuration
5
- attr_accessor :send_pagers, :pager_duty_integration_key, :slack_enabled, :slack_webhook_url, :logger
5
+ attr_accessor :send_pagers, :pager_duty_integration_key,
6
+ :slack_channel, :slack_enabled, :slack_username, :slack_webhook_url,
7
+ :logger
6
8
 
7
9
  def initialize
8
10
  self.send_pagers = false
@@ -15,6 +17,7 @@ module NineOneOne
15
17
  validate_logger
16
18
  validate_pager_duty_key
17
19
  validate_slack_enabled
20
+ validate_slack_opts
18
21
  end
19
22
 
20
23
  private
@@ -50,6 +53,16 @@ module NineOneOne
50
53
  raise ConfigurationError, 'Incorrect Slack webhook URL'
51
54
  end
52
55
  end
56
+
57
+ def validate_slack_opts
58
+ unless slack_username.nil? || slack_username.is_a?(String)
59
+ raise ConfigurationError, "Illegal 'slack_username' value: #{slack_username}"
60
+ end
61
+
62
+ unless slack_channel.nil? || slack_channel.is_a?(String)
63
+ raise ConfigurationError, "Illegal 'slack_channel' value: #{slack_channel}"
64
+ end
65
+ end
53
66
  # rubocop:enable Style/GuardClause
54
67
  end
55
68
  end
@@ -1,14 +1,17 @@
1
1
  module NineOneOne
2
2
  class SlackService
3
- def initialize(webhook_url)
3
+ def initialize(webhook_url, opts = {})
4
4
  uri = URI(webhook_url)
5
5
 
6
- @http = Http.new(uri.host, uri.scheme)
7
- @path = uri.path
6
+ @channel = opts[:channel]
7
+ @http = opts[:http] || Http.new(uri.host, uri.scheme)
8
+ @path = uri.path
9
+ @username = opts[:username]
8
10
  end
9
11
 
10
12
  def notify(message)
11
13
  body = request_body(message)
14
+
12
15
  headers = { 'Content-Type' => 'application/json' }
13
16
 
14
17
  response = http.post(path, body, headers)
@@ -18,10 +21,15 @@ module NineOneOne
18
21
 
19
22
  private
20
23
 
21
- attr_reader :http, :path
24
+ attr_reader :channel, :http, :path, :username
22
25
 
23
26
  def request_body(message)
24
- { text: message }.to_json
27
+ body = { text: message }
28
+
29
+ body[:channel] = channel unless channel.nil?
30
+ body[:username] = username unless username.nil?
31
+
32
+ body.to_json
25
33
  end
26
34
  end
27
35
  end
@@ -1,3 +1,3 @@
1
1
  module NineOneOne
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/nine_one_one.rb CHANGED
@@ -17,7 +17,8 @@ module NineOneOne
17
17
 
18
18
  def self.notification_service
19
19
  if config.slack_enabled
20
- SlackService.new(config.slack_webhook_url)
20
+ SlackService.new(config.slack_webhook_url, username: config.slack_username,
21
+ channel: config.slack_channel)
21
22
  else
22
23
  LogService.new(config.logger)
23
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nine_one_one
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kacper Madej
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-02-02 00:00:00.000000000 Z
12
+ date: 2017-03-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler