Class: NotificationsHandler

Inherits:
Riddl::Utils::Notifications::Producer::HandlerBase
  • Object
show all
Defined in:
lib/cpee/handler_notifications.rb

Overview

This file is part of CPEE.

CPEE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CPEE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CPEE (file COPYING in the main directory). If not, see <www.gnu.org/licenses/>.

Instance Method Summary collapse

Instance Method Details

#createObject



35
36
37
38
# File 'lib/cpee/handler_notifications.rb', line 35

def create
  @data.unserialize_notifications!(:cre,@key)
  @data.notify('handler/change', :instance => @data.instance)
end

#deleteObject



39
40
41
42
# File 'lib/cpee/handler_notifications.rb', line 39

def delete
  @data.unserialize_notifications!(:del,@key)
  @data.notify('handler/change', :instance => @data.instance)
end

#updateObject



43
44
45
46
# File 'lib/cpee/handler_notifications.rb', line 43

def update
  @data.unserialize_notifications!(:upd,@key)
  @data.notify('handler/change', :instance => @data.instance)
end

#ws_closeObject



19
20
21
22
# File 'lib/cpee/handler_notifications.rb', line 19

def ws_close
  @data.unserialize_notifications!(:del,@key)
  @data.notify('handler/change', :instance => @data.instance)
end

#ws_message(data) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cpee/handler_notifications.rb', line 23

def ws_message(data)
  begin
    doc = XML::Smart::string(data)
    callback = doc.find("string(/vote/@id)")
    result = doc.find("string(/vote)")
    @data.callbacks[callback].callback(result == 'true' ? true : false)
    @data.callbacks.delete(callback)
  rescue
    puts "Invalid message over websocket"
  end
end

#ws_open(socket) ⇒ Object



16
17
18
# File 'lib/cpee/handler_notifications.rb', line 16

def ws_open(socket)
  @data.add_websocket(@key,socket)
end