Sha256: 7ef93f119381eddbba5d691e981e44b09bbae0e46bd68a7658536a05a77d3412

Contents?: true

Size: 1.58 KB

Versions: 40

Compression:

Stored size: 1.58 KB

Contents

class Knj::Sms
  def initialize(opts)
    @opts = Knj::ArrayExt.hash_sym(opts)
    
    @opts.each do |key, value|
      if key == :type
        if value == "bibob" or value == "cbb" or value == "smsd_db"
          @type = value
          
          if @type == "smsd_db"
            @db = Knj::Db.new(@opts[:knjdb_args])
            Knj::Thread.new(@db) do |db|
              db.query("SELECT * FROM outbox WHERE id = 0") #ping!
              sleep 15
            end
          end
        else
          raise "Not supported: " + value.to_s
        end
      end
    end
  end
  
  def send_sms(number, msg)
    if @type == "bibob"
      if !@soap
        require "webrick/https"
        @soap = SOAP::WSDLDriverFactory.new("https://www.bibob.dk/SmsSender.asmx?WSDL").create_rpc_driver
      end
      
      result = @soap.SendMessage({
        "cellphone" => @opts[:user],
        "password" => Php4r.md5(@opts[:pass]),
        "smsTo" => {"string" => number},
        "smscontents" => msg,
        "sendDate" => Php4r.date("Y-m-d"),
        "deliveryReport" => "0",
        "fromNumber" => @opts[:user]
      })
      
      if result.sendMessageResult.errorString.to_s != "Ingen fejl."
        raise "Could not send SMS: (" + result.sendMessageResult.errorCode.to_s + "): " + result.sendMessageResult.errorString.to_s
      end
    elsif @type == "smsd_db"
      @db.insert("outbox", {
        "number" => number,
        "text" => msg,
        "insertdate" => Php4r.date("Y-m-d H:i:s")
      })
    else
      raise "Not supported: " + @type
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
knjrbfw-0.0.116 lib/knj/sms.rb
knjrbfw-0.0.115 lib/knj/sms.rb
knjrbfw-0.0.114 lib/knj/sms.rb
knjrbfw-0.0.113 lib/knj/sms.rb
knjrbfw-0.0.111 lib/knj/sms.rb
knjrbfw-0.0.110 lib/knj/sms.rb
knjrbfw-0.0.109 lib/knj/sms.rb
knjrbfw-0.0.108 lib/knj/sms.rb
knjrbfw-0.0.107 lib/knj/sms.rb
knjrbfw-0.0.105 lib/knj/sms.rb
knjrbfw-0.0.104 lib/knj/sms.rb
knjrbfw-0.0.103 lib/knj/sms.rb
knjrbfw-0.0.102 lib/knj/sms.rb
knjrbfw-0.0.101 lib/knj/sms.rb
knjrbfw-0.0.100 lib/knj/sms.rb
knjrbfw-0.0.99 lib/knj/sms.rb
knjrbfw-0.0.98 lib/knj/sms.rb
knjrbfw-0.0.97 lib/knj/sms.rb
knjrbfw-0.0.96 lib/knj/sms.rb
knjrbfw-0.0.95 lib/knj/sms.rb