Class: Lokii::LocalSmsServer

Inherits:
Server
  • Object
show all
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

Attributes inherited from Server

#handlers, #ready, #stopped

Instance Method Summary collapse

Methods inherited from Server

#complete, #daemon?, #disconnect, #process, #ready?, #running?, #setup, #stopped?

Instance Attribute Details

#proxiesObject (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

#checkObject



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.messages.each {|message|
      begin
        hash = {
          :phone => 0, 
          :number => message[:from], 
          :text => message[:text], 
          :created_at => message[:created_at], 
          :processed_at => message[:processed_at]}
        handle(hash)    
      rescue Exception => e
        Lokii::Logger.debug "Could not receive message from #{message[:from]} (#{e.message})"
        next
      end
    }      
  }  
end

#connectObject



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.message}"  
end