Class: Colossus::WriterClient
- Inherits:
-
Object
- Object
- Colossus::WriterClient
- Defined in:
- lib/colossus/writer_client.rb
Defined Under Namespace
Classes: FayeExtension
Instance Attribute Summary collapse
-
#time_out ⇒ Object
readonly
Returns the value of attribute time_out.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#writer_token ⇒ Object
readonly
Returns the value of attribute writer_token.
Instance Method Summary collapse
- #get_presences(optional_user_ids = nil) ⇒ Object
-
#initialize(url, writer_token, time_out = 2) ⇒ WriterClient
constructor
A new instance of WriterClient.
- #push_message(user_ids, message) ⇒ Object
Constructor Details
#initialize(url, writer_token, time_out = 2) ⇒ WriterClient
Returns a new instance of WriterClient.
5 6 7 8 9 |
# File 'lib/colossus/writer_client.rb', line 5 def initialize(url, writer_token, time_out = 2) @url = url @writer_token = writer_token @time_out = time_out end |
Instance Attribute Details
#time_out ⇒ Object (readonly)
Returns the value of attribute time_out.
3 4 5 |
# File 'lib/colossus/writer_client.rb', line 3 def time_out @time_out end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/colossus/writer_client.rb', line 3 def url @url end |
#writer_token ⇒ Object (readonly)
Returns the value of attribute writer_token.
3 4 5 |
# File 'lib/colossus/writer_client.rb', line 3 def writer_token @writer_token end |
Instance Method Details
#get_presences(optional_user_ids = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/colossus/writer_client.rb', line 11 def get_presences(optional_user_ids = nil) user_ids = Array(optional_user_ids) if optional_user_ids unique_token = generate_unique_token EM.synchrony do EM::Synchrony.add_timer(time_out) { raise "Presence request timed out" } EM::Synchrony.sync(faye_client.subscribe("/presences/response/#{unique_token}") { || return ['statuses'] }) EM::Synchrony.sync(faye_client.publish("/presences/request/#{unique_token}", user_ids)) end end |
#push_message(user_ids, message) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/colossus/writer_client.rb', line 21 def (user_ids, ) user_ids = Array(user_ids) EM.synchrony do user_ids.each do |user_id| EM::Synchrony.sync(faye_client.publish("/users/#{user_id}", )) end EM.stop end end |