glottis 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2884f76bb99f4bdec3dd3f76388f9938767ae903
|
4
|
+
data.tar.gz: 7c765d282c0826521fb4eb2bc9eb3e638676935c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c37f77138f8fd920f199023a2cc41091b55df36dabb27901491e0dfc14e9815d033af075c4dc378fcdc8b287bf9dfbdbce281e287cf2714b84a1367c13e7fd5
|
7
|
+
data.tar.gz: 83e91d51ae13a21ab278c7e9697e5e55dffed2c488cb5c2a794830c266f873e581781a05ca42feaccdcf9e01da32d0f1bc762c05fb15b97f951d19d55993bd4a
|
data/README.md
CHANGED
@@ -17,3 +17,5 @@ To install this gem onto your local machine, run `bundle exec rake install`.
|
|
17
17
|
## Contributing
|
18
18
|
|
19
19
|
Bug reports and pull requests are welcome on GitHub at https://github.com/maxdeliso/glottis.
|
20
|
+
|
21
|
+
[![Gem Version](https://badge.fury.io/rb/glottis.svg)](https://badge.fury.io/rb/glottis)
|
data/lib/glottis/client.rb
CHANGED
@@ -2,7 +2,8 @@ require 'thread'
|
|
2
2
|
require 'logger'
|
3
3
|
require 'glottis/handlers/console_input_handler'
|
4
4
|
require 'glottis/handlers/console_output_handler'
|
5
|
-
require 'glottis/handlers/
|
5
|
+
require 'glottis/handlers/remote_input_handler'
|
6
|
+
require 'glottis/handlers/remote_output_handler'
|
6
7
|
|
7
8
|
module Glottis
|
8
9
|
# Client class, used to interact with the host specified.
|
@@ -26,7 +27,8 @@ module Glottis
|
|
26
27
|
@handlers = [
|
27
28
|
Handlers::ConsoleInputHandler.new(@outgoing),
|
28
29
|
Handlers::ConsoleOutputHandler.new(@incoming),
|
29
|
-
Handlers::
|
30
|
+
Handlers::RemoteInputHandler.new(@incoming, @host, @port),
|
31
|
+
Handlers::RemoteOutputHandler.new(@outgoing, @host, @port)
|
30
32
|
]
|
31
33
|
|
32
34
|
@handlers.each(&:join)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'uri'
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Glottis
|
7
|
+
module Handlers
|
8
|
+
# This class manages a TCP connection with a valyx server.
|
9
|
+
class RemoteInputHandler < Thread
|
10
|
+
PROTOCOL = 'http'.freeze
|
11
|
+
STREAM_DELIMITER = "\0".freeze
|
12
|
+
READ_TIMEOUT = 3600 # this needs to be high
|
13
|
+
REMOTE_PATHS = {
|
14
|
+
get_message_stream: '/api/messages/stream'
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
def initialize(incoming, host, port)
|
18
|
+
@incoming = incoming
|
19
|
+
@host = host
|
20
|
+
@port = port
|
21
|
+
|
22
|
+
setup_http
|
23
|
+
|
24
|
+
super do
|
25
|
+
@http.start
|
26
|
+
read_loop
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def cleanup
|
31
|
+
@http.finish if @http.started?
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def setup_http
|
37
|
+
@http = Net::HTTP.new(@host, @port)
|
38
|
+
@http.open_timeout = 1
|
39
|
+
@http.read_timeout = READ_TIMEOUT
|
40
|
+
end
|
41
|
+
|
42
|
+
def read_loop
|
43
|
+
Client.logger.info('reading stream...')
|
44
|
+
@http.get(REMOTE_PATHS.fetch(:get_message_stream)) do |chunk|
|
45
|
+
Client.logger.debug("got chunk of length: #{chunk.length}")
|
46
|
+
chunk.split(STREAM_DELIMITER).each do |msg_data|
|
47
|
+
@incoming.push(JSON.parse(msg_data))
|
48
|
+
end # each
|
49
|
+
end # get
|
50
|
+
end # read_loop
|
51
|
+
end # RemoteInputHandler
|
52
|
+
end # Handlers
|
53
|
+
end # Glottis
|
@@ -6,22 +6,19 @@ require 'json'
|
|
6
6
|
module Glottis
|
7
7
|
module Handlers
|
8
8
|
# This class manages a TCP connection with a valyx server.
|
9
|
-
class
|
9
|
+
class RemoteOutputHandler < Thread
|
10
10
|
POLL_INTERVAL = 0.1
|
11
11
|
PROTOCOL = 'http'.freeze
|
12
12
|
|
13
13
|
REMOTE_PATHS = {
|
14
14
|
get_session: '/api/session',
|
15
|
-
get_messages: '/api/messages',
|
16
15
|
post_message: '/api/message'
|
17
16
|
}.freeze
|
18
17
|
|
19
|
-
def initialize(outgoing,
|
18
|
+
def initialize(outgoing, host, port)
|
20
19
|
@outgoing = outgoing
|
21
|
-
@incoming = incoming
|
22
20
|
@host = host
|
23
21
|
@port = port
|
24
|
-
@received_count = 0
|
25
22
|
|
26
23
|
setup_http
|
27
24
|
|
@@ -30,10 +27,7 @@ module Glottis
|
|
30
27
|
request_session
|
31
28
|
|
32
29
|
loop do
|
33
|
-
request_messages
|
34
30
|
send_queued
|
35
|
-
|
36
|
-
sleep POLL_INTERVAL
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
@@ -49,7 +43,6 @@ module Glottis
|
|
49
43
|
# TODO: make these configurable somewhere
|
50
44
|
@http.open_timeout = 1
|
51
45
|
@http.read_timeout = 1
|
52
|
-
@http.continue_timeout = 1
|
53
46
|
end
|
54
47
|
|
55
48
|
def request_session
|
@@ -94,30 +87,21 @@ module Glottis
|
|
94
87
|
process_new_messages(messages_req.body)
|
95
88
|
end
|
96
89
|
|
97
|
-
def process_new_messages(messages_data)
|
98
|
-
new_messages = JSON.parse(messages_data)
|
99
|
-
Client.logger.debug("received #{new_messages.size} new messages")
|
100
|
-
@received_count += new_messages.size
|
101
|
-
new_messages.each { |msg| @incoming.push(msg) }
|
102
|
-
end
|
103
|
-
|
104
90
|
def send_queued
|
105
|
-
|
106
|
-
Client.logger.info("processing message with #{@outgoing.size} messages outgoing")
|
91
|
+
Client.logger.info("processing message with #{@outgoing.size} messages outgoing")
|
107
92
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
93
|
+
message_data = {
|
94
|
+
from: @sid,
|
95
|
+
to: '*',
|
96
|
+
msg: @outgoing.pop
|
97
|
+
}.to_json
|
113
98
|
|
114
|
-
|
99
|
+
post_req = @http.post(REMOTE_PATHS.fetch(:post_message), message_data)
|
115
100
|
|
116
|
-
|
117
|
-
|
118
|
-
end
|
101
|
+
if_not_ok(post_req) do |err|
|
102
|
+
Client.logger.warn("failed to post message: #{message_data} #{err}")
|
119
103
|
end
|
120
104
|
end # send_queued
|
121
|
-
end #
|
105
|
+
end # RemoteOutputHandler
|
122
106
|
end # Handlers
|
123
107
|
end # Glottis
|
data/lib/glottis/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glottis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max DeLiso
|
@@ -118,7 +118,8 @@ files:
|
|
118
118
|
- lib/glottis/exceptions/user_exited_exception.rb
|
119
119
|
- lib/glottis/handlers/console_input_handler.rb
|
120
120
|
- lib/glottis/handlers/console_output_handler.rb
|
121
|
-
- lib/glottis/handlers/
|
121
|
+
- lib/glottis/handlers/remote_input_handler.rb
|
122
|
+
- lib/glottis/handlers/remote_output_handler.rb
|
122
123
|
- lib/glottis/version.rb
|
123
124
|
homepage: https://github.com/maxdeliso/glottis
|
124
125
|
licenses:
|