Class: SMS::ClientPool

Inherits:
Object
  • Object
show all
Defined in:
lib/sms_client/client_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#fromObject

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

#firstObject



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.(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

#sizeObject



17
18
19
# File 'lib/sms_client/client_pool.rb', line 17

def size
  @config.size
end

#to_sObject



40
41
42
# File 'lib/sms_client/client_pool.rb', line 40

def to_s
  @config.to_s
end