go_card 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/go_card.rb +47 -0
- metadata +80 -0
data/lib/go_card.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'mechanize'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
class GoCard
|
6
|
+
def initialize()
|
7
|
+
@mech = Mechanize.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def login(card_no, password)
|
11
|
+
@mech.get('https://www.seqits.com.au/webtix/welcome/welcome.do/') do |page|
|
12
|
+
page.form_with(:action => '/webtix/welcome/welcome.do') do |f|
|
13
|
+
f['cardOps'] = 'Display'
|
14
|
+
f['cardNum'] = card_no
|
15
|
+
f['pass'] = password
|
16
|
+
end.click_button # Submit the login form
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def logoff()
|
21
|
+
@mech.get("https://www.seqits.com.au/webtix/welcome/welcome.do?logout=true")
|
22
|
+
@mech = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_balance()
|
26
|
+
raise "Did you forget to login?" unless @mech
|
27
|
+
page = @mech.get("https://www.seqits.com.au/webtix/cardinfo/summary.do")
|
28
|
+
page.parser.xpath("//*[@class=\"results_table\"]").first.content =~ /(\$[0-9]*\.[0-9]*)/
|
29
|
+
return $1
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_history(period)
|
33
|
+
start_date = Time.now - (3600 * 24 * period)
|
34
|
+
history_page = @mech.get("https://www.seqits.com.au/webtix/cardinfo/history.do")
|
35
|
+
result_page = history_page.form_with(:action => '/webtix/cardinfo/history.do') do |form|
|
36
|
+
form['startDate'] = start_date.strftime("%d-%b-%Y")
|
37
|
+
form['endDate'] = Time.now.strftime("%d-%b-%Y")
|
38
|
+
end.click_button
|
39
|
+
|
40
|
+
table = result_page.parser.xpath("//*[@class='results_table']//tr")
|
41
|
+
table.shift # Get rid of the headers
|
42
|
+
table.map { |tr|
|
43
|
+
results = tr.xpath('./td').map { |c| c.content.strip.chomp }
|
44
|
+
{ :time => Time.parse(results[0]), :action => results[1], :location => results[2], :charge => results[3] }
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: go_card
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jamie Cook
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-10-23 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: mechanize
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 15
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 0
|
32
|
+
- 0
|
33
|
+
version: 2.0.0
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: A simple ruby API for the Brisbane Translink Go Card
|
37
|
+
email: jamie@ieee.org
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- lib/go_card.rb
|
46
|
+
homepage: https://github.com/jamiecook/gocard-ruby-api
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
requirements: []
|
73
|
+
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.11
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: A simple ruby API for the Brisbane Translink Go Card
|
79
|
+
test_files: []
|
80
|
+
|