Sha256: aadac851ce2d2a6335843e49c4aec9176debcac2ade077c1ebb9f6ebec7f69bc

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

class Backend

  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 {
	Thread.current.report_on_exception = false
        # Wait for thread completion of thread is not the current thread
        Thread.list.each{ |t| t.join unless t == Thread.current }
        # 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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
firetail-0.0.1.pre.alpha lib/backend.rb