Class: SMS::ClientPool
- Inherits:
-
Object
- Object
- SMS::ClientPool
- Defined in:
- lib/sms_client/client_pool.rb
Instance Attribute Summary collapse
-
#from ⇒ Object
Returns the value of attribute from.
Instance Method Summary collapse
- #add(cli) ⇒ Object
- #first ⇒ Object
-
#initialize(config = {}) ⇒ ClientPool
constructor
Config is like this => {“id” => “ID”, “password” => “PASSWORD”, “priority” => 3, “lgt” => => “ID”, “password” => “PASSWORD”, “priority” => 1 … }.
- #remove(key) ⇒ Object
- #size ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ ClientPool
Config is like this => {“id” => “ID”, “password” => “PASSWORD”, “priority” => 3,
"lgt" => {"id" => "ID", "password" => "PASSWORD", "priority" => 1}
...
}
11 12 13 14 |
# File 'lib/sms_client/client_pool.rb', line 11 def initialize(config = {}) @config = deep_symbolize_keys(config).to_a sort end |
Instance Attribute Details
#from ⇒ Object
Returns the value of attribute from.
15 16 17 |
# File 'lib/sms_client/client_pool.rb', line 15 def from @from end |
Instance Method Details
#add(cli) ⇒ Object
21 22 23 24 |
# File 'lib/sms_client/client_pool.rb', line 21 def add(cli) @config.concat deep_symbolize_keys(cli).to_a if cli.is_a? Hash sort end |
#first ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/sms_client/client_pool.rb', line 30 def first @config.each do |cf| cli = Client.new(cf[0]) do |cli| cli.from = from if from cli.login(cf[1][:id], cf[1][:password]) end return cli if cli.available? end end |
#remove(key) ⇒ Object
26 27 28 |
# File 'lib/sms_client/client_pool.rb', line 26 def remove(key) @config.delete(key.to_sym) end |
#size ⇒ Object
17 18 19 |
# File 'lib/sms_client/client_pool.rb', line 17 def size @config.size end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/sms_client/client_pool.rb', line 40 def to_s @config.to_s end |