Class: Lokii::LocalSmsServer
- Defined in:
- lib/lokii/servers/local_sms_server.rb
Overview
The sms server operates against connected sms modem(s). If the ports property is specified in the settings it will try to pool connections to the various ports, otherwise it will attempt to auto-detect
Instance Attribute Summary collapse
-
#proxies ⇒ Object
readonly
Returns the value of attribute proxies.
Attributes inherited from Server
Instance Method Summary collapse
Methods inherited from Server
#complete, #daemon?, #disconnect, #process, #ready?, #running?, #setup, #stopped?
Instance Attribute Details
#proxies ⇒ Object (readonly)
Returns the value of attribute proxies.
8 9 10 |
# File 'lib/lokii/servers/local_sms_server.rb', line 8 def proxies @proxies end |
Instance Method Details
#check ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/lokii/servers/local_sms_server.rb', line 21 def check self.proxies.each {|proxy| proxy..each {|| begin hash = { :phone => 0, :number => [:from], :text => [:text], :created_at => [:created_at], :processed_at => [:processed_at]} handle(hash) rescue Exception => e Lokii::Logger.debug "Could not receive message from #{[:from]} (#{e.})" next end } } end |
#connect ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/lokii/servers/local_sms_server.rb', line 10 def connect Lokii::Logger.debug "Connecting" modems = [] ports = Lokii::Config.ports.split(',') rescue [] ports.each {|port| modems << Sms.new(port) } modems = [Sms.new] if modems.empty? modems.each {|modem| modem.encoding = Lokii::Config.encoding.to_sym} if Lokii::Config.encoding @proxies = modems.map{|modem| Lokii::LocalSmsProxy.new(modem) } @current = 0 end |
#say(text, number, reply = nil) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/lokii/servers/local_sms_server.rb', line 40 def say(text, number, reply = nil) @current += 1 @current = 0 if @current > @proxies.size - 1 @proxies[@current].sms(number.gsub(/\+/, ''), text) Lokii::Logger.debug "Message sent" rescue Exception => e Lokii::Logger.debug "Could not send message #{e.}" end |