Sha256: a2416ec1b171cb0aca6242899f9e1a5046603564fba5982eebd61f7d790fb195

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

require 'config'

module Tracer
  module Server

    def self.log(notice_hash)
      send("http://#{Settings.tracer.host}:#{Settings.tracer.port}/api/v3/projects/#{Settings.tracer.project}/notices?api_key=#{Settings.tracer.api_key}", notice_hash)
    end


    def self.log_changes(changes_hash)
      Rails.logger.debug "Log change: #{changes_hash.inspect}"
      send("http://#{Settings.tracer.host}:#{Settings.tracer.port}/api/v3/projects/#{Settings.tracer.project}/changes?api_key=#{Settings.tracer.api_key}", changes_hash)
    end


    private


    def self.send(url, data)
      uri = URI.parse(url)

      Net::HTTP.start(uri.host, uri.port, read_timeout: 20) do |http|
        http.request_post(uri.path + '?' + uri.query, JSON.dump(data), 'Content-Type' => 'text/xml; charset=utf-8') do |response|
          return true if Net::HTTPNoContent === response
          Rails.logger.error "Tracer request url: #{url}"
          Rails.logger.error "Tracer response #{response.inspect}: #{response.body.inspect}"
        end
      end
    rescue Exception => e
      Rails.logger.error "Tracer request url: #{url}"
      Rails.logger.error "Tracer exception #{e.inspect}: #{e.message}"
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tracer_client-0.2.1 lib/tracer_client/server.rb
tracer_client-0.1.5 lib/tracer_client/server.rb
tracer_client-0.1.4 lib/tracer_client/server.rb
tracer_client-0.1.3 lib/tracer_client/server.rb
tracer_client-0.1.2 lib/tracer_client/server.rb
tracer_client-0.1.1 lib/tracer_client/server.rb
tracer_client-0.1.0 lib/tracer_client/server.rb