Sha256: 0e677aeb17af1817e8e3defc9e997f6f2501bebd00a9314c13ddf4bfc56da052

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 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" => Knj::Php.md5(@opts[:pass]),
				"smsTo" => {"string" => number},
				"smscontents" => msg,
				"sendDate" => Knj::Php.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" => Knj::Php.date("Y-m-d H:i:s")
			})
		else
			raise "Not supported: " + @type
		end
	end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
knjrbfw-0.0.8 lib/knj/sms.rb
knjrbfw-0.0.7 lib/knj/sms.rb
knjrbfw-0.0.4 lib/knj/sms.rb
knjrbfw-0.0.3 lib/knj/sms.rb