Class: GuardWebHookNotifier::Notifier

Inherits:
Guard::Notifier::Base
  • Object
show all
Defined in:
lib/guard-webhook-notifier/notifier.rb

Constant Summary collapse

DEFAULTS =
{
  user_agent: "GuardWebHookNotifier/#{VERSION}",
  url: "http://10.0.2.2:4001/"
}

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Notifier

Returns a new instance of Notifier.



12
13
14
15
# File 'lib/guard-webhook-notifier/notifier.rb', line 12

def initialize(opts = {})
  super
  @options = DEFAULTS.merge(opts)
end

Instance Method Details

#notify(message, opts = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/guard-webhook-notifier/notifier.rb', line 17

def notify(message, opts = {})
  super
  conn = Faraday.new(url: opts[:url])
  conn.post do |req|
    req.headers["Content-Type"] = "application/json"
    req.headers["User-Agent"] = opts[:user_agent]
    req.body = { message: message, options: opts }.to_json
  end
end