Class: Rnotifier::Notifier

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

Class Method Summary collapse

Class Method Details

.connectionObject



5
6
7
8
9
# File 'lib/rnotifier/notifier.rb', line 5

def connection
  @connection ||= Faraday.new(:url => Config.api_host) do |faraday|
    faraday.adapter Faraday.default_adapter  
  end
end

.send(data, path) ⇒ Object



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

def send(data, path)
  response = self.connection.post do |req|
    req.url(path)
    req.headers['Content-Type'] = 'application/json'
    req.headers['Api-Key'] = Config.api_key
    req.options[:timeout] =  Config[:http_open_timeout]
    req.options[:open_timeout] = Config[:http_read_timeout]
    req.body =  MultiJson.dump(data)
  end

  return true if response.status == 200
  Rlogger.error("[RNOTIFIER SERVER] Response Status:#{response.status}")
  false
ensure
  Rnotifier.clear_context
end