ofx-data 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/CODE_OF_CONDUCT.md +49 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +53 -0
  8. data/Rakefile +2 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/lib/ofx-data.rb +1 -0
  12. data/lib/ofx/data.rb +9 -0
  13. data/lib/ofx/data/banking.rb +4 -0
  14. data/lib/ofx/data/banking/balance.rb +21 -0
  15. data/lib/ofx/data/banking/bank_account.rb +35 -0
  16. data/lib/ofx/data/banking/statement.rb +2 -0
  17. data/lib/ofx/data/banking/statement/response.rb +27 -0
  18. data/lib/ofx/data/banking/statement/transaction.rb +23 -0
  19. data/lib/ofx/data/banking/transaction.rb +48 -0
  20. data/lib/ofx/data/declaration.rb +27 -0
  21. data/lib/ofx/data/document.rb +26 -0
  22. data/lib/ofx/data/message_set.rb +2 -0
  23. data/lib/ofx/data/message_set/banking.rb +31 -0
  24. data/lib/ofx/data/message_set/signon.rb +21 -0
  25. data/lib/ofx/data/objects.rb +5 -0
  26. data/lib/ofx/data/serialization.rb +17 -0
  27. data/lib/ofx/data/serialization/banking.rb +4 -0
  28. data/lib/ofx/data/serialization/banking/balance.rb +21 -0
  29. data/lib/ofx/data/serialization/banking/bank_account.rb +38 -0
  30. data/lib/ofx/data/serialization/banking/statement.rb +2 -0
  31. data/lib/ofx/data/serialization/banking/statement/response.rb +38 -0
  32. data/lib/ofx/data/serialization/banking/statement/transaction.rb +31 -0
  33. data/lib/ofx/data/serialization/banking/transaction.rb +28 -0
  34. data/lib/ofx/data/serialization/common.rb +21 -0
  35. data/lib/ofx/data/serialization/document.rb +29 -0
  36. data/lib/ofx/data/serialization/message_set.rb +32 -0
  37. data/lib/ofx/data/serialization/message_set/banking.rb +27 -0
  38. data/lib/ofx/data/serialization/registry.rb +31 -0
  39. data/lib/ofx/data/serialization/transaction/status.rb +26 -0
  40. data/lib/ofx/data/transaction/status.rb +25 -0
  41. data/lib/ofx/data/version.rb +5 -0
  42. data/ofx-data.gemspec +31 -0
  43. metadata +158 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58bb14e713cbccafb2edd203f404bc9d0059e13d
