Introduction
A couple of days ago I have posted an explanation of how to send SMS messages over My Go Account using c#. I have decided to do the same but this time using Ruby. I will not go in detail of how to since the explanation can be found here
Requirements:
- GO Mobile phone line
- My Go account for the phone line (Free for every GO Mobile phone)
Tools Used:
Setup
After installing ruby always update your gems
You will need Mechanize gem.
gem install mechanize
Code
So the following Ruby Class in gomobile.rb has one method just to send an SMS.
require 'rubygems'
require 'mechanize'
class Gomobile
def sendSMS(mobile_number,password,recipient,message)
agent = Mechanize.new
page = agent.get 'https://www.go.com.mt/mygo/'
form = page.form('my_go_login')
form.msisdn = mobile_number
form.password = password
form.actionx = 'authenticatemain'
page = agent.submit form
content = agent.get page
page = agent.get 'https://www.go.com.mt/mygo/main_right.jsp'
form = page.form('smsform')
form.phone_entries = recipient
form.smsInput = message
form.message_template = ''
len = 420 - message.length
num_of_smses = 1;
if len > 279
num_of_smses = 1
elsif len > 147
num_of_smses = 2
elsif len > 11
num_of_smses = 3
elsif len > 0
num_of_smses = 4
else
raise Exception.new("You have exceeded the limit of 420 Characters")
end
form.count = len.to_s+'+%28'+num_of_smses.to_s+'+SMS%29'
form.pentries = recipient
page = agent.submit form
content = agent.get page
end
end
Using the Class
load 'gomobile.rb'
g = Gomobile.new
g.sendSMS("YOUR_NUMBER", "PASSWORD", "NUMBER_TO", "ACTUAL MESSAGE")
Known Issues:
Indentation in Ruby is important, so make sure you have it right.
If it fails to run swap
agent = Mechanize.new
with
agent = WWW::Mechanize.new
Please like & share: