Class: Wamp::MessageHandler::Api

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/wamp/message_handler/api.rb

Overview

handles session

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Api

Returns a new instance of Api.



13
14
15
16
# File 'lib/wamp/message_handler/api.rb', line 13

def initialize(connection)
  @connection = connection
  @id_gen = Wampproto::IdGenerator.new
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



11
12
13
# File 'lib/wamp/message_handler/api.rb', line 11

def connection
  @connection
end

#id_genObject (readonly)

Returns the value of attribute id_gen.



11
12
13
# File 'lib/wamp/message_handler/api.rb', line 11

def id_gen
  @id_gen
end

#session_idObject (readonly)

Returns the value of attribute session_id.



11
12
13
# File 'lib/wamp/message_handler/api.rb', line 11

def session_id
  @session_id
end

Instance Method Details

#call(procedure, options = {}, *args, **kwargs, &handler) ⇒ Object



40
41
42
43
44
# File 'lib/wamp/message_handler/api.rb', line 40

def call(procedure, options = {}, *args, **kwargs, &handler)
  message = Wampproto::Message::Call.new(next_request_id, options, procedure, *args, **kwargs)

  MessageHandler::Call.new(message, connection).send_message(handler)
end

#publish(topic, options = {}, *args, **kwargs, &block) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/wamp/message_handler/api.rb', line 32

def publish(topic, options = {}, *args, **kwargs, &block)
  options = options.merge({ acknowledge: true }) if block_given?
  message = Wampproto::Message::Publish.new(next_request_id, options, topic, *args, **kwargs)

  action = MessageHandler::Publish.new(message, connection)
  action.send_message(&block)
end

#register(procedure, handler, options = {}, &block) ⇒ Object



46
47
48
49
50
# File 'lib/wamp/message_handler/api.rb', line 46

def register(procedure, handler, options = {}, &block)
  message = Wampproto::Message::Register.new(next_request_id, options, procedure)
  action = MessageHandler::Register.new(message, connection)
  action.send_message(handler, &block)
end

#subscribe(topic, handler, options = {}, &block) ⇒ Object



18
19
20
21
22
# File 'lib/wamp/message_handler/api.rb', line 18

def subscribe(topic, handler, options = {}, &block)
  message = Wampproto::Message::Subscribe.new(next_request_id, options, topic)
  action = MessageHandler::Subscribe.new(message, connection)
  action.send_message(handler, &block)
end

#unregister(registration_id, &block) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/wamp/message_handler/api.rb', line 52

def unregister(registration_id, &block)
  registration_id = connection.store[registration_id] if connection.store.include?(registration_id)

  message = Wampproto::Message::Unregister.new(next_request_id, registration_id.to_i)
  action = MessageHandler::Unregister.new(message, connection)
  action.send_message(&block)
end

#unsubscribe(subscription_id, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/wamp/message_handler/api.rb', line 24

def unsubscribe(subscription_id, &block)
  subscription_id = connection.store[subscription_id] if connection.store.include?(subscription_id)

  message = Wampproto::Message::Unsubscribe.new(next_request_id, subscription_id.to_i)
  action = MessageHandler::Unsubscribe.new(message, connection)
  action.send_message(&block)
end