ofx_for_ruby 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5ff318155e5d3faeab49209d7492b3f9ba36400
4
- data.tar.gz: 049c7b99734a9da7a0fcedf0f34dd2b051c63d29
3
+ metadata.gz: 41a866d8860d900a7fee63c524916d3d9cc0f771
4
+ data.tar.gz: 59869261ce4b873f2b10e63502e5d36ad45ba0c0
5
5
  SHA512:
6
- metadata.gz: 0574c03c81ba22a20babfbbba79a4d821ed7f6a5e0a131ed6d4a87f0bbfa6f31d5e3e7ee6fdb8e255fa8d9a9fa4c02755b4412ab08b94d75e905933662ea3231
7
- data.tar.gz: 81a52f06bfc3bcd1280b2057302e0e0882c6b9a468ffcd7e73485a8ae8ad776285c4fa46e7c587fa665059d2961bc12a60c2fff8a82f05aa09b7bb085ee78da6
6
+ metadata.gz: fa7e804432236f4d49c66899a47abe5091a6845beb0898e7419334d67605828bd18f7b9db87f064cbc7ff5ba044647c53ec8467662539a2e68025eb0d72c2416
7
+ data.tar.gz: 757f22807ba8f6e6924360fa1dd4a607972d5fc201c691d3b505ad8b063d1923be03b21cf4a143e4e514f2c051453696d1f70d4a2b26324f1950ecb737d22054
@@ -1,17 +1,17 @@
1
1
  # Copyright © 2007 Chris Guidry <chrisguidry@gmail.com>
2
2
  #
3
3
  # This file is part of OFX for Ruby.
4
- #
4
+ #
5
5
  # OFX for Ruby is free software; you can redistribute it and/or modify
6
6
  # it under the terms of the GNU General Public License as published by
7
7
  # the Free Software Foundation; either version 3 of the License, or
8
8
  # (at your option) any later version.
9
- #
9
+ #
10
10
  # OFX for Ruby is distributed in the hope that it will be useful,
11
11
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
12
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
13
  # GNU General Public License for more details.
14
- #
14
+ #
15
15
  # You should have received a copy of the GNU General Public License
16
16
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
@@ -48,37 +48,35 @@ module OFX
48
48
  body += message_set.to_ofx_102_s
49
49
  end
50
50
  body += "</OFX>\n"
51
-
52
- # puts body
53
51
 
54
52
  body
55
53
  end
56
54
 
57
55
  def from_http_response_body(body)
58
- # puts "Raw response:\n#{body}"
56
+ body = body.lstrip
57
+
58
+ end_of_header_index = body.index("<OFX>")
59
+
60
+ header_str = body[0...end_of_header_index].strip
61
+ body = body[end_of_header_index..-1]
59
62
 
60
- #header_pattern = /(\w+\:.*\n)+\n/
61
- header_pattern = /(\w+\:.*\r*\n)+\r*\n/
62
- header_match = header_pattern.match(body)
63
- if header_match.nil?
63
+ if header_str.nil? || header_str == ""
64
64
  raise NotImplementedError, "OFX server returned unmatched ASCII"
65
- return body
66
65
  end
67
66
 
68
- body = header_match.post_match
69
- header = Header.from_ofx_102_s(header_match[0].strip)
70
-
67
+ header = Header.from_ofx_102_s(header_str)
68
+
71
69
  parser = OFX::OFX102::Parser.new
72
70
 
73
71
  parser.scan_str body
74
-
72
+
75
73
  if parser.documents.length > 1
76
74
  raise NotImplementedError, "Multiple response documents"
77
75
  end
78
-
76
+
79
77
  # require 'pp'
80
78
  # pp parser.ofx_hashes[0]
81
-
79
+
82
80
  document = parser.documents[0]
83
81
  document.header = header
84
82
  document
data/lib/ofx/version.rb CHANGED
@@ -82,5 +82,5 @@ module OFX
82
82
  end
83
83
  end
84
84
 
85
- VERSION = Version.new('0.1.4')
85
+ VERSION = Version.new('0.1.5')
86
86
  end
