Module: NotifyPush::Receiver
- Defined in:
- lib/notify-push.rb
Overview
MODULE->RECEIVER —————————–
Class Method Summary collapse
- .ensure_compatibility ⇒ Object
-
.ensure_dependencies ⇒ Object
——————————————– ENSURANCES ——————————— ——————————————–.
-
.notify(title: "notify-push", subtitle: nil, message:) ⇒ Object
——————————————– NOTIFY ————————————- ——————————————–.
-
.pid_lock ⇒ Object
——————————————– PID —————————————- ——————————————–.
-
.start ⇒ Object
——————————————– START ————————————– ——————————————–.
Class Method Details
.ensure_compatibility ⇒ Object
126 127 128 |
# File 'lib/notify-push.rb', line 126 def self.ensure_compatibility OS.mac? or "The notify-push receiver only supports OS X." end |
.ensure_dependencies ⇒ Object
ENSURANCES ———————————
122 123 124 |
# File 'lib/notify-push.rb', line 122 def self.ensure_dependencies system "command -v terminal-notifier >/dev/null 2>&1" or raise "'terminal-notifier' cannot be found." end |
.notify(title: "notify-push", subtitle: nil, message:) ⇒ Object
NOTIFY ————————————-
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/notify-push.rb', line 133 def self.notify(title: "notify-push", subtitle: nil, message:) args = [ "-message", , "-title", title ] args.concat ["-subtitle", subtitle] unless subtitle.blank? system "terminal-notifier", *args end |
.pid_lock ⇒ Object
PID —————————————-
113 114 115 116 117 |
# File 'lib/notify-push.rb', line 113 def self.pid_lock require "pidfile" PidFile.new end |
.start ⇒ Object
START ————————————–
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/notify-push.rb', line 148 def self.start() ensure_compatibility ensure_dependencies pid_lock require "pusher-client" socket = PusherClient::Socket.new configuration.pusher.key, { secure: true } # Subscribe to main channel socket.subscribe(CHANNEL_NAME) # Bind to the main channel event socket[CHANNEL_NAME].bind("notification") do |data| begin data = JSON.parse(data, symbolize_names: true) notify **data rescue => exception puts "Warning: Failed to process notification." puts exception ensure puts "----------" puts data end end # Bind to the error event socket.bind("pusher:error") do |data| puts "----------" puts "Warning: Pusher Error" puts data end # Connect socket.connect 0 end |