class RenderSync::Clients::Faye::Message
Attributes
channel[RW]
data[RW]
Public Class Methods
batch_messages_query_hash(messages)
click to toggle source
# File lib/render_sync/clients/faye.rb, line 55 def self.batch_messages_query_hash(messages) { channel: "/batch_publish", data: messages.collect(&:to_hash), ext: { auth_token: RenderSync.auth_token } } end
batch_publish(messages)
click to toggle source
# File lib/render_sync/clients/faye.rb, line 32 def self.batch_publish(messages) if RenderSync.async? batch_publish_asynchronous(messages) else batch_publish_synchronous(messages) end end
batch_publish_asynchronous(messages)
click to toggle source
# File lib/render_sync/clients/faye.rb, line 47 def self.batch_publish_asynchronous(messages) RenderSync.reactor.perform do EM::HttpRequest.new(RenderSync.server).post(body: { message: batch_messages_query_hash(messages).to_json }) end end
batch_publish_synchronous(messages)
click to toggle source
# File lib/render_sync/clients/faye.rb, line 40 def self.batch_publish_synchronous(messages) Net::HTTP.post_form( URI.parse(RenderSync.server), message: batch_messages_query_hash(messages).to_json ) end
new(channel, data)
click to toggle source
# File lib/render_sync/clients/faye.rb, line 63 def initialize(channel, data) self.channel = channel self.data = data end
Public Instance Methods
publish()
click to toggle source
# File lib/render_sync/clients/faye.rb, line 82 def publish if RenderSync.async? publish_asynchronous else publish_synchronous end end
publish_asynchronous()
click to toggle source
# File lib/render_sync/clients/faye.rb, line 94 def publish_asynchronous RenderSync.reactor.perform do EM::HttpRequest.new(RenderSync.server).post(body: { message: self.to_json }) end end
publish_synchronous()
click to toggle source
# File lib/render_sync/clients/faye.rb, line 90 def publish_synchronous Net::HTTP.post_form URI.parse(RenderSync.server), message: to_json end
to_hash()
click to toggle source
# File lib/render_sync/clients/faye.rb, line 68 def to_hash { channel: channel, data: data, ext: { auth_token: RenderSync.auth_token } } end
to_json()
click to toggle source
# File lib/render_sync/clients/faye.rb, line 78 def to_json to_hash.to_json end