Class: Slack::Notifier
- Inherits:
-
Object
- Object
- Slack::Notifier
- Defined in:
- lib/slack-notifier.rb,
lib/slack-notifier/config.rb,
lib/slack-notifier/version.rb,
lib/slack-notifier/util/escape.rb,
lib/slack-notifier/util/http_client.rb,
lib/slack-notifier/payload_middleware.rb,
lib/slack-notifier/util/link_formatter.rb,
lib/slack-notifier/payload_middleware/at.rb,
lib/slack-notifier/payload_middleware/base.rb,
lib/slack-notifier/payload_middleware/stack.rb,
lib/slack-notifier/payload_middleware/channels.rb,
lib/slack-notifier/payload_middleware/format_message.rb,
lib/slack-notifier/payload_middleware/format_attachments.rb
Defined Under Namespace
Modules: Util Classes: APIError, Config, PayloadMiddleware
Constant Summary collapse
- VERSION =
rubocop:disable Style/RedundantFreeze
"2.4.0".freeze
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(webhook_url, options = {}, &block) ⇒ Notifier
constructor
A new instance of Notifier.
- #ping(message, options = {}) ⇒ Object
- #post(payload = {}) ⇒ Object
Constructor Details
#initialize(webhook_url, options = {}, &block) ⇒ Notifier
Returns a new instance of Notifier.
16 17 18 19 20 21 22 23 24 |
# File 'lib/slack-notifier.rb', line 16 def initialize webhook_url, ={}, &block @endpoint = URI.parse webhook_url config.http_client(.delete(:http_client)) if .key?(:http_client) config.defaults config.instance_exec(&block) if block_given? middleware.set config.middleware end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
14 15 16 |
# File 'lib/slack-notifier.rb', line 14 def endpoint @endpoint end |
Instance Method Details
#config ⇒ Object
26 27 28 |
# File 'lib/slack-notifier.rb', line 26 def config @_config ||= Config.new end |
#ping(message, options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/slack-notifier.rb', line 30 def ping , ={} if .is_a?(Hash) = else [:text] = end post end |
#post(payload = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/slack-notifier.rb', line 40 def post payload={} params = {} client = payload.delete(:http_client) || config.http_client payload = config.defaults.merge(payload) params[:http_options] = payload.delete(:http_options) if payload.key?(:http_options) middleware.call(payload).map do |pld| params[:payload] = pld.to_json client.post endpoint, params end end |