Class: GoCard

Inherits:
Object
  • Object
show all
Defined in:
lib/go_card.rb

Instance Method Summary collapse

Constructor Details

#initializeGoCard

Returns a new instance of GoCard.



6
7
8
# File 'lib/go_card.rb', line 6

def initialize()
  @mech = Mechanize.new
end

Instance Method Details

#get_balanceObject



25
26
27
28
29
30
# File 'lib/go_card.rb', line 25

def get_balance()
  raise "Did you forget to login?" unless @mech
  page = @mech.get("https://www.seqits.com.au/webtix/cardinfo/summary.do")
  page.parser.xpath("//*[@class=\"results_table\"]").first.content =~ /(\$[0-9]*\.[0-9]*)/
  return $1
end

#get_history(period) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/go_card.rb', line 32

def get_history(period)
  start_date = Time.now - (3600 * 24 * period)
  history_page = @mech.get("https://www.seqits.com.au/webtix/cardinfo/history.do")
  result_page = history_page.form_with(:action => '/webtix/cardinfo/history.do') do |form|
    form['startDate'] = start_date.strftime("%d-%b-%Y")
    form['endDate']   = Time.now.strftime("%d-%b-%Y")
  end.click_button

  table = result_page.parser.xpath("//*[@class='results_table']//tr")
  table.shift # Get rid of the headers
  table.map { |tr|
    results = tr.xpath('./td').map { |c| c.content.strip.chomp }
    { :time => Time.parse(results[0]), :action => results[1], :location => results[2], :charge => results[3] }
  }
end

#login(card_no, password) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/go_card.rb', line 10

def (card_no, password)
  @mech.get('https://www.seqits.com.au/webtix/welcome/welcome.do/') do |page|
    page.form_with(:action => '/webtix/welcome/welcome.do') do |f|
      f['cardOps'] = 'Display' 
      f['cardNum'] = card_no
      f['pass']    = password
    end.click_button # Submit the login form
  end
end

#logoffObject



20
21
22
23
# File 'lib/go_card.rb', line 20

def logoff()
  @mech.get("https://www.seqits.com.au/webtix/welcome/welcome.do?logout=true")
  @mech = nil
end