Module: CPEE::Message

Defined in:
lib/cpee/message.rb

Constant Summary collapse

WHO =
'cpee'
TYPE =
'instance'

Class Method Summary collapse

Class Method Details

.send(type, event, cpee, instance, instance_uuid, instance_name, content = {}, backend) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cpee/message.rb', line 21

def self::send(type, event, cpee, instance, instance_uuid, instance_name, content={}, backend)
  topic = ::File::dirname(event)
  name = ::File::basename(event)
  payload = {
    WHO => cpee,
    TYPE + '-url' => File.join(cpee,instance.to_s),
    TYPE => instance,
    'topic' => topic,
    'type' => type,
    'name' => name,
    'timestamp' =>  Time.now.xmlschema(3),
    'content' => content
  }
  payload[TYPE + '-uuid'] = instance_uuid if instance_uuid
  payload[TYPE + '-name'] = instance_name if instance_name
  backend.publish(type.to_s + ':' + event,
    instance.to_s + ' ' +
    JSON::generate(payload)
  )
end

.send_url(type, event, cpee, content = {}, backend) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cpee/message.rb', line 42

def self::send_url(type, event, cpee, content={}, backend)
  EM.defer do
    topic = ::File::dirname(event)
    name = ::File::basename(event)
    payload = {
      WHO => cpee,
      'topic' => topic,
      'type' => type,
      'name' => name,
      'timestamp' =>  Time.now.xmlschema(3),
      'content' => content
    }
    client = Riddl::Client.new(backend)
    p backend
    client.post [
      Riddl::Parameter::Simple::new('type',type),
      Riddl::Parameter::Simple::new('topic',topic),
      Riddl::Parameter::Simple::new('event',name),
      Riddl::Parameter::Complex::new('notification','application/json',JSON::generate(payload))
    ]
    p backend + '------'
  end
end