otstatus 0.1.2 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/otstatus.rb +48 -12
  3. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a2d17476a9c5b4ac0bb931b706a9d08082f6dc7
4
- data.tar.gz: d25c94bee951622a688e9965e643f8cb6f1d3669
3
+ metadata.gz: 3372fd858d8fed587c986227cb1e530a0a2a456d
4
+ data.tar.gz: dc722af8b79ffe69c2d0967e4df204fc05334ca4
5
5
  SHA512:
6
- metadata.gz: 9b4df941069547ad480c72e9888a3a93d1d8dc0760ef5ccbba9f77ed75f9e175e920c570ce69fb1d9578f3d95c5e3c6fa5486d9c0980d42e8c736231fc4537c2
7
- data.tar.gz: 69df080684b97a27625958ef257580c0dc3b8450ce4da1c0d1194957bc13fb699c4202380b6d4679de7b1804a67d05fdc04afd137b389119c81b0da394e9ecae
6
+ metadata.gz: 7f49b93f29d113980e0f59e8df5d3e52cb3f0a8206bf09ab3b4ffc75407f921ac9967f2f1c7fedad2eb91ab29f8798ed77364c5fb219d3316dccfda559137ca4
7
+ data.tar.gz: 30943fbd2480e83b7fb94d2a75911604ab46191561b623ec51f32883abb955c758acf38b3a21e58718c772dab27dde568c05edddd037039f15f7a0a298c1ed12
data/lib/otstatus.rb CHANGED
@@ -1,17 +1,53 @@
1
- require 'socket'
1
+ require 'rubygems'
2
+ require 'eventmachine'
2
3
  require 'nori'
3
4
 
4
5
  module OtStatus
5
- VERSION = '0.1.2'
6
- QUERY = [6.chr, 0.chr, 255.chr, 255.chr, 'info'].join
7
-
8
- def self.query hostname, port, timeout=1
9
- socket = Socket.tcp hostname, port, connect_timeout: timeout
10
- socket.print QUERY
11
- socket.close_write
12
- result = socket.read
13
- socket.close
14
- parser = Nori.new
15
- parser.parse(result)['tsqp']
6
+ VERSION = '0.2.1'
7
+
8
+ class Query
9
+ attr_accessor :response
10
+
11
+ def initialize
12
+ @response = nil
13
+ end
14
+
15
+ def run hostname, port
16
+ EventMachine.run {
17
+ EventMachine::connect hostname, port, Connection, self
18
+ }
19
+
20
+ parse @response
21
+ end
22
+
23
+ private
24
+ def parse data
25
+ parser = Nori.new
26
+ parser.parse(data)['tsqp']
27
+ end
28
+
29
+ class Connection < EventMachine::Connection
30
+ QUERY = [6.chr, 0.chr, 255.chr, 255.chr, 'info'].join
31
+
32
+ attr_reader :query
33
+
34
+ def initialize query
35
+ @query = query
36
+ end
37
+
38
+ def post_init
39
+ send_data QUERY
40
+ @data = ""
41
+ end
42
+
43
+ def receive_data data
44
+ @data << data
45
+ query.response = @data
46
+ end
47
+
48
+ def unbind
49
+ EventMachine::stop_event_loop
50
+ end
51
+ end
16
52
  end
17
53
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: otstatus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Thelander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-06 00:00:00.000000000 Z
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eventmachine
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: nori
15
29
  requirement: !ruby/object:Gem::Requirement