opal_card_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +45 -0
- data/.travis.yml +14 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +129 -0
- data/Rakefile +14 -0
- data/dockerfiles/Dockerfile.development +24 -0
- data/lib/opal_card_api.rb +160 -0
- data/lib/opal_card_api/version.rb +3 -0
- data/opal_card_api.gemspec +42 -0
- metadata +215 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aa285a08922c3150c998fa8d7a986d101d92404be73f7e466a96df386da2f139
|
4
|
+
data.tar.gz: fd4e2cae1040ba454da2e3cd7d8c653ea79323dfcdfc5012cc3a4c2bb1293756
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 76b3aec6a4d3c6d930d677ad0fcb111bb6a8fa25dd0962eafad79fed55b68b25d17eb33b540969e9802c1e49feeecf7fa984739421d507476ecc2580b5aabdcc
|
7
|
+
data.tar.gz: 071daceec9a1e60e73f96d7e66759c9800e0d0a07db7c752080d789a504d2031c0ee50c962da4522d619651ac56ce399e3f7d198ca63ba879659e8e4e76b96d9
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
Layout/AlignHash:
|
2
|
+
EnforcedHashRocketStyle: table
|
3
|
+
EnforcedColonStyle: table
|
4
|
+
Layout/ClosingParenthesisIndentation:
|
5
|
+
Enabled: false
|
6
|
+
Layout/EmptyLinesAroundBlockBody:
|
7
|
+
Enabled: false
|
8
|
+
Layout/EmptyLinesAroundClassBody:
|
9
|
+
Enabled: false
|
10
|
+
Layout/EmptyLinesAroundMethodBody:
|
11
|
+
Enabled: false
|
12
|
+
Layout/EmptyLinesAroundModuleBody:
|
13
|
+
Enabled: false
|
14
|
+
Layout/EndAlignment:
|
15
|
+
EnforcedStyleAlignWith: start_of_line
|
16
|
+
Layout/IndentationWidth:
|
17
|
+
Width: 1
|
18
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
19
|
+
EnforcedStyle: no_space
|
20
|
+
Layout/SpaceAroundOperators:
|
21
|
+
Enabled: false
|
22
|
+
Layout/Tab:
|
23
|
+
Enabled: false
|
24
|
+
Metrics/AbcSize:
|
25
|
+
Enabled: false
|
26
|
+
Metrics/BlockLength:
|
27
|
+
Max: 64
|
28
|
+
Metrics/ClassLength:
|
29
|
+
Max: 256
|
30
|
+
Metrics/LineLength:
|
31
|
+
Max: 200
|
32
|
+
Metrics/MethodLength:
|
33
|
+
Max: 128
|
34
|
+
Style/AndOr:
|
35
|
+
Enabled: false
|
36
|
+
Style/Documentation:
|
37
|
+
Enabled: false
|
38
|
+
Style/FrozenStringLiteralComment:
|
39
|
+
Enabled: false
|
40
|
+
|
41
|
+
AllCops:
|
42
|
+
TargetRubyVersion: 2.3
|
43
|
+
|
44
|
+
|
45
|
+
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## 0.1.0 - 2019-06-14
|
8
|
+
### Added
|
9
|
+
- Initial release
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at TODO: Write your email address. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
# OpalCardApi
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/cyclotron3k/opal_card_api.svg?branch=master)](https://travis-ci.org/cyclotron3k/opal_card_api)
|
4
|
+
|
5
|
+
Do you live in Sydney? Do you have an Opal card and want to scrape your data? Then this is the gem for you.
|
6
|
+
|
7
|
+
It caches aggressively to minimize the number of "api calls".
|
8
|
+
|
9
|
+
This is a screen-scraping gem, so it is liable to stop working at any moment.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'opal_card_api'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install opal_card_api
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Create a new instance using named parameters:
|
30
|
+
```ruby
|
31
|
+
client = OpalCardApi.new username: 'GladysBerejiklian', password: 'TR41NL0V3R'
|
32
|
+
```
|
33
|
+
|
34
|
+
Or if you like, you can use environment variables: `OPAL_USERNAME` & `OPAL_PASSWORD`
|
35
|
+
```ruby
|
36
|
+
client = OpalCardApi.new
|
37
|
+
```
|
38
|
+
|
39
|
+
Now that you have a client, you can retrieve your cards:
|
40
|
+
```ruby
|
41
|
+
cards = client.cards
|
42
|
+
# => [{"cardNumber"=>"3083857629546364",
|
43
|
+
# "displayCardNumber"=>nil,
|
44
|
+
# "fareCategoryCode"=>nil,
|
45
|
+
# "fareCategoryTitle"=>nil,
|
46
|
+
# "cardNickName"=>"Lobster",
|
47
|
+
# "cardState"=>"ISSUED",
|
48
|
+
# "cardBalance"=>2307,
|
49
|
+
# "active"=>true,
|
50
|
+
# "svPending"=>0,
|
51
|
+
# "toBeActivated"=>false,
|
52
|
+
# "displayName"=>"Lobster",
|
53
|
+
# "cardBalanceInDollars"=>"$23.07",
|
54
|
+
# "currentCardBalanceInDollars"=>"$23.07",
|
55
|
+
# "svPendingInDollars"=>nil}]
|
56
|
+
```
|
57
|
+
|
58
|
+
Typically you'll only have one card, and by calling `transactions` you can get all of the transactions associated with that card:
|
59
|
+
```ruby
|
60
|
+
transactions = client.transactions
|
61
|
+
```
|
62
|
+
|
63
|
+
Now, because we're screen-scraping behind the scenes, and because we probably only want the most recent transactions, `transactions` returns an `Enumerator` that only requests as many pages of transactions as required. Care must be taken to avoid downloading your entire transaction history (unless that is what you want to do).
|
64
|
+
```ruby
|
65
|
+
# GOOD
|
66
|
+
two_most_recent = transactions.take 2
|
67
|
+
# => [{:id=>1301,
|
68
|
+
# :timestamp=>2019-06-13 18:36:00 +1000,
|
69
|
+
# :mode=>"train",
|
70
|
+
# :description=>"Central to Strathfield",
|
71
|
+
# :journey_number=>7,
|
72
|
+
# :fare_applied=>"Off-peak",
|
73
|
+
# :fare=>"$4.40",
|
74
|
+
# :discount=>"$1.32",
|
75
|
+
# :amount=>"-$3.08"},
|
76
|
+
# {:id=>1299,
|
77
|
+
# :timestamp=>2019-06-13 08:53:00 +1000,
|
78
|
+
# :mode=>"train",
|
79
|
+
# :description=>"Strathfield to Central",
|
80
|
+
# :journey_number=>6,
|
81
|
+
# :fare_applied=>"",
|
82
|
+
# :fare=>"$4.40",
|
83
|
+
# :discount=>"$0.00",
|
84
|
+
# :amount=>"-$4.40"}]
|
85
|
+
|
86
|
+
# GOOD - watch out for time zones though
|
87
|
+
transactions.take_while { |t| t[:timestamp] > Time.new(2019, 6, 11, 12, 0, 0) }
|
88
|
+
|
89
|
+
# BAD - using select like this forces every transaction to be downloaded
|
90
|
+
transactions.select { |t| t[:id] >= 1100 }
|
91
|
+
|
92
|
+
# GOOD - we can rely on the reverse chronological order of the results
|
93
|
+
transactions.take_while { |t| t[:id] >= 1100 }
|
94
|
+
|
95
|
+
# PRETTY AWESOME - using Enumerable#lazy to postpone filtering
|
96
|
+
transactions.lazy.select { |t| t[:mode] == 'train' }.first 5
|
97
|
+
|
98
|
+
# Just get all transactions:
|
99
|
+
transactions.to_a
|
100
|
+
```
|
101
|
+
|
102
|
+
If you have more than one card you'll probably want to specify which card to retrieve transactions for. The default behaviour (as illustrated above) is to show transactions for the first card in the card array returned by `OpalCardApi#cards`.
|
103
|
+
|
104
|
+
To retrieve transactions for other cards, you must specify which one
|
105
|
+
```ruby
|
106
|
+
# By specifying the ID of the card:
|
107
|
+
client.transactions('3083857629546364')
|
108
|
+
|
109
|
+
# By specifying then name of the card:
|
110
|
+
client.transactions('Lobster')
|
111
|
+
|
112
|
+
# By specifying the index of the card:
|
113
|
+
client.transactions(3) # your fourth card
|
114
|
+
|
115
|
+
# By using one of the hashes returned by client.cards:
|
116
|
+
client.transactions(client.cards.last)
|
117
|
+
```
|
118
|
+
|
119
|
+
## Contributing
|
120
|
+
|
121
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cyclotron3k/opal_card_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
122
|
+
|
123
|
+
## License
|
124
|
+
|
125
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
126
|
+
|
127
|
+
## Code of Conduct
|
128
|
+
|
129
|
+
Everyone interacting in the OpalCardApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/cyclotron3k/opal_card_api/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << 'test'
|
6
|
+
t.libs << 'lib'
|
7
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
end
|
9
|
+
|
10
|
+
task default: :test
|
11
|
+
|
12
|
+
task :console do
|
13
|
+
exec 'pry -I ./lib -r opal_card_api'
|
14
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
FROM ruby:2.6
|
2
|
+
LABEL description="A useful container for development and testing"
|
3
|
+
LABEL build="docker build -f ./dockerfiles/Dockerfile.development . -t opal-card-api:latest"
|
4
|
+
LABEL usage="docker run -it --rm -v $PWD:/srv opal-card-api:latest"
|
5
|
+
|
6
|
+
VOLUME /srv
|
7
|
+
|
8
|
+
ENV CLANG UTF8
|
9
|
+
ENV TZ Australia/Sydney
|
10
|
+
ENV EDITOR vim
|
11
|
+
|
12
|
+
RUN apt-get -q update && \
|
13
|
+
apt-get -yq install dialog vim tree less && \
|
14
|
+
apt-get -yq --purge autoremove && \
|
15
|
+
apt-get -q clean
|
16
|
+
|
17
|
+
COPY Gemfile* *.gemspec /tmp/
|
18
|
+
COPY lib/opal_card_api/version.rb /tmp/lib/opal_card_api/version.rb
|
19
|
+
|
20
|
+
WORKDIR /tmp
|
21
|
+
RUN bundle install
|
22
|
+
|
23
|
+
WORKDIR /srv
|
24
|
+
CMD bundle exec rake console
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'tzinfo'
|
3
|
+
require 'caching_enumerator'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
require 'opal_card_api/version'
|
7
|
+
|
8
|
+
class OpalCardApi
|
9
|
+
|
10
|
+
DOMAIN = 'www.opal.com.au'.freeze
|
11
|
+
BASE_URI = URI "https://#{DOMAIN}/"
|
12
|
+
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
class JsonParser < Mechanize::Page
|
16
|
+
attr_reader :json
|
17
|
+
def initialize(uri=nil, response=nil, body=nil, code=nil)
|
18
|
+
@json = JSON.parse body
|
19
|
+
super uri, response, body, code
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(
|
24
|
+
username: ENV['OPAL_USERNAME'],
|
25
|
+
password: ENV['OPAL_PASSWORD']
|
26
|
+
)
|
27
|
+
|
28
|
+
raise ArgumentError, 'No username provided' unless username
|
29
|
+
raise ArgumentError, 'No password provided' unless password
|
30
|
+
|
31
|
+
@username = username
|
32
|
+
@password = password
|
33
|
+
@logged_in = false
|
34
|
+
@transactions = {}
|
35
|
+
end
|
36
|
+
|
37
|
+
def agent
|
38
|
+
@agent ||= Mechanize.new do |a|
|
39
|
+
a.user_agent = 'Opal Card API Client (cyclotron3k)'
|
40
|
+
a.pluggable_parser['application/json'] = JsonParser
|
41
|
+
a.max_history = 0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# rubocop:disable Style/RescueStandardError
|
46
|
+
def login
|
47
|
+
@logged_in = true
|
48
|
+
page = get ''
|
49
|
+
|
50
|
+
page = page.form_with(
|
51
|
+
method: 'POST',
|
52
|
+
action: %r{/registeredUserUsernameAndPasswordLogin\z}
|
53
|
+
) do |form|
|
54
|
+
form.h_username = @username
|
55
|
+
form.h_password = @password
|
56
|
+
end.submit
|
57
|
+
|
58
|
+
raise Error, page.json['errorMessage'].to_s unless page.json['validationFailure'] == false
|
59
|
+
rescue
|
60
|
+
@logged_in = false
|
61
|
+
raise
|
62
|
+
end
|
63
|
+
# rubocop:enable Style/RescueStandardError
|
64
|
+
|
65
|
+
def cards
|
66
|
+
@cards ||= get(
|
67
|
+
'/registered/getJsonCardDetailsArray',
|
68
|
+
'_' => DateTime.now.strftime('%Q')
|
69
|
+
).json
|
70
|
+
end
|
71
|
+
|
72
|
+
def transactions(card_identifier=0)
|
73
|
+
|
74
|
+
card_index = identify_card_index card_identifier
|
75
|
+
|
76
|
+
@transactions[card_index] ||= CachingEnumerator.new do |yielder|
|
77
|
+
tz = TZInfo::Timezone.get 'Australia/Sydney'
|
78
|
+
page_no = 1
|
79
|
+
running = true
|
80
|
+
|
81
|
+
while running
|
82
|
+
page = get(
|
83
|
+
'/registered/opal-card-transactions/opal-card-activities-list',
|
84
|
+
'AMonth' => -1,
|
85
|
+
'AYear' => -1,
|
86
|
+
'cardIndex' => card_index,
|
87
|
+
'pageIndex' => page_no,
|
88
|
+
'_' => DateTime.now.strftime('%Q')
|
89
|
+
)
|
90
|
+
|
91
|
+
page.css('tr').drop(1).each do |row|
|
92
|
+
cols = row.css 'td'
|
93
|
+
|
94
|
+
mode = if cols[2].at_css('img')
|
95
|
+
cols[2].at_css('img').attr 'alt'
|
96
|
+
else
|
97
|
+
''
|
98
|
+
end
|
99
|
+
|
100
|
+
timestamp = tz.local_time(
|
101
|
+
*cols[1].text.match(
|
102
|
+
%r{0*(\d+)/0*(\d+)/(\d{4})\s*0*(\d+):0*(\d+)}
|
103
|
+
).captures.map(
|
104
|
+
&:to_i
|
105
|
+
).values_at(2, 1, 0, 3, 4)
|
106
|
+
)
|
107
|
+
|
108
|
+
yielder.yield(
|
109
|
+
id: cols[0].text.to_i,
|
110
|
+
timestamp: timestamp,
|
111
|
+
mode: mode,
|
112
|
+
description: cols[3].text,
|
113
|
+
journey_number: cols[4].text.strip.to_i,
|
114
|
+
fare_applied: cols[5].text,
|
115
|
+
fare: cols[6].text,
|
116
|
+
discount: cols[7].text,
|
117
|
+
amount: cols[8].text
|
118
|
+
)
|
119
|
+
end
|
120
|
+
|
121
|
+
page_no += 1
|
122
|
+
running = false unless page.at_css('a[title="Next page"]')
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def identify_card_index(identifier)
|
133
|
+
case identifier
|
134
|
+
when Integer
|
135
|
+
if identifier < 1000
|
136
|
+
identifier
|
137
|
+
else
|
138
|
+
cards.index { |c| c[:cardNumber] == identifier.to_s }
|
139
|
+
end
|
140
|
+
when String
|
141
|
+
cards.index do |c|
|
142
|
+
%w[cardNumber cardNickName displayName].any? { |k| c[k] == identifier }
|
143
|
+
end
|
144
|
+
when Hash
|
145
|
+
cards.index { |c| c == identifier }
|
146
|
+
end or raise Error, 'Invalid card identifier'
|
147
|
+
end
|
148
|
+
|
149
|
+
def generate_url(path, params={})
|
150
|
+
pr = BASE_URI + path
|
151
|
+
pr.query = URI.encode_www_form(params) unless params.empty?
|
152
|
+
pr.to_s
|
153
|
+
end
|
154
|
+
|
155
|
+
def get(*args)
|
156
|
+
login unless @logged_in
|
157
|
+
agent.get generate_url(*args)
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# lib = File.expand_path('../lib', __FILE__)
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'opal_card_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'opal_card_api'
|
8
|
+
spec.version = OpalCardApi::VERSION
|
9
|
+
spec.authors = ['cyclotron3k']
|
10
|
+
spec.email = ['aidan.samuel@gmailcom']
|
11
|
+
|
12
|
+
spec.summary = 'A screen-scraper to retrieve your cards and transactions from the Opal Card website'
|
13
|
+
spec.homepage = 'https://github.com/cyclotron3k/opal_card_api'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.metadata = {
|
17
|
+
'bug_tracker_uri' => 'https://github.com/cyclotron3k/opal_card_api/issues',
|
18
|
+
'changelog_uri' => 'https://github.com/cyclotron3k/opal_card_api/blob/master/CHANGELOG.md',
|
19
|
+
'documentation_uri' => "https://github.com/cyclotron3k/opal_card_api/blob/v#{OpalCardApi::VERSION}/README.md",
|
20
|
+
'source_code_uri' => 'https://github.com/cyclotron3k/opal_card_api'
|
21
|
+
}
|
22
|
+
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
|
28
|
+
spec.add_runtime_dependency 'caching_enumerator', '~> 0.0'
|
29
|
+
spec.add_runtime_dependency 'mechanize', '~> 2.7'
|
30
|
+
spec.add_runtime_dependency 'tzinfo', '~> 2.0'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
33
|
+
spec.add_development_dependency 'bundler-audit', '~> 0.6'
|
34
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
35
|
+
spec.add_development_dependency 'pry', '~> 0.12'
|
36
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
37
|
+
spec.add_development_dependency 'rubocop', '~> 0.71'
|
38
|
+
spec.add_development_dependency 'vcr', '~> 4.0'
|
39
|
+
spec.add_development_dependency 'webmock', '~> 3.5'
|
40
|
+
|
41
|
+
spec.required_ruby_version = '~> 2.3'
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: opal_card_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- cyclotron3k
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: caching_enumerator
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mechanize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: tzinfo
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.17'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.17'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: bundler-audit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.6'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.6'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.12'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.12'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.71'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.71'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: vcr
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '4.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '4.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.5'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.5'
|
167
|
+
description:
|
168
|
+
email:
|
169
|
+
- aidan.samuel@gmailcom
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- ".gitignore"
|
175
|
+
- ".rubocop.yml"
|
176
|
+
- ".travis.yml"
|
177
|
+
- CHANGELOG.md
|
178
|
+
- CODE_OF_CONDUCT.md
|
179
|
+
- Gemfile
|
180
|
+
- LICENSE.txt
|
181
|
+
- README.md
|
182
|
+
- Rakefile
|
183
|
+
- dockerfiles/Dockerfile.development
|
184
|
+
- lib/opal_card_api.rb
|
185
|
+
- lib/opal_card_api/version.rb
|
186
|
+
- opal_card_api.gemspec
|
187
|
+
homepage: https://github.com/cyclotron3k/opal_card_api
|
188
|
+
licenses:
|
189
|
+
- MIT
|
190
|
+
metadata:
|
191
|
+
bug_tracker_uri: https://github.com/cyclotron3k/opal_card_api/issues
|
192
|
+
changelog_uri: https://github.com/cyclotron3k/opal_card_api/blob/master/CHANGELOG.md
|
193
|
+
documentation_uri: https://github.com/cyclotron3k/opal_card_api/blob/v0.1.0/README.md
|
194
|
+
source_code_uri: https://github.com/cyclotron3k/opal_card_api
|
195
|
+
post_install_message:
|
196
|
+
rdoc_options: []
|
197
|
+
require_paths:
|
198
|
+
- lib
|
199
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
200
|
+
requirements:
|
201
|
+
- - "~>"
|
202
|
+
- !ruby/object:Gem::Version
|
203
|
+
version: '2.3'
|
204
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
requirements: []
|
210
|
+
rubygems_version: 3.0.3
|
211
|
+
signing_key:
|
212
|
+
specification_version: 4
|
213
|
+
summary: A screen-scraper to retrieve your cards and transactions from the Opal Card
|
214
|
+
website
|
215
|
+
test_files: []
|