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 Gomobiledef sendSMS(mobile_number,password,recipient,message)agent = Mechanize.newpage = agent.get 'https://www.go.com.mt/mygo/'form = page.form('my_go_login')form.msisdn = mobile_numberform.password = passwordform.actionx = 'authenticatemain'page = agent.submit formcontent = agent.get pagepage = agent.get 'https://www.go.com.mt/mygo/main_right.jsp'form = page.form('smsform')form.phone_entries = recipientform.smsInput = messageform.message_template = ''len = 420 - message.lengthnum_of_smses = 1;if len > 279num_of_smses = 1elsif len > 147num_of_smses = 2elsif len > 11num_of_smses = 3elsif len > 0num_of_smses = 4elseraise Exception.new("You have exceeded the limit of 420 Characters")endform.count = len.to_s+'+%28'+num_of_smses.to_s+'+SMS%29'form.pentries = recipientpage = agent.submit formcontent = agent.get pageendend
Using the Class
load 'gomobile.rb'g = Gomobile.newg.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: