HTTP request to send sms from rails app

485 Views Asked by At

I'm writing an sms sending function but it doesn't seem to send the sms.
Any idea by sight of this code why?

def self.send_sms(to, from, message)

username = "uname"
password = "pword"
id = rand(36**8).to_s(36)
dlr_url = URI::escape('http://www.skylinesms.com/messages/delivery?id=#{id}&type=%d')
send_url = 'http://localhost:13013/cgi-bin/sendsms?username=#{username}&password=#{password}&to=#{to}&from=#{from}&text=#{message}&dlr-url=#{dlr_url}&dlr-mask=3'
url = URI.parse(URI.encode(send_url))            
req = Net::HTTP::Get.new(url.to_s)
res = Net::HTTP.start(url.host, url.port) {|http|  http.request(req)   }
return res.body

end
1

There are 1 best solutions below

0
On

I'm not sure but I think so

def self.send_sms(to, from, message)
    .....
    Net::HTTP.start(url.host, url.port) { |http| http.get(req.request_uri).body }
  end