glottis 0.1.2 → 0.1.3

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: 2884f76bb99f4bdec3dd3f76388f9938767ae903
4
- data.tar.gz: 7c765d282c0826521fb4eb2bc9eb3e638676935c
3
+ metadata.gz: 7a42b6e38fd2d75e8acbdc2dcf338453c34b69c7
4
+ data.tar.gz: 189a29629e5104997a16071815febe031ee1e794
5
5
  SHA512:
6
- metadata.gz: 1c37f77138f8fd920f199023a2cc41091b55df36dabb27901491e0dfc14e9815d033af075c4dc378fcdc8b287bf9dfbdbce281e287cf2714b84a1367c13e7fd5
7
- data.tar.gz: 83e91d51ae13a21ab278c7e9697e5e55dffed2c488cb5c2a794830c266f873e581781a05ca42feaccdcf9e01da32d0f1bc762c05fb15b97f951d19d55993bd4a
6
+ metadata.gz: 1cffde427455b740691132995a39ac6c1071a23f19bcef3744971958d414967c13ea4c9f28dabd521eef21dda5c074951dd311ee109ac81c6c4420514e1c253d
7
+ data.tar.gz: 22dd5726fef0948fd4c114dddaa52c02a01699bbbcbe155e15622fc0c7f2b59474ae2bbf2689cbc133fdba2590c0e2ff97bc7ec602d468d67749bf9dc15a5eab
data/.gitignore CHANGED
@@ -1,11 +1,11 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.log
11
- *.gem
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.log
11
+ *.gem
@@ -1,5 +1,5 @@
1
- Metrics/LineLength:
2
- Max: 99
3
-
4
- Metrics/MethodLength:
1
+ Metrics/LineLength:
2
+ Max: 99
3
+
4
+ Metrics/MethodLength:
5
5
  Max: 20
