aproxacs-sms_client 0.1.4 → 0.1.5
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/VERSION +1 -1
- data/lib/sms_client/client_pool.rb +13 -5
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
@@ -9,7 +9,7 @@ module SMS
|
|
9
9
|
# }
|
10
10
|
#
|
11
11
|
def initialize(config = {})
|
12
|
-
@config = config.to_a
|
12
|
+
@config = deep_symbolize_keys(config).to_a
|
13
13
|
sort
|
14
14
|
end
|
15
15
|
attr_accessor :from
|
@@ -19,19 +19,19 @@ module SMS
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def add(cli)
|
22
|
-
@config.concat cli.to_a
|
22
|
+
@config.concat deep_symbolize_keys(cli).to_a if cli.is_a? Hash
|
23
23
|
sort
|
24
24
|
end
|
25
25
|
|
26
26
|
def remove(key)
|
27
|
-
@config.delete(key)
|
27
|
+
@config.delete(key.to_sym)
|
28
28
|
end
|
29
29
|
|
30
30
|
def first
|
31
31
|
@config.each do |cf|
|
32
32
|
cli = Client.new(cf[0]) do |cli|
|
33
33
|
cli.from = from if from
|
34
|
-
cli.login(cf[1][
|
34
|
+
cli.login(cf[1][:id], cf[1][:password])
|
35
35
|
end
|
36
36
|
return cli if cli.available?
|
37
37
|
end
|
@@ -44,8 +44,16 @@ module SMS
|
|
44
44
|
private
|
45
45
|
def sort
|
46
46
|
@config.sort! do |a,b|
|
47
|
-
a[1][
|
47
|
+
a[1][:priority] <=> b[1][:priority]
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
def deep_symbolize_keys(hash)
|
52
|
+
hash.inject({}) { |result, (key, value)|
|
53
|
+
value = deep_symbolize_keys(value) if value.is_a? Hash
|
54
|
+
result[(key.to_sym rescue key) || key] = value
|
55
|
+
result
|
56
|
+
}
|
57
|
+
end
|
50
58
|
end
|
51
59
|
end
|