gts 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/gts +1 -0
- data/gts.gemspec +1 -1
- data/lib/gts/command.rb +9 -1
- data/lib/gts/commands/dump_command.rb +16 -0
- data/lib/gts/commands/dump_size_command.rb +16 -0
- data/lib/gts/commands/help_command.rb +17 -0
- data/lib/gts/commands/list_known_devices_command.rb +2 -2
- data/lib/gts/commands/storage_info_command.rb +16 -0
- data/lib/gts/commands/uptime_command.rb +1 -1
- data/lib/gts/server.rb +1 -0
- data/lib/gts/storage.rb +26 -0
- data/lib/gts/storages/redis_storage.rb +46 -0
- data/lib/gts/version.rb +1 -1
- data/lib/gts.rb +9 -0
- metadata +8 -2
data/bin/gts
CHANGED
@@ -51,4 +51,5 @@ Signal.trap("INT") { Gts::Server.stop! }
|
|
51
51
|
Signal.trap("TERM") { Gts::Server.stop! }
|
52
52
|
|
53
53
|
Gts.server = Gts::Server
|
54
|
+
Gts.storage = Gts::RedisStorage.new(:host => "0.0.0.0", :port => 6379) # we use just this one so far, TODO should be configurable
|
54
55
|
Gts.server.start!(:address => options[:address], :port => options[:port], :output_file => options[:output_file])
|
data/gts.gemspec
CHANGED
data/lib/gts/command.rb
CHANGED
@@ -8,10 +8,13 @@ module Gts
|
|
8
8
|
class UnknownCommand < CommandError; end
|
9
9
|
|
10
10
|
@@known_commands = {}
|
11
|
+
@@known_commands_descriptions = {}
|
12
|
+
|
11
13
|
attr_reader :args
|
12
14
|
|
13
|
-
def self.register(name, handler)
|
15
|
+
def self.register(name, handler, desc="")
|
14
16
|
@@known_commands[name] = handler
|
17
|
+
@@known_commands_descriptions[name] = desc
|
15
18
|
end
|
16
19
|
|
17
20
|
def self.execute(command_str)
|
@@ -20,6 +23,11 @@ module Gts
|
|
20
23
|
command_handler(command_name.to_sym).execute
|
21
24
|
end
|
22
25
|
|
26
|
+
def self.known_commands_descriptions
|
27
|
+
@@known_commands_descriptions
|
28
|
+
end
|
29
|
+
|
30
|
+
|
23
31
|
private
|
24
32
|
|
25
33
|
def self.command_handler(command_name)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "gts/command"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Gts
|
5
|
+
|
6
|
+
class DumpCommand < Command
|
7
|
+
|
8
|
+
Gts::Command.register :dump, self, "Dumps captured GPS data from tracking devices into json"
|
9
|
+
|
10
|
+
def execute
|
11
|
+
Gts.storage.dump.map{|l| JSON.parse(l) }.to_json
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "gts/command"
|
2
|
+
|
3
|
+
module Gts
|
4
|
+
|
5
|
+
class DumpSizeCommand < Command
|
6
|
+
|
7
|
+
Gts::Command.register :dump_size, self, "Returns number of records saved in the storage"
|
8
|
+
Gts::Command.register :ds, self, "Alias for dump_size"
|
9
|
+
|
10
|
+
def execute
|
11
|
+
Gts.storage.size.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "gts/command"
|
2
|
+
|
3
|
+
module Gts
|
4
|
+
|
5
|
+
class HelpCommand < Command
|
6
|
+
|
7
|
+
Gts::Command.register :help, self, "Returns this list"
|
8
|
+
|
9
|
+
def execute
|
10
|
+
Gts::Command.known_commands_descriptions.map { |k, v|
|
11
|
+
"#{k.to_s.ljust(30)} - #{v}"
|
12
|
+
}.join("\n")
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -4,8 +4,8 @@ module Gts
|
|
4
4
|
|
5
5
|
class ListKnownDevicesCommand < Command
|
6
6
|
|
7
|
-
Gts::Command.register :list_known_devices, self
|
8
|
-
Gts::Command.register :ld, self
|
7
|
+
Gts::Command.register :list_known_devices, self, "Lists all IMEIs together with the type of device"
|
8
|
+
Gts::Command.register :ld, self, "Alias for list_known_devices"
|
9
9
|
|
10
10
|
def execute
|
11
11
|
Gts.server.list_known_devices
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "gts/command"
|
2
|
+
|
3
|
+
module Gts
|
4
|
+
|
5
|
+
class StorageInfoCommand < Command
|
6
|
+
|
7
|
+
Gts::Command.register :storage_info, self, "Returns information about storage engine"
|
8
|
+
Gts::Command.register :si, self, "Alias for storage_info"
|
9
|
+
|
10
|
+
def execute
|
11
|
+
Gts.storage.info
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/gts/server.rb
CHANGED
@@ -96,6 +96,7 @@ module Gts
|
|
96
96
|
logger.info "Got correct data [from #{client_ip_address}, imei: #{parsed_data[:imei]}]"
|
97
97
|
formatted_data = parsed_data.map{|k,v| "\t#{k}: #{v}\n" }.join
|
98
98
|
logger.debug "Parsed data:\n" + formatted_data
|
99
|
+
Gts.storage.append parsed_data.to_json
|
99
100
|
log_data_to_csv_file(parsed_data)
|
100
101
|
rescue GtsError => e
|
101
102
|
if parsed_data.is_a?(Hash) && parsed_data[:imei]
|
data/lib/gts/storage.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Gts
|
2
|
+
class Storage
|
3
|
+
|
4
|
+
# append new item to the end of the list
|
5
|
+
def append(value)
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
# get all the elements in the list and empty it
|
10
|
+
def dump
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
# get the count of the elements in the list
|
15
|
+
def size
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
def info
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Dir[File.dirname(__FILE__) +"/storages/*.rb"].each {|file| require file }
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "redis"
|
2
|
+
|
3
|
+
module Gts
|
4
|
+
|
5
|
+
class RedisStorage < Gts::Storage
|
6
|
+
|
7
|
+
attr_reader :redis, :host, :port, :list_id
|
8
|
+
|
9
|
+
def initialize(opts)
|
10
|
+
@host = opts[:host] || "0.0.0.0"
|
11
|
+
@port = opts[:port] || "6379"
|
12
|
+
@list_id = opts[:list_id] || "gts_data"
|
13
|
+
@redis = Redis.new(:host => @host, :port => @port)
|
14
|
+
begin
|
15
|
+
@redis.ping
|
16
|
+
rescue Redis::CannotConnectError
|
17
|
+
puts "Failed to start. Redis is not running or wrong host/port provided."
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# append new item to the end of the list
|
23
|
+
def append(value)
|
24
|
+
redis.rpush list_id, value
|
25
|
+
end
|
26
|
+
|
27
|
+
# get all the elements in the list and empty it
|
28
|
+
def dump
|
29
|
+
current_size = size
|
30
|
+
dumped_items = redis.lrange list_id, 0, current_size - 1
|
31
|
+
redis.ltrim list_id, current_size, size - 1
|
32
|
+
dumped_items
|
33
|
+
end
|
34
|
+
|
35
|
+
# get the count of the elements in the list
|
36
|
+
def size
|
37
|
+
redis.llen list_id
|
38
|
+
end
|
39
|
+
|
40
|
+
def info
|
41
|
+
redis.info.map{ |k,v| "#{k}: #{v}" }.join("\n")
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/lib/gts/version.rb
CHANGED
data/lib/gts.rb
CHANGED
@@ -53,6 +53,14 @@ module Gts
|
|
53
53
|
@@server
|
54
54
|
end
|
55
55
|
|
56
|
+
def self.storage=(storage)
|
57
|
+
@@storage = storage
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.storage
|
61
|
+
@@storage
|
62
|
+
end
|
63
|
+
|
56
64
|
end
|
57
65
|
|
58
66
|
require "gts/version"
|
@@ -60,4 +68,5 @@ require "gts/utils/phone_system"
|
|
60
68
|
require "gts/abstract_gps_tracker_handler"
|
61
69
|
require "gts/handlers/tk102_handler"
|
62
70
|
require "gts/command"
|
71
|
+
require "gts/storage"
|
63
72
|
require "gts/server"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: redis
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -94,10 +94,16 @@ files:
|
|
94
94
|
- lib/gts/abstract_gps_tracker_handler.rb
|
95
95
|
- lib/gts/command.rb
|
96
96
|
- lib/gts/command_parser.rb
|
97
|
+
- lib/gts/commands/dump_command.rb
|
98
|
+
- lib/gts/commands/dump_size_command.rb
|
99
|
+
- lib/gts/commands/help_command.rb
|
97
100
|
- lib/gts/commands/list_known_devices_command.rb
|
101
|
+
- lib/gts/commands/storage_info_command.rb
|
98
102
|
- lib/gts/commands/uptime_command.rb
|
99
103
|
- lib/gts/handlers/tk102_handler.rb
|
100
104
|
- lib/gts/server.rb
|
105
|
+
- lib/gts/storage.rb
|
106
|
+
- lib/gts/storages/redis_storage.rb
|
101
107
|
- lib/gts/utils/phone_codes.yml
|
102
108
|
- lib/gts/utils/phone_system.rb
|
103
109
|
- lib/gts/version.rb
|