Ruby Script: Remaining Mobile BB Data Allowance

I recently changed to as my mobile broadband provider. They provide a nice handy way of checking remaining monthly data allowance via their "" service. Signing in is handled automatically on their side based on the network you're using. Handy!

Since I've been messing around with Ruby a bit I figured I'd try and make a ruby script that would check my remaining data for me! My efforts are below!

Please comment on any improvements that you think I can make. Especially relating to the instance vs. class variables!

I use this script in combination with a bash script to display data on my desktop using GeekTool. The bash script attempts to ping the mobile gateway's IP address. If it is available, the ruby script is executed. Simples!



#	Pings once to see if my Huawei B260a mobile gateway is reachable
#	if yes, execute Ruby data allowance checker
#	else, exit
ping -c 1 -t 2 >/dev/null
if [[ $? == 0 ]]; then
	ruby ~/Programming/Ruby/MyStuff/threeMobileBroadband.rb



#!/usr/bin/env ruby
require 'rubygems'
require 'mechanize'

class ThreeMobileBroadband

@@baseURL = ""
def login
  @agent =

  # First Single Sign On page
  @landing1 = @agent.get ''
  @landing2 = @agent.get @landing1.links[0].uri
  # Then click the continue button presented to get to account options section
  @@usagePage ="#{@@baseURL}#{@landing2.forms[0].action}")

def getRemainingData
  # Parse for remaining data table
  @usageValue =  @@usagePage.parser.xpath('//div/div/div/div/table/tbody/tr/td').to_s
  # Get the data, and sub out HTML, then sub out whitespace, then split into array at a close bracket
  @data = @usageValue.gsub(/<\/?[^>]*>/, "").gsub(/\s+/, "").split(/\)/)
  return @data[1]#.inspect

def remainingDataAsOf
  # Parse for caption containing the date & time the remaining data was checked
  @asOfDate = @@usagePage.parser.xpath('//div/div/div/caption/span').to_s.gsub(/<\/?[^>]*>/, "").gsub(/\*\s+/, "")
  return @asOfDate


three =

puts "3 Mobile Broadband Pro"
puts "-----------"
puts "#{three.getRemainingData} MB remaining\n"
print "#{three.remainingDataAsOf}\n"
puts "-----------"