Class: Colossus::SimpleWriterServer
- Inherits:
-
Object
- Object
- Colossus::SimpleWriterServer
- Defined in:
- lib/colossus/simple_writer_server.rb
Defined Under Namespace
Classes: FayeClientExtension
Instance Attribute Summary collapse
-
#faye_client ⇒ Object
readonly
Returns the value of attribute faye_client.
-
#faye_client_extension ⇒ Object
readonly
Returns the value of attribute faye_client_extension.
-
#faye_extension ⇒ Object
readonly
Returns the value of attribute faye_extension.
Instance Method Summary collapse
- #colossus ⇒ Object
-
#initialize(faye_extension) ⇒ SimpleWriterServer
constructor
A new instance of SimpleWriterServer.
- #presence(writer_token, optional_user_ids = nil) ⇒ Object
- #push(writer_token, user_ids, message) ⇒ Object
- #valid?(writer_token) ⇒ Boolean
Constructor Details
#initialize(faye_extension) ⇒ SimpleWriterServer
Returns a new instance of SimpleWriterServer.
5 6 7 8 9 10 |
# File 'lib/colossus/simple_writer_server.rb', line 5 def initialize(faye_extension) @faye_extension = faye_extension @faye_client = faye_extension.faye.get_client @faye_client_extension = FayeClientExtension.new @faye_client.add_extension(faye_client_extension) end |
Instance Attribute Details
#faye_client ⇒ Object (readonly)
Returns the value of attribute faye_client.
3 4 5 |
# File 'lib/colossus/simple_writer_server.rb', line 3 def faye_client @faye_client end |
#faye_client_extension ⇒ Object (readonly)
Returns the value of attribute faye_client_extension.
3 4 5 |
# File 'lib/colossus/simple_writer_server.rb', line 3 def faye_client_extension @faye_client_extension end |
#faye_extension ⇒ Object (readonly)
Returns the value of attribute faye_extension.
3 4 5 |
# File 'lib/colossus/simple_writer_server.rb', line 3 def faye_extension @faye_extension end |
Instance Method Details
#colossus ⇒ Object
48 49 50 |
# File 'lib/colossus/simple_writer_server.rb', line 48 def colossus faye_extension.colossus end |
#presence(writer_token, optional_user_ids = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/colossus/simple_writer_server.rb', line 12 def presence(writer_token, optional_user_ids = nil) raise 'Invalid token' unless valid?(writer_token) faye_client_extension.writer_token = writer_token case optional_user_ids when Array colossus.get_multi(*optional_user_ids) when String colossus.get(optional_user_ids) when NilClass colossus.get_all else raise 'Invalid user_ids data' end end |
#push(writer_token, user_ids, message) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/colossus/simple_writer_server.rb', line 28 def push(writer_token, user_ids, ) raise 'Invalid token' unless valid?(writer_token) faye_client_extension.writer_token = writer_token case user_ids when Array user_ids.each do |user_id| faye_client.publish("/users/#{user_id}", ) end when String faye_client.publish("/users/#{user_ids}", ) else raise 'Invalid user_ids data' end end |
#valid?(writer_token) ⇒ Boolean
44 45 46 |
# File 'lib/colossus/simple_writer_server.rb', line 44 def valid?(writer_token) colossus.verifier.verify_writer_token(writer_token) end |