@@ -1,4 +1,4 @@
1
- language: ruby
2
- rvm:
3
- - 2.1.5
4
- before_install: gem install bundler -v 1.10.6
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in glottis.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in glottis.gemspec
4
+ gemspec
data/README.md CHANGED
@@ -1,21 +1,27 @@
1
- # glottis
2
-
3
- A CLI for the [valyx](https://github.com/maxdeliso/valyx) message passing server.
4
-
5
- ## Installation
6
-
7
- $ gem install glottis
8
-
9
- ## Usage
10
-
11
- $ glottis -h
12
-
13
- ## Development
14
-
15
- To install this gem onto your local machine, run `bundle exec rake install`.
16
-
17
- ## Contributing
18
-
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)
1
+ # glottis
2
+
3
+ A CLI for the [valyx](https://github.com/maxdeliso/valyx) message passing server.
4
+
5
+ ## Installation
6
+
7
+ $ gem install glottis
8
+
9
+ ## Usage
10
+
11
+ $ glottis -h
12
+
13
+ ## Development
14
+
15
+ To check the code:
16
+
17
+ $ bundle exec rake
18
+
19
+ To install this gem onto your local machine:
20
+
21
+ $ bundle exec rake install
22
+
23
+ ## Contributing
24
+
25
+ Bug reports and pull requests are welcome on GitHub at https://github.com/maxdeliso/glottis.
26
+
27
+ [![Gem Version](https://badge.fury.io/rb/glottis.svg)](https://badge.fury.io/rb/glottis)
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
- require 'bundler/gem_tasks'
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+
4
+ RuboCop::RakeTask.new(:rubocop)
5
+
6
+ task default: [:rubocop]
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'glottis'
5
- require 'irb'
6
-
7
- IRB.start
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'glottis'
5
+ require 'irb'
6
+
7
+ IRB.start
data/bin/setup CHANGED
@@ -1,7 +1,7 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -1,22 +1,22 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'slop'
4
- require 'glottis'
5
-
6
- opts = Slop.parse do |o|
7
- o.string '--host', 'a hostname', default: 'localhost'
8
- o.integer '--port', 'TCP port', default: 8080
9
- o.bool '-v', '--verbose', 'enable verbose mode'
10
- o.on '-V', '--version', 'print the version' do
11
- puts "glottis #{Glottis::VERSION}"
12
- exit
13
- end
14
- o.on '-h', '--help' do
15
- puts o
16
- exit
17
- end
18
- end
19
-
20
- Glottis::Client.new(opts[:host],
21
- opts[:port],
22
- verbose: opts[:verbose]).run
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'slop'
4
+ require 'glottis'
5
+
6
+ opts = Slop.parse do |o|
7
+ o.string '--host', 'a hostname', default: 'localhost'
8
+ o.integer '--port', 'TCP port', default: 8080
9
+ o.bool '-v', '--verbose', 'enable verbose mode'
10
+ o.on '-V', '--version', 'print the version' do
11
+ puts "glottis #{Glottis::VERSION}"
12
+ exit
13
+ end
14
+ o.on '-h', '--help' do
15
+ puts o
16
+ exit
17
+ end
18
+ end
19
+
20
+ Glottis::Client.new(opts[:host],
21
+ opts[:port],
22
+ verbose: opts[:verbose]).run
@@ -1,30 +1,29 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'glottis/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'glottis'
8
- spec.version = Glottis::VERSION
9
- spec.authors = ['Max DeLiso']
10
- spec.email = ['maxdeliso@gmail.com']
11
- spec.licenses = ['MIT']
12
- spec.summary = 'simple http messaging client'
13
- spec.homepage = 'https://github.com/maxdeliso/glottis'
14
-
15
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
- f.match(%r{^(test|spec|features)/})
17
- end
18
-
19
- spec.bindir = 'exe'
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ['lib']
22
-
23
- spec.add_runtime_dependency 'rb-readline', '~> 0.5.3'
24
- spec.add_runtime_dependency 'slop', '~> 4.2'
25
-
26
- spec.add_development_dependency 'bundler', '~> 1.10'
27
- spec.add_development_dependency 'pry', '~> 0.10.3'
28
- spec.add_development_dependency 'rake', '~> 10.0'
29
- spec.add_development_dependency 'rubocop', '~> 0.35.1'
30
- end
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'glottis/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'glottis'
8
+ spec.version = Glottis::VERSION
9
+ spec.authors = ['Max DeLiso']
10
+ spec.email = ['maxdeliso@gmail.com']
11
+ spec.licenses = ['MIT']
12
+ spec.summary = 'simple http messaging client'
13
+ spec.homepage = 'https://github.com/maxdeliso/glottis'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_runtime_dependency 'rb-readline', '~> 0.5.3'
24
+ spec.add_runtime_dependency 'slop', '~> 4.2'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.10'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rubocop', '~> 0.37.2'
29
+ end
@@ -1,2 +1,2 @@
1
- require 'glottis/version'
2
- require 'glottis/client'
1
+ require 'glottis/version'
2
+ require 'glottis/client'
@@ -1,46 +1,44 @@
1
- require 'thread'
2
- require 'logger'
3
- require 'glottis/handlers/console_input_handler'
4
- require 'glottis/handlers/console_output_handler'
5
- require 'glottis/handlers/remote_input_handler'
6
- require 'glottis/handlers/remote_output_handler'
7
-
8
- module Glottis
9
- # Client class, used to interact with the host specified.
10
- class Client
11
- def self.logger
12
- @logger ||= Logger.new(STDOUT)
13
- end
14
-
15
- def initialize(host, port, opts = {})
16
- @host = host
17
- @port = port
18
- @outgoing = Queue.new
19
- @incoming = Queue.new
20
- Client.logger.level = opts[:verbose] ? Logger::DEBUG : Logger::WARN
21
- end
22
-
23
- def run
24
- Client.logger.info('starting...')
25
- Thread.abort_on_exception = true
26
-
27
- @handlers = [
28
- Handlers::ConsoleInputHandler.new(@outgoing),
29
- Handlers::ConsoleOutputHandler.new(@incoming),
30
- Handlers::RemoteInputHandler.new(@incoming, @host, @port),
31
- Handlers::RemoteOutputHandler.new(@outgoing, @host, @port)
32
- ]
33
-
34
- @handlers.each(&:join)
35
- rescue Glottis::Exceptions::UserExitedException
36
- Client.logger.info('shutting down...')
37
- rescue Errno::ECONNREFUSED => conn_ref
38
- Client.logger.error("failed to connect: #{conn_ref}")
39
- rescue StandardError => ex
40
- Client.logger.warn("shutting down: #{ex}")
41
- ensure
42
- @handlers.each(&:cleanup)
43
- exit(0)
44
- end # run
45
- end # Client
46
- end
1
+ require 'thread'
2
+ require 'logger'
3
+ require 'glottis/handlers/console_input_handler'
4
+ require 'glottis/handlers/console_output_handler'
5
+ require 'glottis/handlers/remote_input_handler'
6
+ require 'glottis/handlers/remote_output_handler'
7
+
8
+ module Glottis
9
+ # Client class, used to interact with the host specified.
10
+ class Client
11
+ def self.logger
12
+ @logger ||= Logger.new(STDOUT)
13
+ end
14
+
15
+ def initialize(host, port, opts = {})
16
+ @host = host
17
+ @port = port
18
+ @outgoing = Queue.new
19
+ @incoming = Queue.new
20
+ Client.logger.level = opts[:verbose] ? Logger::DEBUG : Logger::WARN
21
+ end
22
+
23
+ def run
24
+ Client.logger.info('starting...')
25
+ Thread.abort_on_exception = true
26
+
27
+ @handlers = [
28
+ Handlers::ConsoleInputHandler.new(@outgoing),
29
+ Handlers::ConsoleOutputHandler.new(@incoming),
30
+ Handlers::RemoteInputHandler.new(@incoming, @host, @port),
31
+ Handlers::RemoteOutputHandler.new(@outgoing, @host, @port)
32
+ ]
33
+
34
+ @handlers.each(&:join)
35
+ rescue Errno::ECONNREFUSED => conn_ref
36
+ Client.logger.error("failed to connect: #{conn_ref}")
37
+ rescue StandardError => ex
38
+ Client.logger.warn("shutting down: #{ex}")
39
+ ensure
40
+ @handlers.each(&:cleanup)
41
+ exit(0)
42
+ end # run
43
+ end # Client
44
+ end
@@ -1,6 +1,6 @@
1
- module Glottis
2
- module Exceptions
3
- class GlottisException < StandardError
4
- end
5
- end
6
- end
1
+ module Glottis
2
+ module Exceptions
3
+ class GlottisException < StandardError
4
+ end
5
+ end
6
+ end
@@ -1,8 +1,8 @@
1
- require 'glottis/exceptions/glottis_exception'
2
-
3
- module Glottis
4
- module Exceptions
5
- class UserExitedException < GlottisException
6
- end
7
- end
8
- end
1
+ require 'glottis/exceptions/glottis_exception'
2
+
3
+ module Glottis
4
+ module Exceptions
5
+ class UserExitedException < GlottisException
6
+ end
7
+ end
8
+ end
@@ -1,32 +1,32 @@
1
- require 'glottis/exceptions/user_exited_exception'
2
- require 'readline'
3
-
4
- module Glottis
5
- module Handlers
6
- # This class holds a reference to the outgoing message queue,
7
- # and posts messages to it from the console as they are entered.
8
- class ConsoleInputHandler < Thread
9
- USER_PROMPT = '> '.freeze
10
-
11
- def initialize(outgoing)
12
- @outgoing = outgoing
13
- super do
14
- loop do
15
- user_input = Readline.readline(USER_PROMPT)
16
- Readline::HISTORY.push(user_input)
17
-
18
- # if user_input.nil?
19
- # raise Glottis::Exceptions::UserExitedException.new
20
- # end
21
-
22
- @outgoing.push(user_input)
23
- end
24
- end
25
- end
26
-
27
- def cleanup
28
- # do nothing
29
- end
30
- end # ConsoleInputHandler
31
- end # Handlers
32
- end # Glottis
1
+ require 'glottis/exceptions/user_exited_exception'
2
+ require 'readline'
3
+
4
+ module Glottis
5
+ module Handlers
6
+ # This class holds a reference to the outgoing message queue,
7
+ # and posts messages to it from the console as they are entered.
8
+ class ConsoleInputHandler < Thread
9
+ USER_PROMPT = '> '.freeze
10
+
11
+ def initialize(outgoing)
12
+ @outgoing = outgoing
13
+ super do
14
+ loop do
15
+ user_input = Readline.readline(USER_PROMPT)
16
+ Readline::HISTORY.push(user_input)
17
+
18
+ # if user_input.nil?
19
+ # raise Glottis::Exceptions::UserExitedException.new
20
+ # end
21
+
22
+ @outgoing.push(user_input)
23
+ end
24
+ end
25
+ end
26
+
27
+ def cleanup
28
+ # do nothing
29
+ end
30
+ end # ConsoleInputHandler
31
+ end # Handlers
32
+ end # Glottis
@@ -1,21 +1,21 @@
1
- module Glottis
2
- module Handlers
3
- # This class holds a reference to the incoming message queue,
4
- # and displays messages in the console as they are received.
5
- class ConsoleOutputHandler < Thread
6
- def initialize(incoming)
7
- @incoming = incoming
8
- super do
9
- loop do
10
- new_msg = @incoming.pop
11
- puts "#{new_msg['from']}, #{new_msg['to']}, #{new_msg['msg']}"
12
- end
13
- end
14
- end
15
-
16
- def cleanup
17
- puts '|'
18
- end
19
- end # ConsoleOutputHandler
20
- end # Handlers
21
- end # Glottis
1
+ module Glottis
2
+ module Handlers
3
+ # This class holds a reference to the incoming message queue,
4
+ # and displays messages in the console as they are received.
5
+ class ConsoleOutputHandler < Thread
6
+ def initialize(incoming)
7
+ @incoming = incoming
8
+ super do
9
+ loop do
10
+ new_msg = @incoming.pop
11
+ puts "#{new_msg['from']}, #{new_msg['to']}, #{new_msg['msg']}"
12
+ end
13
+ end
14
+ end
15
+
16
+ def cleanup
17
+ puts '|'
18
+ end
19
+ end # ConsoleOutputHandler
20
+ end # Handlers
21
+ end # Glottis
@@ -1,53 +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
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
@@ -1,107 +1,87 @@
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 RemoteOutputHandler < Thread
10
- POLL_INTERVAL = 0.1
11
- PROTOCOL = 'http'.freeze
12
-
13
- REMOTE_PATHS = {
14
- get_session: '/api/session',
15
- post_message: '/api/message'
16
- }.freeze
17
-
18
- def initialize(outgoing, host, port)
19
- @outgoing = outgoing
20
- @host = host
21
- @port = port
22
-
23
- setup_http
24
-
25
- super do
26
- @http.start
27
- request_session
28
-
29
- loop do
30
- send_queued
31
- end
32
- end
33
- end
34
-
35
- def cleanup
36
- @http.finish if @http.started?
37
- end
38
-
39
- private
40
-
41
- def setup_http
42
- @http = Net::HTTP.new(@host, @port)
43
- # TODO: make these configurable somewhere
44
- @http.open_timeout = 1
45
- @http.read_timeout = 1
46
- end
47
-
48
- def request_session
49
- Client.logger.info('making initial request for session...')
50
-
51
- session_req = @http.get(REMOTE_PATHS.fetch(:get_session))
52
-
53
- if Integer(session_req.code) != 201
54
- fail("failed to retrieve session: #{response}")
55
- end
56
-
57
- response = JSON.parse(session_req.body)
58
-
59
- @sid = response['sid']
60
- Client.logger.info("current session id: #{@sid}")
61
- end
62
-
63
- def build_messages_from
64
- [
65
- REMOTE_PATHS.fetch(:get_messages),
66
- '?',
67
- URI.encode_www_form([['from', @received_count.to_s]])
68
- ].join
69
- end
70
-
71
- # given the result of a .get or .post, converts the response code,
72
- # and executes the (side effecting) block if the response was not
73
- # successful. calls the block with a message describing the error.
74
- def if_not_ok(http_req, ok_code = 200, &b)
75
- b.call(http_req.body) if Integer(http_req.code) != ok_code
76
- end
77
-
78
- def request_messages
79
- Client.logger.debug("polling for messages with with path: #{build_messages_from}")
80
- messages_req = @http.get(build_messages_from)
81
-
82
- if_not_ok(messages_req) do |err|
83
- Client.logger.error("failed to retrieve messages: #{err}")
84
- return
85
- end
86
-
87
- process_new_messages(messages_req.body)
88
- end
89
-
90
- def send_queued
91
- Client.logger.info("processing message with #{@outgoing.size} messages outgoing")
92
-
93
- message_data = {
94
- from: @sid,
95
- to: '*',
96
- msg: @outgoing.pop
97
- }.to_json
98
-
99
- post_req = @http.post(REMOTE_PATHS.fetch(:post_message), message_data)
100
-
101
- if_not_ok(post_req) do |err|
102
- Client.logger.warn("failed to post message: #{message_data} #{err}")
103
- end
104
- end # send_queued
105
- end # RemoteOutputHandler
106
- end # Handlers
107
- end # Glottis
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 RemoteOutputHandler < Thread
10
+ POLL_INTERVAL = 0.1
11
+ PROTOCOL = 'http'.freeze
12
+
13
+ REMOTE_PATHS = {
14
+ get_session: '/api/session',
15
+ post_message: '/api/message'
16
+ }.freeze
17
+
18
+ def initialize(outgoing, host, port)
19
+ @outgoing = outgoing
20
+ @host = host
21
+ @port = port
22
+
23
+ setup_http
24
+
25
+ super do
26
+ @http.start
27
+ request_session
28
+
29
+ loop do
30
+ send_queued
31
+ end
32
+ end
33
+ end
34
+
35
+ def cleanup
36
+ @http.finish if @http.started?
37
+ end
38
+
39
+ private
40
+
41
+ def setup_http
42
+ @http = Net::HTTP.new(@host, @port)
43
+ # TODO: make these configurable somewhere
44
+ @http.open_timeout = 1
45
+ @http.read_timeout = 1
46
+ end
47
+
48
+ def request_session
49
+ Client.logger.info('making initial request for session...')
50
+
51
+ session_req = @http.get(REMOTE_PATHS.fetch(:get_session))
52
+
53
+ response = JSON.parse(session_req.body)
54
+
55
+ if Integer(session_req.code) != 201
56
+ raise "failed to retrieve session: #{response}"
57
+ end
58
+
59
+ @sid = response['sid']
60
+ Client.logger.info("current session id: #{@sid}")
61
+ end
62
+
63
+ # given the result of a .get or .post, converts the response code,
64
+ # and executes the (side effecting) block if the response was not
65
+ # successful. calls the block with a message describing the error.
66
+ def if_not_ok(http_req, ok_code = 200, &_b)
67
+ yield http_req.body if Integer(http_req.code) != ok_code
68
+ end
69
+
70
+ def send_queued
71
+ Client.logger.info("processing message with #{@outgoing.size} messages outgoing")
72
+
73
+ message_data = {
74
+ from: @sid,
75
+ to: '*',
76
+ msg: @outgoing.pop
77
+ }.to_json
78
+
79
+ post_req = @http.post(REMOTE_PATHS.fetch(:post_message), message_data)
80
+
81
+ if_not_ok(post_req) do |err|
82
+ Client.logger.warn("failed to post message: #{message_data} #{err}")
83
+ end
84
+ end # send_queued
85
+ end # RemoteOutputHandler
86
+ end # Handlers
87
+ end # Glottis
@@ -1,4 +1,3 @@
1
- # Autogenerated version module.
2
- module Glottis
3
- VERSION = '0.1.2'
4
- end
1
+ module Glottis
2
+ VERSION = '0.1.3'.freeze
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glottis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max DeLiso
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-12-13 00:00:00.000000000 Z
11
+ date: 2016-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb-readline
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.10'
55
- - !ruby/object:Gem::Dependency
56
- name: pry
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 0.10.3
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 0.10.3
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +72,14 @@ dependencies:
86
72
  requirements:
87
73
  - - "~>"
88
74
  - !ruby/object:Gem::Version
89
- version: 0.35.1
75
+ version: 0.37.2
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
- version: 0.35.1
82
+ version: 0.37.2
97
83
  description:
98
84
  email:
99
85
  - maxdeliso@gmail.com