Class: RenderSync::Clients::Faye::Message
- Inherits:
-
Object
- Object
- RenderSync::Clients::Faye::Message
- Defined in:
- lib/render_sync/clients/faye.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#data ⇒ Object
Returns the value of attribute data.
Class Method Summary collapse
- .batch_messages_query_hash(messages) ⇒ Object
- .batch_publish(messages) ⇒ Object
- .batch_publish_asynchronous(messages) ⇒ Object
- .batch_publish_synchronous(messages) ⇒ Object
Instance Method Summary collapse
-
#initialize(channel, data) ⇒ Message
constructor
A new instance of Message.
- #publish ⇒ Object
- #publish_asynchronous ⇒ Object
- #publish_synchronous ⇒ Object
- #to_hash ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(channel, data) ⇒ Message
63 64 65 66 |
# File 'lib/render_sync/clients/faye.rb', line 63 def initialize(channel, data) self.channel = channel self.data = data end |
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
30 31 32 |
# File 'lib/render_sync/clients/faye.rb', line 30 def channel @channel end |
#data ⇒ Object
Returns the value of attribute data.
30 31 32 |
# File 'lib/render_sync/clients/faye.rb', line 30 def data @data end |
Class Method Details
.batch_messages_query_hash(messages) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/render_sync/clients/faye.rb', line 55 def self.() { channel: "/batch_publish", data: .collect(&:to_hash), ext: { auth_token: RenderSync.auth_token } } end |
.batch_publish(messages) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/render_sync/clients/faye.rb', line 32 def self.batch_publish() if RenderSync.async? batch_publish_asynchronous() else batch_publish_synchronous() end end |
.batch_publish_asynchronous(messages) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/render_sync/clients/faye.rb', line 47 def self.batch_publish_asynchronous() RenderSync.reactor.perform do EM::HttpRequest.new(RenderSync.server).post(body: { message: ().to_json }) end end |
.batch_publish_synchronous(messages) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/render_sync/clients/faye.rb', line 40 def self.batch_publish_synchronous() Net::HTTP.post_form( URI.parse(RenderSync.server), message: ().to_json ) end |
Instance Method Details
#publish ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/render_sync/clients/faye.rb', line 82 def publish if RenderSync.async? publish_asynchronous else publish_synchronous end end |
#publish_asynchronous ⇒ Object
94 95 96 97 98 99 100 |
# 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 ⇒ Object
90 91 92 |
# 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 ⇒ Object
68 69 70 71 72 73 74 75 76 |
# 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 ⇒ Object
78 79 80 |
# File 'lib/render_sync/clients/faye.rb', line 78 def to_json to_hash.to_json end |