Class: GoCard
- Inherits:
-
Object
- Object
- GoCard
- Defined in:
- lib/go_card.rb
Instance Method Summary collapse
- #get_balance ⇒ Object
- #get_history(period) ⇒ Object
-
#initialize ⇒ GoCard
constructor
A new instance of GoCard.
- #login(card_no, password) ⇒ Object
- #logoff ⇒ Object
Constructor Details
#initialize ⇒ GoCard
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_balance ⇒ Object
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. 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 login(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. # Submit the login form end end |
#logoff ⇒ Object
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 |