ruby-dovado 1.0.3 → 1.0.4
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.
- checksums.yaml +4 -4
- data/lib/dovado.rb +1 -1
- data/lib/dovado/router.rb +8 -28
- data/lib/dovado/router/info.rb +19 -0
- data/lib/dovado/router/internet.rb +4 -0
- data/lib/dovado/router/services.rb +15 -0
- data/lib/dovado/router/sms.rb +5 -0
- data/lib/dovado/router/sms/messages.rb +4 -0
- data/lib/dovado/router/traffic.rb +101 -19
- data/lib/dovado/router/traffic/amount.rb +34 -7
- data/lib/dovado/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3d3a3bde16c3723672ddac0e2d50778259e9a20
|
4
|
+
data.tar.gz: e6fde4e985f7208770b782754c8d0fbe83f4028a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b98ebd1cddb85bf4d4128cb7b172a4f272dfa6abda5c7027469a73c5d19a0bce138740982d9454dcd42cf70b6bb13e8f3cb622987479163a2c894703cab4c22
|
7
|
+
data.tar.gz: b255461df8495cb18c79bb6972e64f9b1d6cc020f94d5015bfcc0d10969eefc684b3b97cca3fa04a48bc14f64ae3149c2e88726215c708af57b7067429137aa0
|
data/lib/dovado.rb
CHANGED
data/lib/dovado/router.rb
CHANGED
@@ -40,20 +40,15 @@ module Dovado
|
|
40
40
|
# @return [Services] The {Services} object
|
41
41
|
# @see {Services}
|
42
42
|
def services
|
43
|
-
|
43
|
+
Services.setup_supervision!
|
44
44
|
client = Actor[:client]
|
45
45
|
router_services = Actor[:router_services]
|
46
46
|
|
47
|
-
unless router_services.valid?
|
48
|
-
client.connect unless client.connected?
|
49
|
-
client.authenticate unless client.authenticated?
|
50
|
-
string = client.command('services')
|
51
|
-
router_services.create_from_string string
|
52
|
-
end
|
47
|
+
router_services.update! unless router_services.valid?
|
53
48
|
|
54
49
|
if router_services[:sms] == 'enabled'
|
55
50
|
|
56
|
-
Sms.
|
51
|
+
Sms.setup_supervision!
|
57
52
|
sms.enabled = true
|
58
53
|
end
|
59
54
|
router_services
|
@@ -69,7 +64,7 @@ module Dovado
|
|
69
64
|
# @return [Internet] the Internet Connection object.
|
70
65
|
# @see {Internet}
|
71
66
|
def internet
|
72
|
-
Internet.
|
67
|
+
Internet.setup_supervision!
|
73
68
|
Actor[:internet]
|
74
69
|
end
|
75
70
|
|
@@ -78,7 +73,7 @@ module Dovado
|
|
78
73
|
# @return [Traffic] the Data Traffic object
|
79
74
|
# @see {Traffic}
|
80
75
|
def traffic
|
81
|
-
Traffic.
|
76
|
+
Traffic.setup_supervision!
|
82
77
|
Actor[:traffic]
|
83
78
|
end
|
84
79
|
|
@@ -87,16 +82,11 @@ module Dovado
|
|
87
82
|
# @return [Info] The {Info} object.
|
88
83
|
# @see {Info}
|
89
84
|
def info
|
90
|
-
|
91
|
-
router_info = Actor[:router_info]
|
85
|
+
Info.setup_supervision!
|
92
86
|
client = Actor[:client]
|
93
87
|
router_info = Actor[:router_info]
|
94
|
-
unless router_info.valid?
|
95
|
-
|
96
|
-
client.authenticate unless client.authenticated?
|
97
|
-
info = client.command('info')
|
98
|
-
router_info.create_from_string info
|
99
|
-
end
|
88
|
+
router_info.update! unless router_info.valid?
|
89
|
+
|
100
90
|
services
|
101
91
|
router_info
|
102
92
|
rescue ConnectionError => ex
|
@@ -117,11 +107,6 @@ module Dovado
|
|
117
107
|
|
118
108
|
private
|
119
109
|
|
120
|
-
def supervise_services
|
121
|
-
return Services.supervise as: :router_services, size: 1 unless Actor[:router_services]
|
122
|
-
return Services.supervise as: :router_services, size: 1 if Actor[:router_services] and Actor[:router_services].dead?
|
123
|
-
end
|
124
|
-
|
125
110
|
def supervise_client
|
126
111
|
args = [{
|
127
112
|
server: @address,
|
@@ -134,10 +119,5 @@ module Dovado
|
|
134
119
|
return Client.supervise as: :client, size: 1, args: args if Actor[:router_services] and Actor[:router_services].dead?
|
135
120
|
end
|
136
121
|
|
137
|
-
def supervise_info
|
138
|
-
return Info.supervise as: :router_info, size: 1 unless Actor[:router_info]
|
139
|
-
return Info.supervise as: :router_info, size: 1 if Actor[:router_info] and Actor[:router_info].dead?
|
140
|
-
end
|
141
|
-
|
142
122
|
end
|
143
123
|
end
|
data/lib/dovado/router/info.rb
CHANGED
@@ -124,9 +124,22 @@ module Dovado
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
+
# Update the data in this {Info} object.
|
128
|
+
def update!
|
129
|
+
client = Actor[:client]
|
130
|
+
client.connect unless client.connected?
|
131
|
+
client.authenticate unless client.authenticated?
|
132
|
+
info = client.command('info')
|
133
|
+
create_from_string info
|
134
|
+
rescue ConnectionError => ex
|
135
|
+
Actor[:client].terminate
|
136
|
+
raise ex
|
137
|
+
end
|
138
|
+
|
127
139
|
# Create a new {Info} object from a +String+.
|
128
140
|
#
|
129
141
|
# @param [String] data_string router information string from the router.
|
142
|
+
# @api private
|
130
143
|
def create_from_string(data_string=nil)
|
131
144
|
unless Actor[:sms]
|
132
145
|
Sms.supervise as: :sms, size: 1
|
@@ -265,6 +278,12 @@ module Dovado
|
|
265
278
|
omni_method
|
266
279
|
end
|
267
280
|
|
281
|
+
# @api private
|
282
|
+
def self.setup_supervision!
|
283
|
+
return supervise as: :router_info, size: 1 unless Actor[:router_info]
|
284
|
+
return supervise as: :router_info, size: 1 if Actor[:router_info] and Actor[:router_info].dead?
|
285
|
+
end
|
286
|
+
|
268
287
|
private
|
269
288
|
|
270
289
|
def omni_method
|
@@ -35,6 +35,15 @@ module Dovado
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
# Update the data in this {Services} object.
|
39
|
+
def update!
|
40
|
+
client = Actor[:client]
|
41
|
+
client.connect unless client.connected?
|
42
|
+
client.authenticate unless client.authenticated?
|
43
|
+
string = client.command('services')
|
44
|
+
create_from_string string
|
45
|
+
end
|
46
|
+
|
38
47
|
# Create a new {Services} object from a string with values from the router
|
39
48
|
# API.
|
40
49
|
#
|
@@ -109,6 +118,12 @@ module Dovado
|
|
109
118
|
home_automation ? (home_automation == "enabled") : false
|
110
119
|
end
|
111
120
|
|
121
|
+
# @api private
|
122
|
+
def self.setup_supervision!
|
123
|
+
return supervise as: :router_services, size: 1 unless Actor[:router_services]
|
124
|
+
return supervise as: :router_services, size: 1 if Actor[:router_services] and Actor[:router_services].dead?
|
125
|
+
end
|
126
|
+
|
112
127
|
private
|
113
128
|
|
114
129
|
def touch!
|
data/lib/dovado/router/sms.rb
CHANGED
@@ -63,6 +63,7 @@ module Dovado
|
|
63
63
|
#
|
64
64
|
# @param [String] data_string String with text message data from the
|
65
65
|
# router.
|
66
|
+
# @api private
|
66
67
|
def create_from_string(data_string=nil)
|
67
68
|
data_array = data_string.split("\n")
|
68
69
|
data_array.each do |data_entry|
|
@@ -92,6 +93,10 @@ module Dovado
|
|
92
93
|
end
|
93
94
|
end
|
94
95
|
|
96
|
+
def self.setup_supervision!
|
97
|
+
supervise as: :sms, size: 1 unless Actor[:sms]
|
98
|
+
end
|
99
|
+
|
95
100
|
end
|
96
101
|
end
|
97
102
|
end
|
@@ -4,22 +4,45 @@ module Dovado
|
|
4
4
|
class Router
|
5
5
|
# Traffic Counters.
|
6
6
|
#
|
7
|
+
# Returns the traffic counters from the router. The developer will have to
|
8
|
+
# check the return values to determine if there is traffic for multiple
|
9
|
+
# modems available, see {#up} and {#down}, this can be done by checking the
|
10
|
+
# type of the return value of these commands.
|
11
|
+
#
|
12
|
+
# @example Single modem
|
13
|
+
# single_modem_amount = @router.traffic.down
|
14
|
+
#
|
15
|
+
# @example Two modems
|
16
|
+
# first_modem_amount = @router.traffic.down.first
|
17
|
+
# second_modem_amount = @router.traffic.down.last
|
18
|
+
#
|
19
|
+
# @example Checking the return value to see if there are multiple modems
|
20
|
+
# traffic_down = @router.traffic.down
|
21
|
+
# if traffic_down.is_a? Dovado::Router::Traffic::Amount
|
22
|
+
# return traffic_down.gigabytes
|
23
|
+
# elsif traffic_down.is_a? Array
|
24
|
+
# return traffic_down.first.gb + traffic_down.last.gb
|
25
|
+
# end
|
26
|
+
#
|
7
27
|
# @since 1.0.3
|
8
28
|
class Traffic
|
9
29
|
include Celluloid
|
10
30
|
|
11
|
-
# Create a new {
|
31
|
+
# Create a new {Traffic} object.
|
12
32
|
def initialize
|
13
33
|
@data = ThreadSafe::Cache.new
|
14
34
|
@client = Actor[:client] unless @client
|
15
35
|
@last_update = nil
|
16
|
-
@data[:down] = Traffic::Amount.new
|
17
|
-
@data[:up] = Traffic::Amount.new
|
36
|
+
@data[:down] = Traffic::Amount.new
|
37
|
+
@data[:up] = Traffic::Amount.new
|
18
38
|
end
|
19
39
|
|
20
40
|
# Data upload traffic amount.
|
21
41
|
#
|
22
|
-
#
|
42
|
+
# If two modems are used, the returned value is an array with {Amount}
|
43
|
+
# objects.
|
44
|
+
#
|
45
|
+
# @return [Amount, Array<Amount>] amount of uploaded data.
|
23
46
|
def up
|
24
47
|
update!
|
25
48
|
@data[:up]
|
@@ -27,22 +50,39 @@ module Dovado
|
|
27
50
|
|
28
51
|
# Data download traffic amount.
|
29
52
|
#
|
30
|
-
#
|
53
|
+
# If two modems are used, the returned value is an array with {Amount}
|
54
|
+
# objects.
|
55
|
+
#
|
56
|
+
# @return [Amount, Array<Amount>] amount of downloaded data.
|
31
57
|
def down
|
32
58
|
update!
|
33
59
|
@data[:down]
|
34
60
|
end
|
35
61
|
|
36
|
-
#
|
62
|
+
# Data download total traffic amount. Useful with multiple modems.
|
63
|
+
#
|
64
|
+
# @return [Amount] total amount of downloaded data.
|
65
|
+
def down_total
|
66
|
+
up, down = update_total_traffic_from_router_info
|
67
|
+
Traffic::Amount.new down
|
68
|
+
end
|
69
|
+
|
70
|
+
# Data upload total traffic amount. Useful with multiple modems.
|
71
|
+
#
|
72
|
+
# @return [Amount] total amount of uploaded data.
|
73
|
+
def up_total
|
74
|
+
up, down = update_total_traffic_from_router_info
|
75
|
+
Traffic::Amount.new up
|
76
|
+
end
|
77
|
+
|
78
|
+
# Update the data in this {Traffic} object.
|
37
79
|
def update!
|
38
80
|
unless valid?
|
39
81
|
begin
|
40
|
-
|
82
|
+
fetch_from_router
|
41
83
|
rescue
|
42
|
-
up, down = fetch_from_router_info
|
84
|
+
@data[:up], @data[:down] = fetch_from_router_info
|
43
85
|
end
|
44
|
-
@data[:down] = Traffic::Amount.new(down)
|
45
|
-
@data[:up] = Traffic::Amount.new(up)
|
46
86
|
touch!
|
47
87
|
end
|
48
88
|
end
|
@@ -55,6 +95,11 @@ module Dovado
|
|
55
95
|
(@last_update + SecureRandom.random_number(9) + 1 <= Time.now.to_i)
|
56
96
|
end
|
57
97
|
|
98
|
+
# @api private
|
99
|
+
def self.setup_supervision!
|
100
|
+
supervise as: :traffic, size: 1 unless Actor[:traffic]
|
101
|
+
end
|
102
|
+
|
58
103
|
private
|
59
104
|
|
60
105
|
def touch!
|
@@ -67,22 +112,59 @@ module Dovado
|
|
67
112
|
client.connect unless client.connected?
|
68
113
|
client.authenticate unless client.authenticated?
|
69
114
|
string = client.command('traffic')
|
115
|
+
# Two Modems
|
116
|
+
multiple = string.match(/(\d+)\W(\d+)\W\/\W(\d+)\n(\d+)\W(\d+)\W\/\W(\d+)/)
|
117
|
+
# One Modem
|
70
118
|
matched = string.match(/(\d+)\W(\d+)\W\/\W(\d+)/)
|
71
|
-
if
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
119
|
+
if multiple # Two modems found
|
120
|
+
if multiple[2]
|
121
|
+
down1 = Traffic::Amount.new matched[2].to_i
|
122
|
+
down1.sim_id = matched[1]
|
123
|
+
end
|
124
|
+
if multiple[3]
|
125
|
+
up1 = Traffic::Amount.new matched[3].to_i
|
126
|
+
up1.sim_id = matched[1]
|
127
|
+
end
|
128
|
+
if multiple[5]
|
129
|
+
down2 = Traffic::Amount.new matched[5].to_i
|
130
|
+
down2.sim_id = matched[4]
|
131
|
+
end
|
132
|
+
if multiple[6]
|
133
|
+
up2 = Traffic::Amount.new matched[6].to_i
|
134
|
+
up2.sim_id = matched[4]
|
135
|
+
end
|
136
|
+
@data[:up] = [up1, up2]
|
137
|
+
@data[:down] = [down1, down2]
|
138
|
+
elsif matched # only one modem found
|
139
|
+
if matched[2]
|
140
|
+
@data[:down] = Traffic::Amount.new matched[2].to_i
|
141
|
+
@data[:down].sim_id = matched[1]
|
142
|
+
end
|
143
|
+
if matched[3]
|
144
|
+
@data[:up] = Traffic::Amount.new matched[3].to_i
|
145
|
+
@data[:up].sim_id = matched[1]
|
146
|
+
end
|
147
|
+
else # Nothing found(?) return data from the Router::Info object
|
148
|
+
@data[:up], @data[:down] = fetch_from_router_info
|
76
149
|
end
|
77
|
-
[up, down]
|
150
|
+
[@data[:up], @data[:down]]
|
78
151
|
end
|
79
152
|
|
80
153
|
def fetch_from_router_info
|
81
154
|
up, down = [@data[:up], @data[:down]]
|
82
|
-
|
155
|
+
begin
|
156
|
+
up, down = update_total_traffic_from_router_info
|
157
|
+
rescue Exception
|
158
|
+
end
|
159
|
+
[up, down]
|
160
|
+
end
|
161
|
+
|
162
|
+
def update_total_traffic_from_router_info
|
163
|
+
Info.setup_supervision! unless Actor[:router_info]
|
83
164
|
router_info = Actor[:router_info]
|
84
|
-
|
85
|
-
|
165
|
+
router_info.update! unless router_info.valid?
|
166
|
+
down = router_info.traffic_modem_rx
|
167
|
+
up = router_info.traffic_modem_tx
|
86
168
|
[up, down]
|
87
169
|
end
|
88
170
|
|
@@ -11,43 +11,70 @@ module Dovado
|
|
11
11
|
# The default base of a kilobyte.
|
12
12
|
DEFAULT_KILO_BASE = 1024
|
13
13
|
|
14
|
+
attr_accessor :sim_id
|
15
|
+
|
14
16
|
# Create a new Amount object.
|
15
17
|
#
|
16
|
-
#
|
18
|
+
# Note: You can set the default base for a kilobyte in the router
|
19
|
+
# admin interface to +1000+ or +1024+, you should use the same base here
|
20
|
+
# to get the right figures. The base can differ from one operator to
|
21
|
+
# another.
|
22
|
+
#
|
23
|
+
# @param [Numeric] value value of this {Amount}, defaults to +0+.
|
17
24
|
# @param [Integer] base the base of a kilobyte.
|
18
|
-
def initialize(value, base=DEFAULT_KILO_BASE)
|
25
|
+
def initialize(value=0, base=DEFAULT_KILO_BASE)
|
19
26
|
raise ArgumentError.new "Argument is not numeric: #{value}" unless value.is_a? Numeric
|
20
27
|
@value = value
|
21
28
|
@base = base
|
22
29
|
end
|
23
30
|
|
24
|
-
# The {Amount} in bytes
|
31
|
+
# The {Amount} in bytes.
|
25
32
|
def bytes
|
26
33
|
@value * @base
|
27
34
|
end
|
28
35
|
|
29
|
-
#
|
36
|
+
# Shortcut to {#bytes}.
|
37
|
+
def b
|
38
|
+
bytes
|
39
|
+
end
|
40
|
+
|
41
|
+
# The {Amount} in kilobytes.
|
30
42
|
def kilobytes
|
31
43
|
@value
|
32
44
|
end
|
33
45
|
|
34
|
-
#
|
46
|
+
# Shortcut to {#kilobytes}.
|
47
|
+
def kb
|
48
|
+
kilobytes
|
49
|
+
end
|
50
|
+
|
51
|
+
# The {Amount} in megabytes.
|
35
52
|
def megabytes
|
36
53
|
(kilobytes / @base.to_f).round(2)
|
37
54
|
end
|
38
55
|
|
39
|
-
#
|
56
|
+
# Shortcut to {#megabytes}.
|
57
|
+
def mb
|
58
|
+
megabytes
|
59
|
+
end
|
60
|
+
|
61
|
+
# The {Amount} in gigabytes.
|
40
62
|
def gigabytes
|
41
63
|
(megabytes / @base.to_f).round(2)
|
42
64
|
end
|
43
65
|
|
66
|
+
# Shortcut to {#gigabytes}.
|
67
|
+
def gb
|
68
|
+
gigabytes
|
69
|
+
end
|
70
|
+
|
44
71
|
end
|
45
72
|
|
46
73
|
# Create a new {Amount} object.
|
47
74
|
#
|
48
75
|
# @param [Numeric] value initial value of the {Amount}.
|
49
76
|
# @param [Integer] base the base of a kilobyte.
|
50
|
-
def Amount(value, base=DEFAULT_KILO_BASE)
|
77
|
+
def Amount(value=0, base=DEFAULT_KILO_BASE)
|
51
78
|
Amount.new(value, base)
|
52
79
|
end
|
53
80
|
end
|
data/lib/dovado/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-dovado
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Lindblom
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid
|