Sha256: 9f2bd26fde9eb15beb895274438db840b916d5133d78e22593a8a1ba52e9b3d2

Contents?: true

Size: 1.18 KB

Versions: 1

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/project/#{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

1 entries across 1 versions & 1 rubygems

Version Path
tracer_client-0.3.0 lib/tracer_client/server.rb