Class: Radar::Presence

Inherits:
Resource show all
Defined in:
lib/radar_client_rb/resource.rb

Instance Method Summary collapse

Methods inherited from Resource

#logger

Constructor Details

#initialize(client, name) ⇒ Presence

Returns a new instance of Presence.


16
17
18
# File 'lib/radar_client_rb/resource.rb', line 16

def initialize(client, name)
  super(client, "presence:/#{client.subdomain}/#{name}")
end

Instance Method Details

#getObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/radar_client_rb/resource.rb', line 20

def get
  result = {}

  clients = get_clients.select { |client| client['online'] }
  sentries = clients.map { |client| client['sentry'] }
  online_sentries = select_online_sentries(sentries)
  online_clients = clients.select { |client| online_sentries.include?(client['sentry']) }

  online_clients.each do |client|
    user_id = client['userId']
    result[user_id] ||= { :clients => {}, :userType => client['userType'] }
    result[user_id][:clients][client['clientId']] = client['userData'] || {}
  end
  result
end