I created a simple form that enables the user to enter the text of the short message, the sender name (or number), and the destination mobile number. A copy of the message should be stored in the database as the user sends it. I have created a Message model that has the required fields.
I have the following scaffold-generated create method that creates a message and stores it in the database:
******************************************************
def create
@message = Message.new(params[:message])
respond_to do |format|
if @message.save
flash[:notice] = 'Message was successfully created.'
format.html { redirect_to(@message) }
format.xml { render :xml => @message, :status => :created, :location => @message }
else
format.html { render :action => "new" }
format.xml { render :xml => @message.errors, :status => :unprocessable_entity }
end
end
I created a simple form that enables the user to enter the text of
the short message, the sender name (or number), and the destination
mobile number. A copy of the message should be stored in the
database as the user sends it. I have created a Message model that
has the required fields.
I have the following scaffold-generated create method that creates a
message and stores it in the database:
You need to have a look at the Net::HTTP libraries, which allows you
to make http requests of various sorts. If i were you, I'd add a send
method to the Message model which does the necessary dtugg.
class Message < ActiveRecord::Base
def sendsms
require "net/http"
Net::HTTP.get_response('www.domain.com','/sendsms/sendsms.asp?
username=xxxx&password=xxxx&mno=999999&msg=Hi from
rails&Sid=xxxx&fl=0&mt=0')
end
Now it works but is there any possibility that the URL could be
exposed in a way or another to some bad user? Is there something
like encrypting the URL or something? Or is it just safe to use the
above method?
It's not impossible for someone in the right place at the right time
to snoop that username and password. There's not a lot you can do
about that unless the people providing the service also provide https
access (or use some other mitigating scheme, eg only allowing requests
from certain ip addresses.
In case of sending Unicode messages I have to convert the message’s characters to hexadecimal, I’ve looked into Ruby documentation but it looks like Ruby doesn’t have enough regarding to this issue. I’ve been searching for hours but didn’t find a perfect solution … do you have any suggestion guys?
For the record, all carriers have an email SMS system.
Sprint: [10-digit number]@messaging.sprintpcs.com
Cingular / ATT : [number]@txt.att.com
These services are of course free, and subject to limitations and
possibly delays. If you need to send a ton of SMSes out, or need
guarenteed quick delivery, you'll need to look into an SMS gateway
service like clickatell.
For the record, all carriers have an email SMS system.
Sprint: [10-digit number]@messaging.sprintpcs.com
Cingular / ATT : [number]@txt.att.com
These services are of course free, and subject to limitations and
possibly delays. If you need to send a ton of SMSes out, or need
guarenteed quick delivery, you'll need to look into an SMS gateway
service like clickatell.