Class: WarCorrespondent::Uplink

Inherits:
Object
  • Object
show all
Defined in:
lib/warcorrespondent/uplink.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUplink

Returns a new instance of Uplink.



8
9
10
# File 'lib/warcorrespondent/uplink.rb', line 8

def initialize
  @@messages = []
end

Instance Attribute Details

#secretObject

Returns the value of attribute secret.



6
7
8
# File 'lib/warcorrespondent/uplink.rb', line 6

def secret
  @secret
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/warcorrespondent/uplink.rb', line 5

def url
  @url
end

Instance Method Details

#add(message) ⇒ Object



12
13
14
# File 'lib/warcorrespondent/uplink.rb', line 12

def add(message)
  @@messages << message
end

#runObject



31
32
33
34
35
36
# File 'lib/warcorrespondent/uplink.rb', line 31

def run
  loop do
    sync
    sleep 1
  end
end

#syncObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/warcorrespondent/uplink.rb', line 16

def sync
  return if @@messages.size == 0
  buffer = []
  10.times do
    buffer << @@messages.shift if @@messages.size > 0
  end
  buffer.each do |message| 
    begin
      post(encode(message))
    rescue
      add(message)
    end
  end
end