Class: WampClient::Message::Publish

Inherits:
Base
  • Object
show all
Defined in:
lib/wamp_client/message.rb

Overview

Publish Sent by a Publisher to a Broker to publish an event. Formats:

[PUBLISH, Request|id, Options|dict, Topic|uri]
[PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list]
[PUBLISH, Request|id, Options|dict, Topic|uri, Arguments|list, ArgumentsKw|dict]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Check

included

Constructor Details

#initialize(request, options, topic, arguments = nil, argumentskw = nil) ⇒ Publish

Returns a new instance of Publish.



386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'lib/wamp_client/message.rb', line 386

def initialize(request, options, topic, arguments=nil, argumentskw=nil)

  self.class.check_id('request', request)
  self.class.check_dict('options', options)
  self.class.check_uri('topic', topic)
  self.class.check_list('arguments', arguments, true)
  self.class.check_dict('argumentskw', argumentskw, true)

  self.request = request
  self.options = options
  self.topic = topic
  self.arguments = arguments
  self.argumentskw = argumentskw

end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



384
385
386
# File 'lib/wamp_client/message.rb', line 384

def arguments
  @arguments
end

#argumentskwObject

Returns the value of attribute argumentskw.



384
385
386
# File 'lib/wamp_client/message.rb', line 384

def argumentskw
  @argumentskw
end

#optionsObject

Returns the value of attribute options.



384
385
386
# File 'lib/wamp_client/message.rb', line 384

def options
  @options
end

#requestObject

Returns the value of attribute request.



384
385
386
# File 'lib/wamp_client/message.rb', line 384

def request
  @request
end

#topicObject

Returns the value of attribute topic.



384
385
386
# File 'lib/wamp_client/message.rb', line 384

def topic
  @topic
end

Class Method Details

.parse(params) ⇒ Object



406
407
408
409
410
411
412
413
414
# File 'lib/wamp_client/message.rb', line 406

def self.parse(params)

  self.check_gte('params list', 4, params.count)
  self.check_equal('message type', self.type, params[0])

  params.shift
  self.new(*params)

end

.typeObject



402
403
404
# File 'lib/wamp_client/message.rb', line 402

def self.type
  Types::PUBLISH
end

Instance Method Details

#payloadObject



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'lib/wamp_client/message.rb', line 416

def payload
  self.arguments ||= []
  self.argumentskw ||= {}

  payload = [self.class.type]
  payload.push(self.request)
  payload.push(self.options)
  payload.push(self.topic)

  return payload if (self.arguments.empty? and self.argumentskw.empty?)
  payload.push(self.arguments)

  return payload if (self.argumentskw.empty?)
  payload.push(self.argumentskw)

  payload
end

#to_sObject



434
435
436
# File 'lib/wamp_client/message.rb', line 434

def to_s
  'PUBLISH > ' + self.payload.to_s
end