Class: Wamp::MessageHandler::Api
- Inherits:
-
Object
- Object
- Wamp::MessageHandler::Api
- Extended by:
- Forwardable
- Defined in:
- lib/wamp/message_handler/api.rb
Overview
handles session
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#id_gen ⇒ Object
readonly
Returns the value of attribute id_gen.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
Instance Method Summary collapse
- #call(procedure, options = {}, *args, **kwargs, &handler) ⇒ Object
-
#initialize(connection) ⇒ Api
constructor
A new instance of Api.
- #publish(topic, options = {}, *args, **kwargs, &block) ⇒ Object
- #register(procedure, handler, options = {}, &block) ⇒ Object
- #subscribe(topic, handler, options = {}, &block) ⇒ Object
- #unregister(registration_id, &block) ⇒ Object
- #unsubscribe(subscription_id, &block) ⇒ Object
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
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
11 12 13 |
# File 'lib/wamp/message_handler/api.rb', line 11 def connection @connection end |
#id_gen ⇒ Object (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_id ⇒ Object (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, = {}, *args, **kwargs, &handler) = Wampproto::Message::Call.new(next_request_id, , procedure, *args, **kwargs) MessageHandler::Call.new(, connection).(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, = {}, *args, **kwargs, &block) = .merge({ acknowledge: true }) if block_given? = Wampproto::Message::Publish.new(next_request_id, , topic, *args, **kwargs) action = MessageHandler::Publish.new(, connection) action.(&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, = {}, &block) = Wampproto::Message::Register.new(next_request_id, , procedure) action = MessageHandler::Register.new(, connection) action.(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, = {}, &block) = Wampproto::Message::Subscribe.new(next_request_id, , topic) action = MessageHandler::Subscribe.new(, connection) action.(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) = Wampproto::Message::Unregister.new(next_request_id, registration_id.to_i) action = MessageHandler::Unregister.new(, connection) action.(&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) = Wampproto::Message::Unsubscribe.new(next_request_id, subscription_id.to_i) action = MessageHandler::Unsubscribe.new(, connection) action.(&block) end |