lib/tracebin/reporter.rb in tracebin-0.0.10 vs lib/tracebin/reporter.rb in tracebin-0.0.11
- old
+ new
@@ -1,6 +1,5 @@
-require 'net/https'
require 'json'
require 'concurrent'
module Tracebin
class Reporter
@@ -9,10 +8,16 @@
def initialize(storage = Tracebin::Agent.storage, config = Tracebin::Agent.config, logger = Tracebin::Agent.logger)
@logger = logger
@config = config
@storage = storage
+ if config.enable_ssl
+ require 'net/https'
+ else
+ require 'net/http'
+ end
+
host = Tracebin::Agent.config.host
path = Tracebin::Agent.config.report_path
@uri = URI("#{host}/#{path}")
@bin_id = Tracebin::Agent.config.bin_id
@@ -42,11 +47,14 @@
def send_data(payload)
logger.info 'TRACEBIN: Sending analytics data to the server.'
logger.info "TRACEBIN: Sending #{payload.length} samples to: #{@uri}"
http = Net::HTTP.new @uri.host, @uri.port
- http.use_ssl = true
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+
+ if config.enable_ssl
+ http.use_ssl = true
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
body = {
bin_id: @bin_id,
report: payload
}.to_json