Module: NotifyPush::Receiver
- Defined in:
- lib/notify-push.rb
Overview
MODULE->RECEIVER —————————–
Class Method Summary collapse
-
.notify(title: "notify-push", subtitle: nil, message:) ⇒ Object
——————————————– NOTIFY ————————————- ——————————————–.
-
.pid_lock ⇒ Object
——————————————– PID —————————————- ——————————————–.
-
.start ⇒ Object
——————————————– START ————————————– ——————————————–.
Class Method Details
.notify(title: "notify-push", subtitle: nil, message:) ⇒ Object
NOTIFY ————————————-
146 147 148 149 150 151 152 153 154 |
# File 'lib/notify-push.rb', line 146 def self.notify(title: "notify-push", subtitle: nil, message:) = "#{subtitle} - #{message}" if subtitle Notifier.notify({ title: title, message: }) end |
.pid_lock ⇒ Object
PID —————————————-
137 138 139 140 141 |
# File 'lib/notify-push.rb', line 137 def self.pid_lock require "pidfile" PidFile.new end |
.start ⇒ Object
START ————————————–
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 193 194 195 196 197 198 199 200 |
# File 'lib/notify-push.rb', line 159 def self.start() 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 |