Sha256: eba01e5fd8ad9ea18ea135d523bbfd2e17d156d1f57cc38346632a82e0c1c743

Contents?: true

Size: 1.61 KB

Versions: 48

Compression:

Stored size: 1.61 KB

Contents

require 'apps/messenger/lib/sms_backend'

module Spider; module Messenger; module Backends; module SMS
    
    module SmsTools
        include Messenger::SMSBackend
        
        def self.send_message(msg)
            Spider.logger.debug("Sending SMS #{msg.ticket}")
            file_path = File.join(Spider.conf.get('messenger.smstools.path_outgoing'), msg.ticket)
            File.open(file_path, 'w') do |f|
                f << "To: +39#{msg.to}\n\n"
                f << msg.text
            end
            File.chmod(0666, file_path)
            return true
        end
        
        
        def self.update_statuses
            Messenger::SMS.where{ |sms| sms.status == :backend }.each do |msg|
                path_sent = nil
                path_failed = nil
                if p_sent = Spider.conf.get('messenger.smstools.path_sent')
                    path_sent = File.join(p_sent, msg.ticket)
                end
                if p_failed = Spider.conf.get('messenger.smstools.path_failed')
                    path_failed = File.join(p_failed, msg.ticket)
                end
                if path_sent && File.exist?(path_sent)
                    msg.status = :sent
                    msg.save
                    File.rm(path_failed) if Spider.conf.get('messenger.smstools.remove_sent')
                elsif path_failed && File.exist?(path_failed)
                    msg.add_failure
                    msg.save
                    File.rm(path_failed) if Spider.conf.get('messenger.smstools.remove_failed')
                end
            end
        end
        
        
        
    end
    
end; end; end; end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
spiderfw-0.6.21 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.20 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.19 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.18 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.17 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.16 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.15 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.14 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.13 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.12 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.11 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.10 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.9 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.8 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.7 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.6 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.5 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.4 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.3 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.2 apps/messenger/backends/sms/smstools.rb