Class: Captivus::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/captivus/notifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Notifier

Returns a new instance of Notifier.



7
8
9
# File 'lib/captivus/notifier.rb', line 7

def initialize(config)
  @config = config
end

Instance Method Details

#==(other) ⇒ Object



26
27
28
# File 'lib/captivus/notifier.rb', line 26

def ==(other)
  other.is_a?(Notifier) && config == other.config
end

#notify(payload) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/captivus/notifier.rb', line 11

def notify(payload)
  return if config.development_environments.include?(config.environment)

  connection = Faraday.new(:url => "#{config.scheme}://#{config.host}") do |faraday|
    faraday.request :hmac_authentication, config.api_key, config.api_secret_key, {:service_id => 'Captivus'}
    faraday.adapter :net_http
  end

  connection.post do |request|
    request.headers['Content-Type'] = 'application/json; charset=UTF-8'
    request.url '/events'
    request.body = Captivus::Util.hash_to_json(payload)
  end
end