Class: Spanx::Notifier::Slack
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #enabled? ⇒ Boolean
- #endpoint ⇒ Object
-
#initialize(config) ⇒ Slack
constructor
A new instance of Slack.
- #publish(blocked_ip) ⇒ Object
Constructor Details
#initialize(config) ⇒ Slack
Returns a new instance of Slack.
10 11 12 |
# File 'lib/spanx/notifier/slack.rb', line 10 def initialize(config) @config = config[:slack] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/spanx/notifier/slack.rb', line 8 def config @config end |
Instance Method Details
#enabled? ⇒ Boolean
37 38 39 |
# File 'lib/spanx/notifier/slack.rb', line 37 def enabled? config && config[:enabled] end |
#endpoint ⇒ Object
30 31 32 33 34 35 |
# File 'lib/spanx/notifier/slack.rb', line 30 def endpoint return nil unless enabled? token = config[:token] base_url = config[:base_url] URI.parse("#{base_url}/services/hooks/incoming-webhook?token=#{token}") end |
#publish(blocked_ip) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/spanx/notifier/slack.rb', line 14 def publish blocked_ip return nil unless enabled? = (blocked_ip) uri = endpoint http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(uri.request_uri, {'Content-Type' => 'text/json'}) request.body = { text: }.to_json http.request(request) end |