Class: Colossus::SimpleWriterServer

Inherits:
Object
  • Object
show all
Defined in:
lib/colossus/simple_writer_server.rb

Defined Under Namespace

Classes: FayeClientExtension

Instance Attribute Summary collapse

Instance Method Summary collapse

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_clientObject (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_extensionObject (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_extensionObject (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

#colossusObject



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, message)
  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}", message)
    end
  when String
    faye_client.publish("/users/#{user_ids}", message)
  else
    raise 'Invalid user_ids data'
  end
end

#valid?(writer_token) ⇒ Boolean

Returns:

  • (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