@@ -0,0 +1,192 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
+
3
+ class OFXParserTest < Minitest::Test
4
+ def test_parse_with_no_newline_after_header
5
+ body = <<-EOS
6
+
7
+ OFXHEADER:100
8
+ DATA:OFXSGML
9
+ VERSION:102
10
+ SECURITY:NONE
11
+ ENCODING:USASCII
12
+ CHARSET:1252
13
+ COMPRESSION:NONE
14
+ OLDFILEUID:NONE
15
+ NEWFILEUID:NONE
16
+ <OFX>
17
+ <SIGNONMSGSRSV1>
18
+ <SONRS>
19
+ <STATUS>
20
+ <CODE>0
21
+ <SEVERITY>INFO
22
+ </STATUS>
23
+ <DTSERVER>20221013120000[0:GMT]
24
+ <LANGUAGE>ENG
25
+ <FI>
26
+ <ORG>B1
27
+ <FID>10898
28
+ </FI>
29
+ <INTU.BID>10898
30
+ </SONRS>
31
+ </SIGNONMSGSRSV1>
32
+ <BANKMSGSRSV1>
33
+ <STMTTRNRS>
34
+ <TRNUID>1
35
+ <STATUS>
36
+ <CODE>0
37
+ <SEVERITY>INFO
38
+ <MESSAGE>Success
39
+ </STATUS>
40
+ <STMTRS>
41
+ <CURDEF>USD
42
+ <BANKACCTFROM>
43
+ <BANKID>0713456513
44
+ <ACCTID>123456788
45
+ <ACCTTYPE>CHECKING
46
+ </BANKACCTFROM>
47
+ <BANKTRANLIST>
48
+ <DTSTART>20221003120000[0:GMT]
49
+ <DTEND>20221012120000[0:GMT]
50
+ <STMTTRN>
51
+ <TRNTYPE>DEBIT
52
+ <DTPOSTED>20221012120000[0:GMT]
53
+ <TRNAMT>-100.01
54
+ <FITID>202210120
55
+ <NAME>CAPITAL ONE N.A. CAPITALONE 0000
56
+ <MEMO>0234345d WEB ID: 15234563
57
+ </STMTTRN>
58
+ </BANKTRANLIST>
59
+ <LEDGERBAL>
60
+ <BALAMT>29.03
61
+ <DTASOF>20221013120000[0:GMT]
62
+ </LEDGERBAL>
63
+ <AVAILBAL>
64
+ <BALAMT>30.06
65
+ <DTASOF>20221013120000[0:GMT]
66
+ </AVAILBAL>
67
+ </STMTRS>
68
+ </STMTTRNRS>
69
+ </BANKMSGSRSV1>
70
+ </OFX>
71
+ EOS
72
+
73
+ serializer = OFX::OFX102::Serializer.new
74
+ document = serializer.from_http_response_body(body)
75
+
76
+ signon_message_set = document.message_sets[0]
77
+ signon_response = signon_message_set.responses[0]
78
+
79
+ banking_statement_message_set = document.message_sets[1]
80
+ banking_statement_response = banking_statement_message_set.responses[0]
81
+
82
+ assert_equal '123456788', banking_statement_response.account.account_identifier
83
+ assert_equal '0713456513', banking_statement_response.account.bank_identifier
84
+ assert_equal '30.06', banking_statement_response.available_balance.amount
85
+ assert_equal '29.03', banking_statement_response.ledger_balance.amount
86
+
87
+ transactions = banking_statement_response.transactions
88
+ assert_equal 1, transactions.size
89
+
90
+ transaction = transactions.first
91
+ assert_equal '-100.01', transaction.amount.to_f.to_s
92
+ assert_equal 'CAPITAL ONE N.A. CAPITALONE 0000', transaction.payee
93
+ assert_equal :debit, transaction.transaction_type
94
+ end
95
+
96
+ def test_with_newline_after_header
97
+ body =
98
+ "OFXHEADER:100
99
+ DATA:OFXSGML
100
+ VERSION:102
101
+ SECURITY:NONE
102
+ ENCODING:USASCII
103
+ CHARSET:1252
104
+ COMPRESSION:NONE
105
+ OLDFILEUID:NONE
106
+ NEWFILEUID:NONE
107
+
108
+ <OFX>
109
+ <SIGNONMSGSRSV1>
110
+ <SONRS>
111
+ <STATUS>
112
+ <CODE>0
113
+ <SEVERITY>INFO
114
+ </STATUS>
115
+ <DTSERVER>20221013120000[0:GMT]
116
+ <LANGUAGE>ENG
117
+ <FI>
118
+ <ORG>B1
119
+ <FID>10898
120
+ </FI>
121
+ <INTU.BID>10898
122
+ </SONRS>
123
+ </SIGNONMSGSRSV1>
124
+ <BANKMSGSRSV1>
125
+ <STMTTRNRS>
126
+ <TRNUID>1
127
+ <STATUS>
128
+ <CODE>0
129
+ <SEVERITY>INFO
130
+ <MESSAGE>Success
131
+ </STATUS>
132
+ <STMTRS>
133
+ <CURDEF>USD
134
+ <BANKACCTFROM>
135
+ <BANKID>0713456513
136
+ <ACCTID>123456788
137
+ <ACCTTYPE>CHECKING
138
+ </BANKACCTFROM>
139
+ <BANKTRANLIST>
140
+ <DTSTART>20221003120000[0:GMT]
141
+ <DTEND>20221012120000[0:GMT]
142
+ <STMTTRN>
143
+ <TRNTYPE>DEBIT
144
+ <DTPOSTED>20221012120000[0:GMT]
145
+ <TRNAMT>-100.01
146
+ <FITID>202210120
147
+ <NAME>CAPITAL ONE N.A. CAPITALONE 0000
148
+ <MEMO>0234345d WEB ID: 15234563
149
+ </STMTTRN>
150
+ </BANKTRANLIST>
151
+ <LEDGERBAL>
152
+ <BALAMT>29.03
153
+ <DTASOF>20221013120000[0:GMT]
154
+ </LEDGERBAL>
155
+ <AVAILBAL>
156
+ <BALAMT>30.06
157
+ <DTASOF>20221013120000[0:GMT]
158
+ </AVAILBAL>
159
+ </STMTRS>
160
+ </STMTTRNRS>
161
+ </BANKMSGSRSV1>
162
+ </OFX>"
163
+
164
+ serializer = OFX::OFX102::Serializer.new
165
+ document = serializer.from_http_response_body(body)
166
+
167
+ # require 'pp'
168
+ # pp document
169
+
170
+ signon_message_set = document.message_sets[0]
171
+ signon_response = signon_message_set.responses[0]
172
+
173
+ signon_message_set = document.message_sets[0]
174
+ signon_response = signon_message_set.responses[0]
175
+
176
+ banking_statement_message_set = document.message_sets[1]
177
+ banking_statement_response = banking_statement_message_set.responses[0]
178
+
179
+ assert_equal '123456788', banking_statement_response.account.account_identifier
180
+ assert_equal '0713456513', banking_statement_response.account.bank_identifier
181
+ assert_equal '30.06', banking_statement_response.available_balance.amount
182
+ assert_equal '29.03', banking_statement_response.ledger_balance.amount
183
+
184
+ transactions = banking_statement_response.transactions
185
+ assert_equal 1, transactions.size
186
+
187
+ transaction = transactions.first
188
+ assert_equal '-100.01', transaction.amount.to_f.to_s
189
+ assert_equal 'CAPITAL ONE N.A. CAPITALONE 0000', transaction.payee
190
+ assert_equal :debit, transaction.transaction_type
191
+ end
192
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ofx_for_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Guidry
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-12-27 00:00:00.000000000 Z
12
+ date: 2022-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -168,6 +168,7 @@ files:
168
168
  - test/test_helper.rb
169
169
  - test/test_ofx_version.rb
170
170
  - test/test_parser.rb
171
+ - test/test_serializer.rb
171
172
  homepage: http://github.com/baconpat/ofx_for_ruby
172
173
  licenses: []
173
174
  metadata: {}