lib/notifier/gntp.rb in notifier-0.2.1 vs lib/notifier/gntp.rb in notifier-0.4.0

- old
+ new

@@ -1,22 +1,37 @@ module Notifier - module GNTP - extend self - + module GNTP extend self def supported? - begin - require "ruby_gntp" unless defined?(::GNTP) - true - rescue LoadError - false - end + Timeout.timeout(1) { TCPSocket.new(host, port).close } + true + rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Timeout::Error + false end + def port + ENV.fetch("GNTP_PORT", 23053) + end + + def host + ENV["GNTP_HOST"] || ssh_connection || "127.0.0.1" + end + + def ssh_connection + ENV["SSH_CONNECTION"][/^([^ ]+)/, 1] if ENV["SSH_CONNECTION"] + end + def notify(options) - ::GNTP.notify( - :title => options[:title], - :text => options[:message], - :icon => options[:image] - ) + gntp = Adapters::GNTP.new({ + :name => "test_notifier", + :host => host, + :port => port + }) + + gntp.notify({ + :name => "status", + :title => options[:title], + :message => options[:message], + :icon => options[:image] + }) end end end