Class: Wamp::Client::Request::Subscribe

Inherits:
Base
  • Object
show all
Defined in:
lib/wamp/client/request/subscribe.rb

Instance Attribute Summary

Attributes inherited from Base

#on_success, #requests, #send_message_callback, #session

Instance Method Summary collapse

Methods inherited from Base

#error, #generate_id, #initialize, #request, #success

Constructor Details

This class inherits a constructor from Wamp::Client::Request::Base

Instance Method Details

#create_request(request_id, topic, handler, options = {}, &callback) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wamp/client/request/subscribe.rb', line 17

def create_request(request_id, topic, handler, options={}, &callback)

  # Create the lookup
  lookup = {t: topic, h: handler, o: options, c: callback}

  # Create the message
  message = Message::Subscribe.new(request_id, options, topic)

  # Return
  [lookup, message]
end

#process_error(message, lookup) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/wamp/client/request/subscribe.rb', line 56

def process_error(message, lookup)
  if lookup
    # Get the params
    topic = lookup[:t]
    callback = lookup[:c]

    # Create the details
    details = message.details || {}
    details[:topic] = topic unless details[:topic]
    details[:type] = 'subscribe'

    # Return the values
    [callback, details]
  else
    [nil, nil]
  end
end

#process_success(message, lookup) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/wamp/client/request/subscribe.rb', line 29

def process_success(message, lookup)
  if lookup
    # Get the params
    topic = lookup[:t]
    handler = lookup[:h]
    options = lookup[:o]
    callback = lookup[:c]

    # Create the subscription
    s_id = message.subscription
    s = Manager::SubscriptionObject.new(topic, handler, options, self.session, s_id)

    # Create the details
    details = {}
    details[:topic] = topic unless details[:topic]
    details[:type] = 'subscribe'

    # Call the on_success method
    self.on_success.call(s_id, s)

    # Return the values
    [callback, s, details]
  else
    [nil, nil, nil]
  end
end