Class: Backend

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

Class Method Summary collapse

Class Method Details

.send_now(payload, options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/backend.rb', line 3

def self.send_now(payload, options)
  #Firetail.logger.debug "running backend"
  # Parse it as URI
  uri = URI(options[:url])

  # Create a new request
  http = Net::HTTP.new(uri.hostname, uri.port)
  #http.set_debug_output($stdout) # Use this is you want to see the data output
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
  http.read_timeout = options[:network_timeout]

  begin
    # Create a new request
    req = CustomPost.new(uri.path,
    {
      'content-type': 'application/nd-json',
      'x-ft-api-key': options[:api_key]
    })

    req.body = payload
    # Create new thread
    Thread.new {
      # Send the request
      request = http.request(req)
    }
    #Firetail.logger.debug "response from firetail: #{res}"
  rescue StandardError => e
    Firetail.logger.info "Firetail HTTP Request failed (#{e.message})"
  end
end