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-1.0.1 apps/messenger/backends/sms/smstools.rb
spiderfw-1.0.0 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.39 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.38 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.37 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.35 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.34 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.33 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.32 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.31 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.30 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.29 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.28 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.27 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.26 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.26.pre1 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.25 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.24 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.23 apps/messenger/backends/sms/smstools.rb
spiderfw-0.6.22 apps/messenger/backends/sms/smstools.rb