banks_api-shinsei 0.1.2
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/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +10 -0
- data/banks_api-shinsei.gemspec +30 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/banks_api/shinsei.rb +11 -0
- data/lib/banks_api/shinsei/bank_account.rb +22 -0
- data/lib/banks_api/shinsei/credential_set.rb +25 -0
- data/lib/banks_api/shinsei/faraday_middleware.rb +27 -0
- data/lib/banks_api/shinsei/js_parser.rb +73 -0
- data/lib/banks_api/shinsei/session.rb +149 -0
- data/lib/banks_api/shinsei/transaction.rb +22 -0
- data/lib/banks_api/shinsei/user_account.rb +53 -0
- data/lib/banks_api/shinsei/version.rb +5 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c0fe55edb230ff601e804d626ff9201f7f9af1508b71c993d7724786714305a5
|
4
|
+
data.tar.gz: 1004228f73c9edc6890960eb2dbd21664eeb72c8592f30f9150a1bf818ba6764
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f1eb7a3b3a955f47829d316a4604ad3cdda798963dd9891ed7d75c73876a73ad158cf34ebdef275275d802c66cf1ad8a5ec1fca4547cb3e77e4e429644c57473
|
7
|
+
data.tar.gz: b2c7c7ee180f1cf124e3a32b0b60e0cf99bd9cc990354d7dad160024300e95c1f2903ebd09ecc192562b895569bc9b8e264a5371b8e354efc34d0e100d75afb5
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
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 david.stosik+git-noreply@gmail.com. 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) 2018 David Stosik
|
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,45 @@
|
|
1
|
+
# BanksApi::Shinsei
|
2
|
+
|
3
|
+
[BanksAPI](/davidstosik/banks_api) implementation for [Shinsei Bank](http://shinseibank.com) accounts.
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/banks_api/shinsei`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
TODO: Delete this and the text above, and describe your gem
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'banks_api-shinsei'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install banks_api-shinsei
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
TODO: Write usage instructions here
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
|
+
|
33
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/banks_api-shinsei. 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.
|
38
|
+
|
39
|
+
## License
|
40
|
+
|
41
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
42
|
+
|
43
|
+
## Code of Conduct
|
44
|
+
|
45
|
+
Everyone interacting in the BanksApi::Shinsei project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/banks_api-shinsei/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "banks_api/shinsei/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "banks_api-shinsei"
|
7
|
+
spec.version = BanksApi::Shinsei::VERSION
|
8
|
+
spec.authors = ["David Stosik"]
|
9
|
+
spec.email = ["david.stosik+git-noreply@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{BanksAPI implementation for Shinsei Bank accounts}
|
12
|
+
spec.description = %q{Fetch Shinsei Bank transactions via a standardized API}
|
13
|
+
spec.homepage = "https://github.com/davidstosik/banks_api-shinsei"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency "banks_api", "~> 0.1"
|
26
|
+
spec.add_dependency "faraday", "~> 0.15"
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
30
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "banks_api/shinsei"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "banks_api/shinsei/version"
|
2
|
+
require "banks_api"
|
3
|
+
require "banks_api/shinsei/credential_set"
|
4
|
+
require "banks_api/shinsei/session"
|
5
|
+
|
6
|
+
module BanksApi
|
7
|
+
module Shinsei
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
BanksApi::Bank.register_bank(:shinsei, BanksApi::Shinsei::Session)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BanksApi
|
2
|
+
module Shinsei
|
3
|
+
class BankAccount < BankAccount
|
4
|
+
attr_reader :type, :base_balance
|
5
|
+
|
6
|
+
def initialize(type:, base_balance:, session:, **other)
|
7
|
+
super(other)
|
8
|
+
@type = type
|
9
|
+
@base_balance = Money.from_amount(base_balance, currency)
|
10
|
+
@session = session
|
11
|
+
end
|
12
|
+
|
13
|
+
def transactions(from:, to:)
|
14
|
+
session.fetch_transactions(account: self, from: from, to: to)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
attr_reader :session
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module BanksApi
|
2
|
+
module Shinsei
|
3
|
+
class CredentialSet
|
4
|
+
attr_reader :account, :password, :pin
|
5
|
+
|
6
|
+
def initialize(account:, password:, pin:, code_card:)
|
7
|
+
@account = account
|
8
|
+
@password = password
|
9
|
+
@pin = pin
|
10
|
+
@code_card = code_card.split(",")
|
11
|
+
end
|
12
|
+
|
13
|
+
def get_grid_value(coordinates)
|
14
|
+
x = coordinates[0].tr("A-J", "0-9").to_i
|
15
|
+
y = coordinates[1].to_i
|
16
|
+
|
17
|
+
code_card[y][x]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :code_card
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "banks_api/shinsei/js_parser"
|
2
|
+
|
3
|
+
module BanksApi
|
4
|
+
module Shinsei
|
5
|
+
class FaradayMiddleware < Faraday::Middleware
|
6
|
+
def call(request_env)
|
7
|
+
request_env.body.force_encoding(Encoding::ASCII_8BIT)
|
8
|
+
request_env.request_headers["User-Agent"] = USER_AGENT
|
9
|
+
|
10
|
+
@app.call(request_env).on_complete do |response_env|
|
11
|
+
# #toutf8 converts half-width Katakana to full-width (???)
|
12
|
+
# As recommended in the official Ruby documentation (see link below),
|
13
|
+
# we'll use this instead.
|
14
|
+
# https://docs.ruby-lang.org/ja/2.4.0/method/Kconv/m/toutf8.html
|
15
|
+
response_env.body = NKF.nkf("-wxm0", response_env.body)
|
16
|
+
|
17
|
+
if response_env.response_headers["content-type"]&.match?(/text\/html/)
|
18
|
+
response_env.body = JsParser.data_for(response_env.body)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
USER_AGENT = "Mozilla/5.0 (Windows; U; Windows NT 5.1;) PowerDirectBot/0.1".freeze
|
24
|
+
private_constant :USER_AGENT
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module BanksApi
|
2
|
+
module Shinsei
|
3
|
+
class JsParser
|
4
|
+
def self.data_for(html_body)
|
5
|
+
new(html_body).data
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(html_body)
|
9
|
+
@html_body = html_body
|
10
|
+
end
|
11
|
+
|
12
|
+
def data
|
13
|
+
@_data ||= setup_code.
|
14
|
+
to_enum(:scan, var_assign_regex).
|
15
|
+
inject({}) do |variables|
|
16
|
+
|
17
|
+
name, index, value = Regexp.last_match.captures
|
18
|
+
|
19
|
+
value = parse_value(value)
|
20
|
+
|
21
|
+
if index
|
22
|
+
variables[name] ||= []
|
23
|
+
variables[name][index.to_i] = value
|
24
|
+
else
|
25
|
+
variables[name] = value
|
26
|
+
end
|
27
|
+
|
28
|
+
variables
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
attr_reader :html_body
|
35
|
+
|
36
|
+
def setup_code
|
37
|
+
@_setup_code ||= html_body.lines.first.
|
38
|
+
match(snippet_regex).
|
39
|
+
to_a.fetch(0, "")
|
40
|
+
end
|
41
|
+
|
42
|
+
def snippet_regex
|
43
|
+
/(?<=<script language="JavaScript">).*(?=<\/script>)/
|
44
|
+
end
|
45
|
+
|
46
|
+
def var_assign_regex
|
47
|
+
/(\w+)(?:\[(\d+)\])?=(.*?)(?=;)/
|
48
|
+
end
|
49
|
+
|
50
|
+
def parse_value(value)
|
51
|
+
if value == "new Array()"
|
52
|
+
[]
|
53
|
+
else
|
54
|
+
match_numeric(match_string(value))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def match_string(value)
|
59
|
+
value.match(/^('|"|)(.*)\1$/)[2]
|
60
|
+
end
|
61
|
+
|
62
|
+
def match_numeric(value)
|
63
|
+
match = value.match /^\d{1,3}(,\d{3})*(\.\d*)?$/
|
64
|
+
return value unless match
|
65
|
+
if match[2]
|
66
|
+
value.tr(",", "").to_f
|
67
|
+
else
|
68
|
+
value.tr(",", "").to_i
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require "csv"
|
2
|
+
require "faraday"
|
3
|
+
require "kconv"
|
4
|
+
require "banks_api/shinsei/js_parser"
|
5
|
+
require "banks_api/shinsei/bank_account"
|
6
|
+
require "banks_api/shinsei/transaction"
|
7
|
+
require "banks_api/shinsei/faraday_middleware"
|
8
|
+
|
9
|
+
module BanksApi
|
10
|
+
module Shinsei
|
11
|
+
class Session
|
12
|
+
def initialize(credentials)
|
13
|
+
@credentials = CredentialSet.new(credentials)
|
14
|
+
end
|
15
|
+
|
16
|
+
def fetch_accounts
|
17
|
+
login
|
18
|
+
data = connection.post(nil, accounts_data).body
|
19
|
+
|
20
|
+
data["fldAccountID"].map.with_index do |account_id, index|
|
21
|
+
BankAccount.new(
|
22
|
+
id: account_id,
|
23
|
+
type: data["fldAccountType"][index],
|
24
|
+
description: data["fldAccountDesc"][index],
|
25
|
+
currency: data["fldCurrCcy"][index],
|
26
|
+
balance: data["fldCurrBalance"][index],
|
27
|
+
base_balance: data["fldBaseBalance"][index],
|
28
|
+
session: self
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
# logout
|
33
|
+
end
|
34
|
+
|
35
|
+
def fetch_transactions(account:, from:, to:)
|
36
|
+
login
|
37
|
+
fetch_accounts
|
38
|
+
post_data = transactions_data(account: account, from: from, to: to, step: 1)
|
39
|
+
connection.post(nil, post_data)
|
40
|
+
post_data = transactions_data(account: account, from: from, to: to, step: 2)
|
41
|
+
csv = connection.post(nil, post_data).body.lines[9..-1].join
|
42
|
+
headers = [:date, :ref_no, :description, :debit, :credit, :balance]
|
43
|
+
CSV.parse(csv, col_sep: "\t", headers: headers).map do |csv_line|
|
44
|
+
Transaction.from_csv_line(csv_line, currency: account.currency)
|
45
|
+
end.reverse
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
attr_reader :credentials, :session_id
|
51
|
+
|
52
|
+
URL = "https://pdirect04.shinseibank.com/FLEXCUBEAt/LiveConnect.dll".freeze
|
53
|
+
private_constant :URL
|
54
|
+
|
55
|
+
def login
|
56
|
+
data = connection.post(nil, login_phase1_data).body
|
57
|
+
@session_id = data["fldSessionID"]
|
58
|
+
connection.post(nil, login_phase2_data(data))
|
59
|
+
end
|
60
|
+
|
61
|
+
def logout
|
62
|
+
end
|
63
|
+
|
64
|
+
def connection
|
65
|
+
@_connection ||= initialize_connection
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize_connection
|
69
|
+
Faraday.new(url: URL) do |faraday|
|
70
|
+
faraday.request(:url_encoded)
|
71
|
+
faraday.use(FaradayMiddleware)
|
72
|
+
faraday.adapter(Faraday.default_adapter)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def login_phase1_data
|
77
|
+
{
|
78
|
+
"MfcISAPICommand" => "EntryFunc",
|
79
|
+
"fldAppID" => "RT",
|
80
|
+
"fldTxnID" => "LGN",
|
81
|
+
"fldScrSeqNo" => "01",
|
82
|
+
"fldRequestorID" => "41",
|
83
|
+
"fldDeviceID" => "01",
|
84
|
+
"fldUserID" => credentials.account,
|
85
|
+
"fldUserNumId" => credentials.pin,
|
86
|
+
"fldUserPass" => credentials.password,
|
87
|
+
"fldLangID" => "ENG", # or JPN
|
88
|
+
"fldRegAuthFlag" => "A"
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def login_phase2_data(data)
|
93
|
+
{
|
94
|
+
"MfcISAPICommand" => "EntryFunc",
|
95
|
+
"fldAppID" => "RT",
|
96
|
+
"fldTxnID" => "LGN",
|
97
|
+
"fldScrSeqNo" => "41",
|
98
|
+
"fldRequestorID" => "55",
|
99
|
+
"fldSessionID" => session_id,
|
100
|
+
"fldDeviceID" => "01",
|
101
|
+
"fldGridChallange1" => credentials.get_grid_value(data["fldGridChallange1"]),
|
102
|
+
"fldGridChallange2" => credentials.get_grid_value(data["fldGridChallange2"]),
|
103
|
+
"fldGridChallange3" => credentials.get_grid_value(data["fldGridChallange3"]),
|
104
|
+
"fldUserID" => "",
|
105
|
+
"fldUserNumId" => "",
|
106
|
+
"fldNumSeq" => "1",
|
107
|
+
"fldLangID" => "ENG",
|
108
|
+
"fldRegAuthFlag" => data["fldRegAuthFlag"]
|
109
|
+
}
|
110
|
+
end
|
111
|
+
|
112
|
+
def accounts_data
|
113
|
+
{
|
114
|
+
"MfcISAPICommand" => "EntryFunc",
|
115
|
+
"fldAppID" => "RT",
|
116
|
+
"fldTxnID" => "ACS",
|
117
|
+
"fldScrSeqNo" => "00",
|
118
|
+
"fldRequestorID" => "23",
|
119
|
+
"fldSessionID" => session_id,
|
120
|
+
"fldAcctID" => "",
|
121
|
+
"fldAcctType" => "CHECKING",
|
122
|
+
"fldIncludeBal" => "Y",
|
123
|
+
"fldPeriod" => "",
|
124
|
+
"fldCurDef" => "JPY"
|
125
|
+
}
|
126
|
+
end
|
127
|
+
|
128
|
+
def transactions_data(account:, from:, to:, step:)
|
129
|
+
{
|
130
|
+
"MfcISAPICommand" => "EntryFunc",
|
131
|
+
"fldScrSeqNo" => "01",
|
132
|
+
"fldAppID" => "RT",
|
133
|
+
'fldSessionID'=> session_id,
|
134
|
+
"fldTxnID" => %w(ACA DAA)[step-1],
|
135
|
+
"fldRequestorID" => "9",
|
136
|
+
"fldAcctID" => account.id,
|
137
|
+
"fldAcctType" => account.type,
|
138
|
+
"fldIncludeBal" => "N",
|
139
|
+
"fldStartDate" => from.strftime("%Y%m%d"),
|
140
|
+
"fldEndDate" => to.strftime("%Y%m%d"),
|
141
|
+
"fldStartNum" => "0",
|
142
|
+
"fldEndNum" => "0",
|
143
|
+
"fldCurDef" => "JPY",
|
144
|
+
"fldPeriod" => (from ? "2" : "1")
|
145
|
+
}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BanksApi
|
2
|
+
module Shinsei
|
3
|
+
class Transaction < Transaction
|
4
|
+
attr_reader :ref_no
|
5
|
+
|
6
|
+
def initialize(ref_no:, **other)
|
7
|
+
super(other)
|
8
|
+
@ref_no = ref_no
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.from_csv_line(csv_line, currency:)
|
12
|
+
new(
|
13
|
+
date: Date.parse(csv_line[:date]),
|
14
|
+
ref_no: csv_line[:ref_no],
|
15
|
+
description: csv_line[:description],
|
16
|
+
amount: csv_line[:credit].to_i - csv_line[:debit].to_i, # can both be non zero?
|
17
|
+
currency: currency
|
18
|
+
)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module BanksApi
|
2
|
+
class BankNameResolver
|
3
|
+
def initialize(bank_name)
|
4
|
+
@bank_name = bank_name
|
5
|
+
end
|
6
|
+
|
7
|
+
def domain
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module BanksApi
|
13
|
+
module UserAccount
|
14
|
+
def initialize(bank:, credentials:)
|
15
|
+
@bank = bank
|
16
|
+
@credentials = credentials
|
17
|
+
end
|
18
|
+
|
19
|
+
def accounts
|
20
|
+
@accounts ||= api.fetch_accounts
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :bank, :credentials
|
26
|
+
|
27
|
+
def api
|
28
|
+
bank_domain::Session
|
29
|
+
end
|
30
|
+
|
31
|
+
def bank_domain
|
32
|
+
BankNameResolver.new(bank).domain
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module BanksApi
|
38
|
+
module Shinsei
|
39
|
+
class UserAccount < UserAccount
|
40
|
+
def initialize(bank:, credentials:)
|
41
|
+
super
|
42
|
+
@session = Session.new(credentials)
|
43
|
+
end
|
44
|
+
|
45
|
+
def accounts
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
attr_reader :session
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: banks_api-shinsei
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Stosik
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: banks_api
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.15'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
description: Fetch Shinsei Bank transactions via a standardized API
|
84
|
+
email:
|
85
|
+
- david.stosik+git-noreply@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- CODE_OF_CONDUCT.md
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- banks_api-shinsei.gemspec
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- lib/banks_api/shinsei.rb
|
101
|
+
- lib/banks_api/shinsei/bank_account.rb
|
102
|
+
- lib/banks_api/shinsei/credential_set.rb
|
103
|
+
- lib/banks_api/shinsei/faraday_middleware.rb
|
104
|
+
- lib/banks_api/shinsei/js_parser.rb
|
105
|
+
- lib/banks_api/shinsei/session.rb
|
106
|
+
- lib/banks_api/shinsei/transaction.rb
|
107
|
+
- lib/banks_api/shinsei/user_account.rb
|
108
|
+
- lib/banks_api/shinsei/version.rb
|
109
|
+
homepage: https://github.com/davidstosik/banks_api-shinsei
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.7.6
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: BanksAPI implementation for Shinsei Bank accounts
|
133
|
+
test_files: []
|