27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/pushify/juggernaut.rb', line 27
def send_data(hash, response = false)
hash[:channels] = Array(hash[:channels]) if hash[:channels]
hash[:client_ids] = Array(hash[:client_ids]) if hash[:client_ids]
res = []
hosts.each do |address|
begin
hash[:secret_key] = address[:secret_key] if address[:secret_key]
@socket = TCPSocket.new(address[:host], address[:port])
@socket.print(hash.to_json + CR)
@socket.flush
res << @socket.readline(CR) if response
ensure
@socket.close if @socket and !@socket.closed?
end
end
res.collect {|r| ActiveSupport::JSON.decode(r.chomp!(CR)) } if response
end
|