Class: Glottis::Handlers::RemoteOutputHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/glottis/handlers/remote_output_handler.rb

Overview

Manages posting outgoing messages to the remote valyx server.

Constant Summary collapse

POLL_INTERVAL =
0.1
PROTOCOL =
'http'
REMOTE_PATHS =
{
  get_session: '/api/v1/session',
  legacy_session: '/api/session',
  post_message: '/api/v1/messages',
  legacy_post_message: '/api/message'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outgoing, host, port) ⇒ RemoteOutputHandler

Returns a new instance of RemoteOutputHandler.



24
25
26
27
28
29
30
31
32
33
# File 'lib/glottis/handlers/remote_output_handler.rb', line 24

def initialize(outgoing, host, port)
  @outgoing = outgoing
  @host = host
  @port = port
  @running = false
  @thread = nil
  @sid = nil
  @cookie = nil
  setup_http
end

Instance Attribute Details

Returns the value of attribute cookie.



22
23
24
# File 'lib/glottis/handlers/remote_output_handler.rb', line 22

def cookie
  @cookie
end

#sidObject (readonly)

Returns the value of attribute sid.



22
23
24
# File 'lib/glottis/handlers/remote_output_handler.rb', line 22

def sid
  @sid
end

Instance Method Details

#cleanupObject



50
51
52
53
54
# File 'lib/glottis/handlers/remote_output_handler.rb', line 50

def cleanup
  @running = false
  @http.finish if @http.started?
  @thread&.kill if @thread&.alive?
end

#joinObject



46
47
48
# File 'lib/glottis/handlers/remote_output_handler.rb', line 46

def join
  @thread&.join
end

#startObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/glottis/handlers/remote_output_handler.rb', line 35

def start
  @running = true
  @thread = Thread.new do
    @http.start
    request_session

    send_queued while @running
  end
  self
end