Send an SMS over My GO account programmatically using Ruby (Outdated)

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.

  1. require 'rubygems'
  2. require 'mechanize'
  3. class Gomobile
  4. def sendSMS(mobile_number,password,recipient,message)
  5. agent = Mechanize.new
  6. page = agent.get 'https://www.go.com.mt/mygo/'
  7. form = page.form('my_go_login')
  8. form.msisdn = mobile_number
  9. form.password = password
  10. form.actionx = 'authenticatemain'
  11. page = agent.submit form
  12. content = agent.get page
  13. page = agent.get 'https://www.go.com.mt/mygo/main_right.jsp'
  14. form = page.form('smsform')
  15. form.phone_entries = recipient
  16. form.smsInput = message
  17. form.message_template = ''
  18. len = 420 - message.length
  19. num_of_smses = 1;
  20. if len > 279
  21. num_of_smses = 1
  22. elsif len > 147
  23. num_of_smses = 2
  24. elsif len > 11
  25. num_of_smses = 3
  26. elsif len > 0
  27. num_of_smses = 4
  28. else
  29. raise Exception.new("You have exceeded the limit of 420 Characters")
  30. end
  31. form.count = len.to_s+'+%28'+num_of_smses.to_s+'+SMS%29'
  32. form.pentries = recipient
  33. page = agent.submit form
  34. content = agent.get page
  35. end
  36. end

Using the Class

  1. load 'gomobile.rb'
  2. g = Gomobile.new
  3. 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