Skip to content

Instantly share code, notes, and snippets.

@bjjb
Created January 2, 2013 19:00
Show Gist options
  • Save bjjb/4436920 to your computer and use it in GitHub Desktop.
Save bjjb/4436920 to your computer and use it in GitHub Desktop.
A simple Ruby program for sending webtexts from three.ie.
#!/usr/bin/env ruby
$username = "08312345676" # Replace with your phone number
$password = "000000" # Replace with your webtext PIN
require 'mechanize'
# A simple three.ie webtext CLI.
# Requires Ruby 1.9 and Mechanize (gem install mechanize)
# Logs in, fills in the webtext form, submits it, and prints out the result.
# Pass recipients as arguments to the script (full numbers, like +1234567890)
# Then type away, and enter ^D (Ctrl+D) to send the SMS.
class Three < Mechanize
def initialize
super
@username = $username
@password = $password
@page = get("https://webtexts.three.ie")
end
def login
form = @page.form(action: '/webtext/users/login')
form['data[User][telephoneNo]'] = @username
form['data[User][pin]'] = @password
@page = form.submit
self
end
def send_message(message, *recipients)
return if recipients.size == 0
form = @page.form(action: '/webtext/messages/send')
form['data[Message][message]'] = message
form['data[Message][recipients_individual]'] = recipients.join(',')
@page = form.submit
puts @page.at('#flashMessage span').text
puts
puts status
self
end
def status
@page.search("#hub_overview ul li").map(&:text).join("\n")
end
end
recipients = ARGV.shift until ARGV.empty?
message = ARGF.read
Three.new.login.send_message(message, recipients)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment