Class: Colossus::HTTPWriterClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, writer_token = Colossus.config.writer_token, time_out = 2) ⇒ HTTPWriterClient

Returns a new instance of HTTPWriterClient.



5
6
7
8
9
10
11
# File 'lib/colossus/http_writer_client.rb', line 5

def initialize(url,
               writer_token = Colossus.config.writer_token,
               time_out     = 2)
  @url          = url
  @writer_token = writer_token
  @time_out     = time_out
end

Instance Attribute Details

#time_outObject (readonly)

Returns the value of attribute time_out.



3
4
5
# File 'lib/colossus/http_writer_client.rb', line 3

def time_out
  @time_out
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/colossus/http_writer_client.rb', line 3

def url
  @url
end

#writer_tokenObject (readonly)

Returns the value of attribute writer_token.



3
4
5
# File 'lib/colossus/http_writer_client.rb', line 3

def writer_token
  @writer_token
end

Instance Method Details

#presence(optional_user_ids = nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/colossus/http_writer_client.rb', line 13

def presence(optional_user_ids = nil)
  user_ids = Array(optional_user_ids) if optional_user_ids
  connection.post('/presence_request') do |req|
    req.body = { user_ids: user_ids, writer_token: writer_token }
  end.body
end

#push(user_ids, message) ⇒ Object



20
21
22
23
24
25
# File 'lib/colossus/http_writer_client.rb', line 20

def push(user_ids, message)
  user_ids = Array(user_ids)
  connection.post('/message') do |req|
    req.body = { user_ids: user_ids, message: message, writer_token: writer_token}
  end.body
end