Website Network

Sending Free SMS from Ruby

This is a quick demo of how to send Free SMS from Ruby, via our webservice

Download Ruby, Create two files using Scite, SMS.rb, and RechnerServiceModule.rb

SMS.rb is as follows:

require "soap/rpc/driver"
require "RechnerServiceModule"
include RechnerServiceModule

server = 'http://www.freebiesms.co.uk/sendsms.asmx'

wiredump_dev=STDERR

service = SOAP::RPC::Driver.new(server, RechnerServiceModule::InterfaceNS)
service.wiredump_dev=wiredump_dev

service.default_encodingstyle = SOAP::EncodingStyle::ASPDotNetHandler::Namespace
RechnerServiceModule::add_method(service)

result = service.SendSms("Bob","004478660xxxx","00447866xxxxx","Hello From Ruby","en-GB")

(Replace xxxx with the mobile number)

Then RechnerServiceModule.rb is as follows

module RechnerServiceModule
InterfaceNS = 'http://FreebieSMS.co.uk'
Methods=[['SendSms','FromName','FromNumber','ToNumber','Message','locale']]

def RechnerServiceModule.add_method(drv)
Methods.each do |method, *param|
drv.add_method_with_soapaction(method, InterfaceNS+"/#{ method }", *param)
end
end
end

Press Tools > Go (or F5) with SMS.rb highlighted, and you should see this:

>ruby sms.rb
Wire dump:

opening connection to www.freebiesms.co.uk...
opened
<- "POST /sendsms.asmx HTTP/1.1\r\nAccept: */*\r\nContent-Type: text/xml; charset=utf-8\r\nUser-Agent: SOAP4R/1.5.5\r\nSoapaction: \"http://FreebieSMS.co.uk/SendSms\"\r\nContent-Length: 547\r\nHost: www.freebiesms.co.uk\r\n\r\n"
<- "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<env:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n    xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\"\n    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n  <env:Body>\n    <n1:SendSms xmlns:n1=\"http://FreebieSMS.co.uk\">\n      <n1:FromName>Bob</n1:FromName>\n      <n1:FromNumber>004478660xxxx</n1:FromNumber>\n      <n1:ToNumber>0044786606xxx</n1:ToNumber>\n      <n1:Message>Hello From Ruby</n1:Message>\n      <n1:locale>en-GB</n1:locale>\n    </n1:SendSms>\n  </env:Body>\n</env:Envelope>"
-> "HTTP/1.1 200 OK\r\n"
-> "Date: Sun, 26 Jul 2009 15:49:50 GMT\r\n"
-> "Server: Microsoft-IIS/6.0\r\n"
-> "X-Powered-By: ASP.NET\r\n"
-> "X-AspNet-Version: 2.0.50727\r\n"
-> "Cache-Control: no-cache\r\n"
-> "Pragma: no-cache\r\n"
-> "Expires: -1\r\n"
-> "Content-Type: text/xml; charset=utf-8\r\n"
-> "Content-Length: 297\r\n"
-> "\r\n"
reading 297 bytes...
-> "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><SendSmsResponse xmlns=\"http://FreebieSMS.co.uk\" /></soap:Body></soap:Envelope>"
read 297 bytes
Conn keep-alive
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SendSmsResponse xmlns="http://FreebieSMS.co.uk" /></soap:Body></soap:Envelope>

>Exit code: 0

Code Download > Free SMS Ruby

Comments