Class: SPSPub

Inherits:
Object
  • Object
show all
Includes:
SimplePubSub
Defined in:
lib/sps-pub.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address: 'sps', port: '59000') ⇒ SPSPub

Returns a new instance of SPSPub.



12
13
14
# File 'lib/sps-pub.rb', line 12

def initialize(address: 'sps', port: '59000')
  @client = Net::WS.new "ws://%s:%s/" % [address, port]
end

Class Method Details

.listen(topic = '#', address: 'sps') ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/sps-pub.rb', line 37

def self.listen(topic='#', address: 'sps')

  Client.connect(address) do |client|
    client.get(topic) do |topic, message| 
      puts "[%s] SPS listener INFO %s: %s" % 
        [Time.now.strftime("%Y-%m-%d %H:%M"), topic, message]
    end
  end
end

.notice(s, address: 'sps', port: '59000') ⇒ Object



22
23
24
25
26
# File 'lib/sps-pub.rb', line 22

def self.notice(s, address: 'sps', port: '59000')

  client = Net::WS.new "ws://%s:%s/" % [address, port]
  client.send s
end

.pub(s, address: 'sps', port: '59000') ⇒ Object



28
29
30
# File 'lib/sps-pub.rb', line 28

def self.pub(s, address: 'sps', port: '59000')
  self.notice(s, address: 'sps', port: '59000')
end

.publish(s, address: 'sps', port: '59000') ⇒ Object



32
33
34
# File 'lib/sps-pub.rb', line 32

def self.publish(s, address: 'sps', port: '59000')
  self.notice(s, address: 'sps', port: '59000')
end

.subscribe(topic = '#', address: 'sps') ⇒ Object



47
48
49
# File 'lib/sps-pub.rb', line 47

def self.subscribe(topic='#', address: 'sps')
  self.listen(topic='#', address: 'sps')
end

Instance Method Details

#notice(s) ⇒ Object



16
17
18
# File 'lib/sps-pub.rb', line 16

def notice(s)
  @client.send s
end

#publishObject



20
21
22
# File 'lib/sps-pub.rb', line 20

def notice(s)
  @client.send s
end