Send SMS from Ruby On Rails application using web service, SOAP API
Posted by Bhushan G Ahire | Posted in Rails, ruby | Posted on 15-01-2010
0
SOAP4R is a Ruby library for accessing Web Services via SOAP. Recently I had a chance to explore SOAP4R. Here’s how to get started with it.
Installation
Although Ruby 1.8.x comes with SOAP4R in its standard library, it is an old, buggy version. I highly recommend using the latest gem (1.5.8 as of the this update). It has one dependency, httpclient.
gem install soap4r --include-dependencies
Service
There are many services available to send SMS but I prefer to use,
MailServe-SMS
MailServe-SMS, text messaging service, is everything you need for fast, no-frills, no-fuss text messaging. A quick and easy way to send SMS.
Let’s explore these further.
Method 1: Read the WSDL at run-time
require "soap/wsdlDriver" wsdl = "http://sms.qlc.co.in/smsapi.wsdl" driver = SOAP::WSDLDriverFactory.new(wsdl).create_rpc_drive
A single call to a driver factory reads the WSDL file, and creates a driver class for you to use, complete with the methods defined by the service. What if your service requires authentication? The driver inherits methods from httpclient, so you can specify its options as you would for httpclient:
Once driver is get initialised you need to call SMS sending API i.e. SendSMSRequest.
driver.SendSMSRequest("username", "password", "sender_no", "from_no", "message")
Once This will return you response 200 SMS sent successfully on success else if the information submitted was wrong then 500 Information submitted was incomplete.
Method 2: Generate classes from WSDL
SOAP4R installs a command-line utility called ‘wsdl2ruby’ which can generate a client or server.
Coming soon…..
