Module: Notifier::GNTP

Extended by:
GNTP
Included in:
GNTP
Defined in:
lib/notifier/gntp.rb

Instance Method Summary collapse

Instance Method Details

#hostObject


14
15
16
# File 'lib/notifier/gntp.rb', line 14

def host
  ENV["GNTP_HOST"] || ssh_connection || "127.0.0.1"
end

#notify(options) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/notifier/gntp.rb', line 22

def notify(options)
  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

#portObject


10
11
12
# File 'lib/notifier/gntp.rb', line 10

def port
  ENV.fetch("GNTP_PORT", 23053)
end

#ssh_connectionObject


18
19
20
# File 'lib/notifier/gntp.rb', line 18

def ssh_connection
  ENV["SSH_CONNECTION"][/^([^ ]+)/, 1] if ENV["SSH_CONNECTION"]
end

#supported?Boolean

Returns:

  • (Boolean)

3
4
5
6
7
8
# File 'lib/notifier/gntp.rb', line 3

def supported?
  Timeout.timeout(1) { TCPSocket.new(host, port).close }
  true
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Timeout::Error
  false
end