ofx_ruby 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/Guardfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/bin/console +16 -0
- data/bin/setup +7 -0
- data/lib/ofx/aggregate.rb +49 -0
- data/lib/ofx/document/bank_account.rb +37 -0
- data/lib/ofx/document/bank_message_set.rb +33 -0
- data/lib/ofx/document/financial_institution.rb +20 -0
- data/lib/ofx/document/include_transactions.rb +38 -0
- data/lib/ofx/document/signon_message_set.rb +30 -0
- data/lib/ofx/document/signon_request.rb +44 -0
- data/lib/ofx/document/statement_request.rb +19 -0
- data/lib/ofx/document/statement_transaction.rb +24 -0
- data/lib/ofx/document.rb +113 -0
- data/lib/ofx/errors.rb +101 -0
- data/lib/ofx/handler.rb +34 -0
- data/lib/ofx/http.rb +27 -0
- data/lib/ofx/parser.rb +27 -0
- data/lib/ofx/version.rb +3 -0
- data/lib/ofx.rb +19 -0
- data/ofx-ruby-0.0.11.gem +0 -0
- data/ofx_ruby.gemspec +30 -0
- metadata +198 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b3e805dbc28725d84ebcc43c30743e2976668443
|
4
|
+
data.tar.gz: 460f2de7bac240c3b80ea3fef77c47362589090e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9805716f606c85cf2409670758044b1445777f3e72ec11477062d2527316fc604078c7918fbb1666fadff9f5c883166e347645c2118e53d3b04776afcaff8429
|
7
|
+
data.tar.gz: b3b7bb253395c4589a150109b01b9b3cfdf79c59267c38cba0304c37d3fbdd39faa222186f361cd13107d2ceaa1e6fed717459bbfb8428b32725caa6e73d30d7
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 rob
|
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,41 @@
|
|
1
|
+
# OfxRuby
|
2
|
+
|
3
|
+
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/ofx_ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ofx_ruby'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ofx_ruby
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ofx_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dotenv"
|
5
|
+
require "ofx"
|
6
|
+
require "excon"
|
7
|
+
require "byebug"
|
8
|
+
require "pp"
|
9
|
+
|
10
|
+
@body = File.read('test/fixtures/fake_ofx_response.xml').gsub(/\s/,'')
|
11
|
+
@parser = OFX::Parser.new(@body)
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
Dotenv.load
|
15
|
+
|
16
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Aggregate
|
4
|
+
attr_reader :tag
|
5
|
+
protected :tag
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@tag = options[:name] || :ofx
|
9
|
+
end
|
10
|
+
|
11
|
+
def root
|
12
|
+
dump(@tag)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def dump(element, body = nil)
|
18
|
+
tag = element.upcase
|
19
|
+
"<#{tag}>#{body}</#{tag}>"
|
20
|
+
end
|
21
|
+
|
22
|
+
def elements
|
23
|
+
respond_to?(:order, true) ? sort_by_order : public_methods(false)
|
24
|
+
end
|
25
|
+
|
26
|
+
def ordered?
|
27
|
+
respond_to?(:order, true)
|
28
|
+
end
|
29
|
+
|
30
|
+
def sort_by_order
|
31
|
+
public_methods(false).sort_by { |element| order.index(element.to_s) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_element_group(tag)
|
35
|
+
if send(tag).respond_to?(:element_group, true)
|
36
|
+
send(tag).send(:element_group)
|
37
|
+
else
|
38
|
+
dump(tag, send(tag))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def element_group
|
43
|
+
body = elements.inject('') do |result, tag|
|
44
|
+
result.dup << build_element_group(tag)
|
45
|
+
end
|
46
|
+
dump(@tag, body)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Document
|
4
|
+
class BankAccount < StatementRequest
|
5
|
+
def initialize(options = {})
|
6
|
+
@routing = options[:routing] || (raise Errors::RoutingNumberMissing)
|
7
|
+
@account = options[:account] || (raise Errors::AccountNumberMissing)
|
8
|
+
@type = account_type(options[:type] || :checking)
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def bankid
|
13
|
+
@routing
|
14
|
+
end
|
15
|
+
|
16
|
+
def acctid
|
17
|
+
@account
|
18
|
+
end
|
19
|
+
|
20
|
+
def accttype
|
21
|
+
@type
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def account_type(type = :checking)
|
27
|
+
case type
|
28
|
+
when :savings then 'SAVINGS'
|
29
|
+
when :money_market then 'MONEYMRKT'
|
30
|
+
when :credit_line then 'CREDITLINE'
|
31
|
+
when :checking then 'CHECKING'
|
32
|
+
else raise Errors::AccountTypeNotAvailable.new(account_type: type)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Document
|
4
|
+
class BankMessageSet < Document
|
5
|
+
def initialize(options = {})
|
6
|
+
@routing = options[:routing]
|
7
|
+
@account = options[:account]
|
8
|
+
@start = options[:start]
|
9
|
+
@end = options[:end]
|
10
|
+
@id = options[:id]
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def statement_request
|
15
|
+
StatementTransaction.new(
|
16
|
+
name: :stmttrnrq,
|
17
|
+
routing: @routing,
|
18
|
+
account: @account,
|
19
|
+
start: @start,
|
20
|
+
end: @end,
|
21
|
+
id: trnuid
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def trnuid
|
28
|
+
@id
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Document
|
4
|
+
class FinancialInstitution < SignonRequest
|
5
|
+
@@tag = :fi
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def org
|
12
|
+
@fi_org
|
13
|
+
end
|
14
|
+
|
15
|
+
def fid
|
16
|
+
@fi_fid
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Document
|
4
|
+
class IncludeTransactions < StatementRequest
|
5
|
+
def initialize(options = {})
|
6
|
+
@tag = :inctran
|
7
|
+
@include = options[:include].nil? ? true : false
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def include
|
12
|
+
include? ? 'Y' : 'N'
|
13
|
+
end
|
14
|
+
|
15
|
+
def dtstart
|
16
|
+
date(@start || Date.today - 30)
|
17
|
+
end
|
18
|
+
|
19
|
+
def dtend
|
20
|
+
date(@end || Date.today)
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
|
25
|
+
def include?
|
26
|
+
@include
|
27
|
+
end
|
28
|
+
|
29
|
+
def date(date)
|
30
|
+
date.strftime('%Y%m%d%H%M%S')
|
31
|
+
end
|
32
|
+
|
33
|
+
def order
|
34
|
+
%w{ dtstart dtend include }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Document
|
4
|
+
class SignonMessageSet < Document
|
5
|
+
def initialize(options = {})
|
6
|
+
@user = options[:user]
|
7
|
+
@password = options[:password]
|
8
|
+
@time = options[:time]
|
9
|
+
@fi_org = options[:fi_org]
|
10
|
+
@fi_fid = options[:fi_fid]
|
11
|
+
@app_id = options[:app_id]
|
12
|
+
@app_ver = options[:app_ver]
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def sonrq
|
17
|
+
SignonRequest.new(
|
18
|
+
name: :sonrq,
|
19
|
+
user: @user,
|
20
|
+
password: @password,
|
21
|
+
time: @time,
|
22
|
+
fi_org: @fi_org,
|
23
|
+
fi_fid: @fi_fid,
|
24
|
+
app_id: @app_id,
|
25
|
+
app_ver: @app_ver
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Document
|
4
|
+
class SignonRequest < SignonMessageSet
|
5
|
+
def initialize(options = {})
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def appver
|
10
|
+
@app_ver
|
11
|
+
end
|
12
|
+
|
13
|
+
def appid
|
14
|
+
@app_id
|
15
|
+
end
|
16
|
+
|
17
|
+
def language
|
18
|
+
'ENG'
|
19
|
+
end
|
20
|
+
|
21
|
+
def fi
|
22
|
+
FinancialInstitution.new(name: :fi, fi_org: @fi_org, fi_fid: @fi_fid)
|
23
|
+
end
|
24
|
+
|
25
|
+
def userpass
|
26
|
+
@password
|
27
|
+
end
|
28
|
+
|
29
|
+
def userid
|
30
|
+
@user
|
31
|
+
end
|
32
|
+
|
33
|
+
def dtclient
|
34
|
+
@time
|
35
|
+
end
|
36
|
+
|
37
|
+
protected
|
38
|
+
|
39
|
+
def order
|
40
|
+
%w{ dtclient userid userpass language fi appid appver }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Document
|
4
|
+
class StatementRequest < StatementTransaction
|
5
|
+
def initialize(options = {})
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def bank_account
|
10
|
+
BankAccount.new(name: :bankacctfrom, routing: @routing,
|
11
|
+
account: @account)
|
12
|
+
end
|
13
|
+
|
14
|
+
def include_transactions
|
15
|
+
IncludeTransactions.new(name: :inctran, start: @start, end: @end)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Document
|
4
|
+
class StatementTransaction < BankMessageSet
|
5
|
+
def initialize(options = {})
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def trnuid
|
10
|
+
@id
|
11
|
+
end
|
12
|
+
|
13
|
+
def statement_request
|
14
|
+
StatementRequest.new(
|
15
|
+
name: :stmtrq,
|
16
|
+
routing: @routing,
|
17
|
+
account: @account,
|
18
|
+
start: @start,
|
19
|
+
end: @end
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/ofx/document.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OFX
|
4
|
+
class Document < Aggregate
|
5
|
+
attr_reader :uri
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
@user = options[:user] || ENV['OFX_USER']
|
9
|
+
@password = options[:password] || ENV['OFX_PASSWORD']
|
10
|
+
@uri = options[:uri] || ENV['OFX_URI']
|
11
|
+
@fi_org = options[:fi_org] || ENV['OFX_FI_ORG']
|
12
|
+
@fi_fid = options[:fi_fid] || ENV['OFX_FI_FID']
|
13
|
+
@routing = options[:routing] || ENV['OFX_ROUTING']
|
14
|
+
@account = options[:account] || ENV['OFX_ACCOUNT']
|
15
|
+
@app_id = options[:app_id] || ENV['OFX_APP_ID']
|
16
|
+
@app_ver = options[:app_ver] || ENV['OFX_APP_VER']
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def signon
|
21
|
+
SignonMessageSet.new(
|
22
|
+
name: :signonmsgsrqv1,
|
23
|
+
time: Time.now.strftime('%Y%m%d%H%M%S'),
|
24
|
+
user: user,
|
25
|
+
password: password,
|
26
|
+
fi_org: fi_org,
|
27
|
+
fi_fid: fi_fid,
|
28
|
+
app_id: app_id,
|
29
|
+
app_ver: app_ver
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def bank
|
34
|
+
BankMessageSet.new(
|
35
|
+
name: :bankmsgsrqv1,
|
36
|
+
routing: routing,
|
37
|
+
account: account,
|
38
|
+
id: trnuid
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
protected
|
43
|
+
|
44
|
+
def dtclient
|
45
|
+
Time.now.strftime('%Y%m%d%H%M%S')
|
46
|
+
end
|
47
|
+
|
48
|
+
def trnuid
|
49
|
+
Time.now.to_i.to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
def user
|
53
|
+
@user || (raise Errors::UserMissing)
|
54
|
+
end
|
55
|
+
|
56
|
+
def password
|
57
|
+
@password || (raise Errors::PasswordMissing)
|
58
|
+
end
|
59
|
+
|
60
|
+
def fi_org
|
61
|
+
@fi_org || (raise Errors::FiOrgMissing)
|
62
|
+
end
|
63
|
+
|
64
|
+
def fi_fid
|
65
|
+
@fi_fid || (raise Errors::FiFidMissing)
|
66
|
+
end
|
67
|
+
|
68
|
+
def routing
|
69
|
+
@routing || (raise Errors::RoutingMissing)
|
70
|
+
end
|
71
|
+
|
72
|
+
def account
|
73
|
+
@account || (raise Errors::AccountMissing)
|
74
|
+
end
|
75
|
+
|
76
|
+
def app_id
|
77
|
+
@app_id || (raise Errors::AppIdMissing)
|
78
|
+
end
|
79
|
+
|
80
|
+
def app_ver
|
81
|
+
@app_ver || (raise Errors::AppVerMissing)
|
82
|
+
end
|
83
|
+
|
84
|
+
def uri
|
85
|
+
@uri || (raise Errors::URIMissing)
|
86
|
+
end
|
87
|
+
|
88
|
+
def http
|
89
|
+
@http ||= HTTP.new(uri: @uri)
|
90
|
+
end
|
91
|
+
|
92
|
+
def ofx_header
|
93
|
+
{
|
94
|
+
ofxheader: 100,
|
95
|
+
data: 'OFXSGML',
|
96
|
+
version: 103,
|
97
|
+
security: 'NONE',
|
98
|
+
encoding: 'UNICODE',
|
99
|
+
charset: 1252,
|
100
|
+
compression: 'NONE',
|
101
|
+
oldfileuid: 'NONE',
|
102
|
+
newfileuid: 'NONE'
|
103
|
+
}.inject('') do |result, values|
|
104
|
+
result.dup << "#{values[0].upcase}:#{values[1]}\n"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def body
|
109
|
+
[ofx_header, element_group].join
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
data/lib/ofx/errors.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Errors < StandardError
|
4
|
+
def initialize(options = {})
|
5
|
+
@account_type = options[:accoint_type]
|
6
|
+
end
|
7
|
+
|
8
|
+
class UserMissing < Errors
|
9
|
+
def message
|
10
|
+
"You need to include 'user' in the options hash" \
|
11
|
+
"when you initialize your ofx document or " \
|
12
|
+
"set OFX_USER as an environment variable."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class PasswordMissing < Errors
|
17
|
+
def message
|
18
|
+
"You need to include 'password' in the options hash" \
|
19
|
+
"when you initialize your ofx document or " \
|
20
|
+
"set OFX_PASSWORD as an environment variable."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class FiOrgMissing < Errors
|
25
|
+
def message
|
26
|
+
"You need to include 'fi_org' in the options hash" \
|
27
|
+
"when you initialize your ofx document or " \
|
28
|
+
"set OFX_FI_ORG as an environment variable."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class FiFidMissing < Errors
|
33
|
+
def message
|
34
|
+
"You need to include 'fi_fid' in the options hash" \
|
35
|
+
"when you initialize your ofx document or " \
|
36
|
+
"set OFX_FI_FID as an environment variable."
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class RoutingMissing < Errors
|
41
|
+
def message
|
42
|
+
"You need to include 'routing' in the options hash" \
|
43
|
+
"when you initialize your ofx document or " \
|
44
|
+
"set OFX_ROUTING as an environment variable."
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class AccountMissing < Errors
|
49
|
+
def message
|
50
|
+
"You need to include 'account' in the options hash" \
|
51
|
+
"when you initialize your ofx document or " \
|
52
|
+
"set OFX_ACCOUNT as an environment variable."
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class AppIdMissing < Errors
|
57
|
+
def message
|
58
|
+
"You need to include 'app_id' in the options hash" \
|
59
|
+
"when you initialize your ofx document or " \
|
60
|
+
"set OFX_APP_ID as an environment variable."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
class AppVerMissing < Errors
|
65
|
+
def message
|
66
|
+
"You need to include 'app_ver' in the options hash" \
|
67
|
+
"when you initialize your ofx document or " \
|
68
|
+
"set OFX_APP_VER as an environment variable."
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class URIMissing < Errors
|
73
|
+
def message
|
74
|
+
'You must specify the uri of the ofx server you' \
|
75
|
+
'plan to connect to. in the options hash.'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class RoutingNumberMissing < Errors
|
80
|
+
def message
|
81
|
+
'You must specify the routing number for ' \
|
82
|
+
'your account in the options hash or ' \
|
83
|
+
'set OFX_URI as an environment.'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
class AccountNumberMissing < Errors
|
88
|
+
def message
|
89
|
+
'You must specify the account number in the options hash.'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class AccountTypeNotAvailable < Errors
|
94
|
+
def message
|
95
|
+
"The account type #{@account_type} is not available. " \
|
96
|
+
"Please choose :savings, :money_market, :credit_line or " \
|
97
|
+
"omit for :checking."
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
data/lib/ofx/handler.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Handler < Ox::Sax
|
4
|
+
TRANSACTION_ATTRS = [:TRNTYPE, :DTPOSTED, :TRNAMT, :FITID, :NAME]
|
5
|
+
ATTRS_MAP = { TRNTYPE: :as_s, DTPOSTED: :as_time,
|
6
|
+
TRNAMT: :as_f, FITID: :as_s, NAME: :as_s }
|
7
|
+
|
8
|
+
def initialize(parser)
|
9
|
+
@parser = parser
|
10
|
+
end
|
11
|
+
|
12
|
+
def start_element(name)
|
13
|
+
@transaction = {} if name == :STMTTRN
|
14
|
+
@current_node = name
|
15
|
+
end
|
16
|
+
|
17
|
+
def value(value)
|
18
|
+
return unless TRANSACTION_ATTRS.include?(@current_node)
|
19
|
+
@transaction[@current_node] = value.send(ATTRS_MAP[@current_node])
|
20
|
+
end
|
21
|
+
|
22
|
+
def end_element(name)
|
23
|
+
return unless name == :STMTTRN
|
24
|
+
@parser.output[:transactions] = [] if @parser.output[:transactions].nil?
|
25
|
+
@parser.output[:transactions].push(
|
26
|
+
type: @transaction[:TRNTYPE],
|
27
|
+
posted: @transaction[:DTPOSTED],
|
28
|
+
amount: @transaction[:TRNAMT],
|
29
|
+
fitid: @transaction[:FITID],
|
30
|
+
name: @transaction[:NAME]
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/ofx/http.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class HTTP
|
4
|
+
attr_reader :uri, :body
|
5
|
+
|
6
|
+
def initialize(options = {})
|
7
|
+
@uri = options[:uri] || ENV['OFX_URI']
|
8
|
+
end
|
9
|
+
|
10
|
+
def uri
|
11
|
+
@uri || (raise Errors::URIMissing)
|
12
|
+
end
|
13
|
+
|
14
|
+
def headers
|
15
|
+
{
|
16
|
+
'Content-Type': 'application/x-ofx',
|
17
|
+
'Accept': '*/*, application/x-ofx'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def raw_headers
|
22
|
+
headers.inject('') do |result, (key, value)|
|
23
|
+
result.dup << "#{key}: #{value}\n"
|
24
|
+
end.strip
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/ofx/parser.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module OFX
|
3
|
+
class Parser
|
4
|
+
attr_reader :body
|
5
|
+
attr_accessor :output
|
6
|
+
|
7
|
+
def initialize(body, options = {})
|
8
|
+
@body = body
|
9
|
+
@output = {}
|
10
|
+
dump
|
11
|
+
end
|
12
|
+
|
13
|
+
def ofx_version
|
14
|
+
@body[/VERSION:([0-9]{3})/, 1].to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
def transactions
|
18
|
+
@output[:transactions]
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def dump
|
24
|
+
@dump ||= Ox.sax_parse(Handler.new(self), @body)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/ofx/version.rb
ADDED
data/lib/ofx.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'ox'
|
2
|
+
require 'ofx/version'
|
3
|
+
require 'ofx/errors'
|
4
|
+
require 'ofx/http'
|
5
|
+
require 'ofx/aggregate'
|
6
|
+
require 'ofx/handler'
|
7
|
+
require 'ofx/document'
|
8
|
+
require 'ofx/parser'
|
9
|
+
require 'ofx/document/signon_message_set'
|
10
|
+
require 'ofx/document/bank_message_set'
|
11
|
+
require 'ofx/document/signon_request'
|
12
|
+
require 'ofx/document/financial_institution'
|
13
|
+
require 'ofx/document/statement_transaction'
|
14
|
+
require 'ofx/document/statement_request'
|
15
|
+
require 'ofx/document/bank_account'
|
16
|
+
require 'ofx/document/include_transactions'
|
17
|
+
|
18
|
+
module OFX
|
19
|
+
end
|
data/ofx-ruby-0.0.11.gem
ADDED
Binary file
|
data/ofx_ruby.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ofx'
|
5
|
+
|
6
|
+
Gem::Specification.new do |g|
|
7
|
+
g.name = "ofx_ruby"
|
8
|
+
g.version = OFX::VERSION
|
9
|
+
g.authors = ["rob"]
|
10
|
+
g.email = ["rob.all3n@gmail.com"]
|
11
|
+
g.homepage = "http://graveflex.com"
|
12
|
+
|
13
|
+
g.license = "MIT"
|
14
|
+
g.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|g|features)/}) }
|
15
|
+
g.require_paths = ["lib"]
|
16
|
+
|
17
|
+
g.add_development_dependency "bundler", "~> 1.10"
|
18
|
+
g.add_development_dependency "rake", "~> 10.0"
|
19
|
+
g.add_development_dependency "minitest", "~> 5.9"
|
20
|
+
g.add_development_dependency "excon", "~> 0.52.0"
|
21
|
+
g.add_development_dependency "guard", "~> 2.14.0"
|
22
|
+
g.add_development_dependency "guard-minitest", "~> 2.4.5"
|
23
|
+
g.add_development_dependency "dotenv", "~> 2.1.1"
|
24
|
+
g.add_development_dependency "byebug", "~> 9.0.5"
|
25
|
+
|
26
|
+
g.required_ruby_version = ">= 2.3"
|
27
|
+
g.add_dependency "ox", "~> 2.4"
|
28
|
+
|
29
|
+
g.summary = g.description = %q{A simple, incomplete OFX gem for Ruby.}
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,198 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ofx_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.11
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rob
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.9'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.9'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: excon
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.52.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.52.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.14.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.14.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.4.5
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.4.5
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.1.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.1.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 9.0.5
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 9.0.5
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: ox
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '2.4'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '2.4'
|
139
|
+
description: A simple, incomplete OFX gem for Ruby.
|
140
|
+
email:
|
141
|
+
- rob.all3n@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".travis.yml"
|
148
|
+
- CODE_OF_CONDUCT.md
|
149
|
+
- Gemfile
|
150
|
+
- Guardfile
|
151
|
+
- LICENSE.txt
|
152
|
+
- README.md
|
153
|
+
- Rakefile
|
154
|
+
- bin/console
|
155
|
+
- bin/setup
|
156
|
+
- lib/ofx.rb
|
157
|
+
- lib/ofx/aggregate.rb
|
158
|
+
- lib/ofx/document.rb
|
159
|
+
- lib/ofx/document/bank_account.rb
|
160
|
+
- lib/ofx/document/bank_message_set.rb
|
161
|
+
- lib/ofx/document/financial_institution.rb
|
162
|
+
- lib/ofx/document/include_transactions.rb
|
163
|
+
- lib/ofx/document/signon_message_set.rb
|
164
|
+
- lib/ofx/document/signon_request.rb
|
165
|
+
- lib/ofx/document/statement_request.rb
|
166
|
+
- lib/ofx/document/statement_transaction.rb
|
167
|
+
- lib/ofx/errors.rb
|
168
|
+
- lib/ofx/handler.rb
|
169
|
+
- lib/ofx/http.rb
|
170
|
+
- lib/ofx/parser.rb
|
171
|
+
- lib/ofx/version.rb
|
172
|
+
- ofx-ruby-0.0.11.gem
|
173
|
+
- ofx_ruby.gemspec
|
174
|
+
homepage: http://graveflex.com
|
175
|
+
licenses:
|
176
|
+
- MIT
|
177
|
+
metadata: {}
|
178
|
+
post_install_message:
|
179
|
+
rdoc_options: []
|
180
|
+
require_paths:
|
181
|
+
- lib
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
version: '2.3'
|
187
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
requirements: []
|
193
|
+
rubyforge_project:
|
194
|
+
rubygems_version: 2.5.1
|
195
|
+
signing_key:
|
196
|
+
specification_version: 4
|
197
|
+
summary: A simple, incomplete OFX gem for Ruby.
|
198
|
+
test_files: []
|