Class: Wamp::Client::Request::Publish

Inherits:
Base
  • Object
show all
Defined in:
lib/wamp/client/request/publish.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, args = nil, kwargs = nil, options = {}, &callback) ⇒ Object



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

def create_request(request_id, topic, args=nil, kwargs=nil, options={}, &callback)

  # Create the lookup
  lookup = options[:acknowledge] ? {t: topic, a: args, k: kwargs, o: options, c: callback} : nil

  # Create the message
  message = Message::Publish.new(request_id, options, topic, args, kwargs)

  # Return
  [lookup, message]
end

#process_error(message, lookup) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/wamp/client/request/publish.rb', line 50

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] = 'publish'

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

#process_success(message, lookup) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/wamp/client/request/publish.rb', line 28

def process_success(message, lookup)
  if lookup
    # Get the params
    topic = lookup[:t]
    args = lookup[:a]
    kwargs = lookup[:k]
    options = lookup[:o]
    callback = lookup[:c]

    # Create the details
    details = {}
    details[:topic] = topic
    details[:type] = 'publish'
    details[:publication] = message.publication

    # Return the values
    [callback, { args: args, kwargs: kwargs, options: options }, details]
  else
    [nil, nil, nil]
  end
end