class Bixby::WebSocket::Message
Attributes
body[R]
headers[R]
id[R]
type[R]
Public Class Methods
from_wire(body)
click to toggle source
# File lib/bixby-common/websocket/message.rb, line 15 def self.from_wire(body) obj = MultiJson.load(body) clazz = case obj["type"] when "rpc", "connect" Request when "rpc_result" Response end req = clazz.allocate req.instance_eval do @id = obj["id"] @type = obj["type"] @body = obj["data"] if obj.include? "headers" then @headers = obj["headers"] end end return req end
new(id=nil, type="rpc", headers=nil)
click to toggle source
# File lib/bixby-common/websocket/message.rb, line 9 def initialize(id=nil, type="rpc", headers=nil) @id = id || SecureRandom.uuid @type = type @headers = headers || {} end
Public Instance Methods
to_s()
click to toggle source
Convert object to String, useful for debugging
@return [String]
# File lib/bixby-common/websocket/message.rb, line 50 def to_s # :nocov: s = [] s << "#{self.class}:#{self.object_id}" s << " id: #{self.id}" s << " type: #{self.type}" s << " headers: " + Debug.pretty_hash(self.headers) s << " body: " + Debug.pretty_hash(MultiJson.load(self.body)) s.join("\n") end
to_wire()
click to toggle source
# File lib/bixby-common/websocket/message.rb, line 38 def to_wire hash = { :type => @type, :id => @id, :headers => @headers, :data => @body } MultiJson.dump(hash) end