4
+ data.tar.gz: b250e11392cd18af58df75d418979d2c79a72a3c
5
+ SHA512:
6
+ metadata.gz: f046d7ab0a396fbf058d717a8446c848f0d0b49134cb7e0583a991e9c9804612bc6e2cb386c5cadbca4196716bb1232113c10a0b28843dbc33bd395c4142986d
7
+ data.tar.gz: 8eb9596f4eba26fcfe509139af32dcfa0b9a1defbc2b7d1990467d2db7dc8d535181dc95b0c749f89696c6026851f84ad4682f0db41e9c441cbf086e97f43244
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at matt@reprocessed.org. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ofx-data.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Matt Patterson
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,53 @@
1
+ # Ofx::Data
2
+
3
+ The Open Financial Exchange standard is a standard for transferring information
4
+ between financial institutions, and between financial institutions and their
5
+ users. It specifies a messaging protocal and uses XML-based documents to
6
+ transfer data around. This gem implements an object model and serializer for
7
+ those documents, leaving the Request / Response HTTP-based parts of the
8
+ specification well alone.
9
+
10
+ At the moment it's targeting OFX 2.0.3. I'll look at later (and earlier
11
+ versions) when that's finished.
12
+
13
+ ## Current state
14
+
15
+ I'm targeting statement download responses first, since that's my pressing
16
+ concern. Once that's done and I'm happy with the architecture I'll work my way
17
+ through the spec, completing the Banking section first.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'ofx-data'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install ofx-data
34
+
35
+ ## Usage
36
+
37
+ TODO: Write usage instructions here
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ 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).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ofx-data. 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.
48
+
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
53
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ofx/data"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/ofx-data.rb ADDED
@@ -0,0 +1 @@
1
+ require "ofx/data"
data/lib/ofx/data.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "ofx/data/version"
2
+ require "ofx/data/objects"
3
+ require "ofx/data/serialization"
4
+
5
+ module OFX
6
+ module Data
7
+ # Your code goes here...
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ require "ofx/data/banking/balance"
2
+ require "ofx/data/banking/bank_account"
3
+ require "ofx/data/banking/statement"
4
+ require "ofx/data/banking/transaction"
@@ -0,0 +1,21 @@
1
+ require "date"
2
+ require "bigdecimal"
3
+
4
+ module OFX
5
+ module Data
6
+ module Banking
7
+ class Balance
8
+ attr_reader :amount, :date
9
+
10
+ def initialize(opts)
11
+ @amount = BigDecimal.new(opts.fetch(:amount))
12
+ @date = opts.fetch(:date)
13
+ end
14
+
15
+ def ofx_type
16
+ :"banking.balance"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,35 @@
1
+ module OFX
2
+ module Data
3
+ module Banking
4
+ class BankAccount
5
+ VALID_TYPES = [:checking, :savings, :money_market, :credit_line]
6
+ attr_reader :bank_id, :branch_id, :account_id, :account_type, :account_key
7
+
8
+ def initialize(opts)
9
+ @bank_id = opts.fetch(:bank_id)
10
+ raise ArgumentError, ":bank_id must be 1-9 characters long" if @bank_id.length > 9
11
+ @branch_id = opts.fetch(:branch_id, "")
12
+ raise ArgumentError, ":branch_id must be 1-22 characters long" if @branch_id.length > 22
13
+ @account_id = opts.fetch(:account_id)
14
+ raise ArgumentError, ":account_id must be 1-22 characters long" if @account_id.length > 22
15
+ @account_type = opts.fetch(:account_type)
16
+ raise ArgumentError, ":account_type must be one of #{VALID_TYPES.inspect}, it was #{@account_type.inspect}" if !VALID_TYPES.include?(@account_type)
17
+ @account_key = opts.fetch(:account_key, "")
18
+ raise ArgumentError, ":account_key must be 1-22 characters long" if @account_key.length > 22
19
+ end
20
+
21
+ def fitid_str
22
+ [
23
+ :bank_id, :branch_id, :account_id, :account_type, :account_key
24
+ ].map { |meth|
25
+ send(meth)
26
+ }.join("")
27
+ end
28
+
29
+ def ofx_type
30
+ :"banking.bank_account"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,2 @@
1
+ require "ofx/data/banking/statement/response"
2
+ require "ofx/data/banking/statement/transaction"
@@ -0,0 +1,27 @@
1
+ module OFX
2
+ module Data
3
+ module Banking
4
+ module Statement
5
+ class Response
6
+ attr_reader :curdef, :account, :ledger_balance, :available_balance,
7
+ :start_date, :end_date, :transactions, :marketing_info
8
+
9
+ def initialize(opts)
10
+ @curdef = opts.fetch(:curdef)
11
+ @account = opts.fetch(:account)
12
+ @ledger_balance = opts.fetch(:ledger_balance)
13
+ @available_balance = opts.fetch(:available_balance)
14
+ @start_date = opts.fetch(:start_date)
15
+ @end_date = opts.fetch(:end_date)
16
+ @transactions = opts.fetch(:transactions, [])
17
+ @marketing_info = opts.fetch(:marketing_info, "")
18
+ end
19
+
20
+ def ofx_type
21
+ :"banking.statement.response"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,23 @@
1
+ module OFX
2
+ module Data
3
+ module Banking
4
+ module Statement
5
+ module Transaction
6
+ class Response
7
+ attr_reader :trnuid, :status, :response
8
+
9
+ def initialize(opts)
10
+ @trnuid = opts.fetch(:trnuid)
11
+ @status = opts.fetch(:status)
12
+ @response = opts.fetch(:response)
13
+ end
14
+
15
+ def ofx_type
16
+ :"banking.statement.transaction.response"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,48 @@
1
+ require "bigdecimal"
2
+ require "digest/sha1"
3
+
4
+ module OFX
5
+ module Data
6
+ module Banking
7
+ class Transaction
8
+ FIELDS = [:type, :date_posted, :amount, :bank_account_to, :name, :refnum, :payee_id, :memo].freeze
9
+ VALID_TYPES = [
10
+ :credit, :debit, :int, :div, :fee, :srvchg, :dep, :atm, :pos, :xfer,
11
+ :check, :payment, :cash, :directdep, :directdebit, :repeatpmt, :other
12
+ ].freeze
13
+
14
+ def self.with_synthetic_fitid(opts)
15
+ input = FIELDS.map { |key|
16
+ opts.fetch(key, "")
17
+ }.map { |value|
18
+ value.respond_to?(:fitid_str) ? value.fitid_str : value.to_s
19
+ }.join("")
20
+ fitid = Digest::SHA1.hexdigest(input)
21
+ new(opts.merge(fitid: fitid))
22
+ end
23
+
24
+ attr_reader :fitid, *FIELDS
25
+
26
+ def initialize(opts)
27
+ @type = opts.fetch(:type)
28
+ raise ArgumentError, ":type must be one of #{VALID_TYPES.inspect}, was #{@type}" if !VALID_TYPES.include?(@type)
29
+ @date_posted = opts.fetch(:date_posted)
30
+ @amount = BigDecimal.new(opts.fetch(:amount))
31
+ @fitid = opts.fetch(:fitid)
32
+ @bank_account_to = opts.fetch(:bank_account_to, nil)
33
+ @name = opts.fetch(:name, nil)
34
+ raise ArgumentError, ":name must be 1-32 characters long" if @name && @name.length > 32
35
+ @refnum = opts.fetch(:refnum, nil)
36
+ raise ArgumentError, ":refnum must be 1-32 characters long" if @refnum && @refnum.length > 32
37
+ @payee_id = opts.fetch(:payee_id, nil)
38
+ raise ArgumentError, ":payee_id must be 1-12 characters long" if @payee_id && @payee_id.length > 12
39
+ @memo = opts.fetch(:memo, nil)
40
+ end
41
+
42
+ def ofx_type
43
+ :"banking.statement_transaction"
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,27 @@
1
+ module OFX
2
+ module Data
3
+ class Declaration
4
+ DEFAULTS = {
5
+ :"2.0.3" => {ofxheader: "200", version: "203"}
6
+ }
7
+
8
+ def self.[](key)
9
+ new(DEFAULTS.fetch(key))
10
+ end
11
+
12
+ def self.default
13
+ self[:"2.0.3"]
14
+ end
15
+
16
+ attr_reader :ofxheader, :version, :security, :oldfileuid, :newfileuid
17
+
18
+ def initialize(opts)
19
+ @ofxheader = opts.fetch(:ofxheader, "NONE")
20
+ @version = opts.fetch(:version, "NONE")
21
+ @security = opts.fetch(:security, "NONE")
22
+ @oldfileuid = opts.fetch(:oldfileuid, "NONE")
23
+ @newfileuid = opts.fetch(:newfileuid, "NONE")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require "ofx/data/declaration"
2
+
3
+ module OFX
4
+ module Data
5
+ class Document
6
+ attr_reader :message_sets, :declaration
7
+
8
+ def initialize(opts = {})
9
+ @message_sets = opts.fetch(:message_sets, []).freeze
10
+ @declaration = opts.fetch(:declaration, Declaration.default)
11
+ end
12
+
13
+ def response?
14
+ true
15
+ end
16
+
17
+ def request?
18
+ !response?
19
+ end
20
+
21
+ def ofx_type
22
+ :document
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,2 @@
1
+ require "ofx/data/message_set/signon"
2
+ require "ofx/data/message_set/banking"
@@ -0,0 +1,31 @@
1
+ module OFX
2
+ module Data
3
+ module MessageSet
4
+ module Banking
5
+ MESSAGE_SET_TYPE = :banking
6
+
7
+ class Request
8
+ def message_set_type
9
+ MESSAGE_SET_TYPE
10
+ end
11
+ end
12
+
13
+ class Response
14
+ attr_reader :messages
15
+
16
+ def initialize(messages)
17
+ @messages = messages
18
+ end
19
+
20
+ def message_set_type
21
+ MESSAGE_SET_TYPE
22
+ end
23
+
24
+ def ofx_type
25
+ :"message_sets.banking.response"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ module OFX
2
+ module Data
3
+ module MessageSet
4
+ module Signon
5
+ MESSAGE_SET_TYPE = :signon
6
+
7
+ class Request
8
+ def message_set_type
9
+ MESSAGE_SET_TYPE
10
+ end
11
+ end
12
+
13
+ class Response
14
+ def message_set_type
15
+ MESSAGE_SET_TYPE
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require "ofx/data/document"
2
+ require "ofx/data/transaction/status"
3
+ require "ofx/data/message_set"
4
+ require "ofx/data/banking"
5
+
@@ -0,0 +1,17 @@
1
+ require "ofx/data/serialization/registry"
2
+ require "ofx/data/serialization/document"
3
+ require "ofx/data/serialization/message_set"
4
+ require "ofx/data/serialization/banking"
5
+ require "ofx/data/serialization/transaction/status"
6
+
7
+ module OFX
8
+ module Data
9
+ module Serialization
10
+ def self.serialize(object)
11
+ xml = Builder::XmlMarkup.new
12
+ registry.serializer_for(object).serialize(object, xml)
13
+ xml.target!
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ require "ofx/data/serialization/banking/balance"
2
+ require "ofx/data/serialization/banking/bank_account"
3
+ require "ofx/data/serialization/banking/transaction"
4
+ require "ofx/data/serialization/banking/statement"
@@ -0,0 +1,21 @@
1
+ require "ofx/data/serialization"
2
+ require "ofx/data/serialization/common"
3
+
4
+ module OFX
5
+ module Data
6
+ module Serialization
7
+ module Banking
8
+ class Balance
9
+ extend Serialization::Common
10
+
11
+ def self.serialize(balance, builder)
12
+ builder.BALAMT balance.amount.to_s("F")
13
+ builder.DTASOF balance.date.strftime("%Y%m%d%H%M%S")
14
+ end
15
+ end
16
+ end
17
+
18
+ register Banking::Balance, :"banking.balance"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,38 @@
1
+ require "ofx/data/serialization"
2
+ require "ofx/data/serialization/common"
3
+
4
+ module OFX
5
+ module Data
6
+ module Serialization
7
+ module Banking
8
+ class BankAccount
9
+ extend Serialization::Common
10
+ ACCT_TYPES = {
11
+ checking: "CHECKING".freeze,
12
+ savings: "SAVINGS".freeze,
13
+ money_market: "MONEYMRKT".freeze,
14
+ credit_line: "CREDITLINE"
15
+ }
16
+
17
+ def self.serialize(bank_account, builder)
18
+ builder.BANKID bank_account.bank_id
19
+ if bank_account.branch_id != ""
20
+ builder.BRANCHID bank_account.branch_id
21
+ end
22
+ builder.ACCTID bank_account.account_id
23
+ builder.ACCTTYPE acct_type(bank_account.account_type)
24
+ if bank_account.account_key != ""
25
+ builder.ACCTKEY bank_account.account_key
26
+ end
27
+ end
28
+
29
+ def self.acct_type(type)
30
+ ACCT_TYPES.fetch(type)
31
+ end
32
+ end
33
+ end
34
+
35
+ register Banking::BankAccount, :"banking.bank_account"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,2 @@
1
+ require "ofx/data/serialization/banking/statement/response"
2
+ require "ofx/data/serialization/banking/statement/transaction"
@@ -0,0 +1,38 @@
1
+ require "ofx/data/serialization"
2
+ require "ofx/data/serialization/common"
3
+
4
+ module OFX
5
+ module Data
6
+ module Serialization
7
+ module Banking
8
+ module Statement
9
+ class Response
10
+ extend Serialization::Common
11
+
12
+ def self.serialize(response, builder)
13
+ builder.STMTRS do |builder|
14
+ builder.CURDEF response.curdef.to_s.upcase
15
+ builder.BANKACCTFROM do |builder|
16
+ serialize_object(response.account, builder)
17
+ end
18
+ builder.BANKTRANLIST do |builder|
19
+ builder.DTSTART response.start_date.strftime("%Y%m%d%H%M%S")
20
+ builder.DTEND response.end_date.strftime("%Y%m%d%H%M%S")
21
+ serialize_collection(response.transactions, builder)
22
+ end
23
+ builder.LEDGERBAL do |builder|
24
+ serialize_object(response.ledger_balance, builder)
25
+ end
26
+ builder.AVAILBAL do |builder|
27
+ serialize_object(response.available_balance, builder)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ register Banking::Statement::Response, :"banking.statement.response"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,31 @@
1
+ require "ofx/data/serialization"
2
+ require "ofx/data/serialization/common"
3
+
4
+ module OFX
5
+ module Data
6
+ module Serialization
7
+ module Banking
8
+ module Statement
9
+ module Transaction
10
+ class Response
11
+ extend Common
12
+
13
+ def self.serialize(transaction, builder)
14
+ builder.STMTTRNRS do |builder|
15
+ builder.TRNUID transaction.trnuid
16
+ serialize_collection(children(transaction), builder)
17
+ end
18
+ end
19
+
20
+ def self.children(transaction)
21
+ [transaction.status, transaction.response]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ register Banking::Statement::Transaction::Response, :"banking.statement.transaction.response"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ require "ofx/data/serialization"
2
+ require "ofx/data/serialization/common"
3
+
4
+ module OFX
5
+ module Data
6
+ module Serialization
7
+ module Banking
8
+ class Transaction
9
+ extend Serialization::Common
10
+
11
+ def self.serialize(transaction, builder)
12
+ builder.STMTTRN do |builder|
13
+ builder.TRNTYPE transaction.type.to_s.upcase
14
+ builder.DTPOSTED transaction.date_posted.strftime("%Y%m%d%H%M%S")
15
+ builder.TRNAMT transaction.amount.to_s("F")
16
+ builder.FITID transaction.fitid
17
+ if transaction.name
18
+ builder.NAME transaction.name
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ register Banking::Transaction, :"banking.statement_transaction"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ module OFX
2
+ module Data
3
+ module Serialization
4
+ module Common
5
+ def serialize_object(object, builder)
6
+ registry.serializer_for(object).serialize(object, builder)
7
+ end
8
+
9
+ def serialize_collection(collection, builder)
10
+ collection.each do |object|
11
+ serialize_object(object, builder)
12
+ end
13
+ end
14
+
15
+ def registry
16
+ OFX::Data::Serialization.registry
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ require "ofx/data/serialization"
2
+ require "ofx/data/serialization/common"
3
+
4
+ module OFX
5
+ module Data
6
+ module Serialization
7
+ class Document
8
+ extend Common
9
+
10
+ def self.serialize(document, builder)
11
+ decl = document.declaration
12
+ builder.instruct!
13
+ builder.instruct!(:OFX, {
14
+ OFXHEADER: decl.ofxheader,
15
+ VERSION: decl.version,
16
+ SECURITY: decl.security,
17
+ OLDFILEUID: decl.oldfileuid,
18
+ NEWFILEUID: decl.newfileuid
19
+ })
20
+ builder.OFX do |builder|
21
+ MessageSet.serialize(document.message_sets, builder)
22
+ end
23
+ end
24
+ end
25
+
26
+ register(Document, :document)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,32 @@
1
+ require "ofx/data/serialization"
2
+ require "ofx/data/serialization/common"
3
+ require "ofx/data/serialization/message_set/banking"
4
+
5
+ module OFX
6
+ module Data
7
+ module Serialization
8
+ module MessageSet
9
+ extend Common
10
+
11
+ ORDER = [
12
+ :signon, :signup, :banking, :credit_card_statements,
13
+ :investment_statements, :interbank_funds_transfers,
14
+ :wire_funds_transfers, :payments, :general_email,
15
+ :investment_security_list, :biller_directory,
16
+ :bill_delivery, :fi_profile
17
+ ]
18
+ ORDER_LOOKUP = Hash[ORDER.each_with_index.map { |k, v| [k, v] }]
19
+
20
+ def self.order_sets(message_sets)
21
+ message_sets.sort_by { |set| ORDER_LOOKUP[set.message_set_type] }
22
+ end
23
+
24
+ def self.serialize(message_sets, builder)
25
+ serialize_collection(order_sets(message_sets), builder)
26
+ end
27
+ end
28
+
29
+ register(MessageSet, :message_sets)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ require "ofx/data/serialization"
2
+ require "ofx/data/serialization/common"
3
+
4
+ module OFX
5
+ module Data
6
+ module Serialization
7
+ module MessageSet
8
+ module Banking
9
+ class Request
10
+ end
11
+
12
+ class Response
13
+ extend Serialization::Common
14
+
15
+ def self.serialize(message_set, builder)
16
+ builder.BANKMSGSRSV1 do |builder|
17
+ serialize_collection(message_set.messages, builder)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ register MessageSet::Banking::Response, :"message_sets.banking.response"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ module OFX
2
+ module Data
3
+ module Serialization
4
+ class Registry
5
+ def initialize
6
+ @registry = {}
7
+ end
8
+
9
+ def register(serialization_class, ofx_type)
10
+ @registry[ofx_type] = serialization_class
11
+ end
12
+
13
+ def serializer_for(data_instance)
14
+ @registry.fetch(data_instance.ofx_type)
15
+ end
16
+
17
+ def registered_for(serialization_class)
18
+ @registry.find(->() { [] }) { |ofx_type, klass| klass == serialization_class }.first
19
+ end
20
+ end
21
+
22
+ def self.registry
23
+ @registry ||= OFX::Data::Serialization::Registry.new
24
+ end
25
+
26
+ def self.register(*args)
27
+ registry.register(*args)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,26 @@
1
+ require "ofx/data/serialization"
2
+ require "ofx/data/serialization/common"
3
+
4
+ module OFX
5
+ module Data
6
+ module Serialization
7
+ module Transaction
8
+ class Status
9
+ extend Serialization::Common
10
+
11
+ def self.serialize(status, builder)
12
+ builder.STATUS do |builder|
13
+ builder.CODE status.code
14
+ builder.SEVERITY status.severity.to_s.upcase
15
+ unless status.message.nil?
16
+ builder.MESSAGE status.message
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ register Transaction::Status, :"transaction.status"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module OFX
2
+ module Data
3
+ module Transaction
4
+ class Status
5
+ SEVERITIES = [:info, :warn, :error].freeze
6
+
7
+ attr_reader :code, :severity, :message
8
+
9
+ def initialize(opts)
10
+ @code = opts.fetch(:code)
11
+ raise ArgumentError, ":code must be an integer, was #{@code.inspect}" unless @code.is_a?(Fixnum)
12
+ raise ArgumentError, ":code must be a positive integer < 1000000, was #{@code}" if @code > 999999
13
+ @severity = opts.fetch(:severity)
14
+ raise ArgumentError, ":severity must be one of #{SEVERITIES.inspect}, was #{@severity.inspect}" unless SEVERITIES.include?(@severity)
15
+ @message = opts.fetch(:message, nil)
16
+ raise ArgumentError, ":message must be no more than 255 chars, was #{@message.length}" if @message && @message.length > 255
17
+ end
18
+
19
+ def ofx_type
20
+ :"transaction.status"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ module OFX
2
+ module Data
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/ofx-data.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ofx/data/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ofx-data"
8
+ spec.version = OFX::Data::VERSION
9
+ spec.authors = ["Matt Patterson"]
10
+ spec.email = ["matt@reprocessed.org"]
11
+
12
+ spec.summary = %q{Generate OFX XML documents}
13
+ spec.description = <<EOS
14
+ The Open Financial eXchange standard uses XML-based documents to transfer data
15
+ around. This gem implements an object model and serializer for those documents,
16
+ leaving the Request / Response HTTP-based parts of the specification well alone
17
+ EOS
18
+ spec.homepage = "https://github.com/fidothe/ofx-data"
19
+ spec.license = "MIT"
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "builder", "~> 3.2"
27
+ spec.add_development_dependency "bundler", "~> 1.12"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency "nokogiri", "~> 1.6"
31
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ofx-data
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Patterson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: builder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ description: |
84
+ The Open Financial eXchange standard uses XML-based documents to transfer data
85
+ around. This gem implements an object model and serializer for those documents,
86
+ leaving the Request / Response HTTP-based parts of the specification well alone
87
+ email:
88
+ - matt@reprocessed.org
89
+ executables: []
90
+ extensions: []
91
+ extra_rdoc_files: []
92
+ files:
93
+ - ".gitignore"
94
+ - ".rspec"
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - bin/console
101
+ - bin/setup
102
+ - lib/ofx-data.rb
103
+ - lib/ofx/data.rb
104
+ - lib/ofx/data/banking.rb
105
+ - lib/ofx/data/banking/balance.rb
106
+ - lib/ofx/data/banking/bank_account.rb
107
+ - lib/ofx/data/banking/statement.rb
108
+ - lib/ofx/data/banking/statement/response.rb
109
+ - lib/ofx/data/banking/statement/transaction.rb
110
+ - lib/ofx/data/banking/transaction.rb
111
+ - lib/ofx/data/declaration.rb
112
+ - lib/ofx/data/document.rb
113
+ - lib/ofx/data/message_set.rb
114
+ - lib/ofx/data/message_set/banking.rb
115
+ - lib/ofx/data/message_set/signon.rb
116
+ - lib/ofx/data/objects.rb
117
+ - lib/ofx/data/serialization.rb
118
+ - lib/ofx/data/serialization/banking.rb
119
+ - lib/ofx/data/serialization/banking/balance.rb
120
+ - lib/ofx/data/serialization/banking/bank_account.rb
121
+ - lib/ofx/data/serialization/banking/statement.rb
122
+ - lib/ofx/data/serialization/banking/statement/response.rb
123
+ - lib/ofx/data/serialization/banking/statement/transaction.rb
124
+ - lib/ofx/data/serialization/banking/transaction.rb
125
+ - lib/ofx/data/serialization/common.rb
126
+ - lib/ofx/data/serialization/document.rb
127
+ - lib/ofx/data/serialization/message_set.rb
128
+ - lib/ofx/data/serialization/message_set/banking.rb
129
+ - lib/ofx/data/serialization/registry.rb
130
+ - lib/ofx/data/serialization/transaction/status.rb
131
+ - lib/ofx/data/transaction/status.rb
132
+ - lib/ofx/data/version.rb
133
+ - ofx-data.gemspec
134
+ homepage: https://github.com/fidothe/ofx-data
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.5.1
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Generate OFX XML documents
158
+ test_files: []