qonto_ofx 1.0.1

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.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +1 -0
  4. data/.rubocop_todo.yml +68 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +60 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +34 -0
  9. data/Rakefile +11 -0
  10. data/bin/qonto_ofx +24 -0
  11. data/bin/setup +8 -0
  12. data/lib/api_gateway.rb +47 -0
  13. data/lib/base_validator.rb +17 -0
  14. data/lib/converter.rb +158 -0
  15. data/lib/ofx_validator.rb +17 -0
  16. data/lib/organization_validator.rb +17 -0
  17. data/lib/qonto_ofx/version.rb +3 -0
  18. data/lib/transactions_listing_validator.rb +17 -0
  19. data/qonto_ofx.gemspec +32 -0
  20. data/qonto_organization_schema.json +63 -0
  21. data/qonto_transactions_schema.json +175 -0
  22. data/schema/.DS_Store +0 -0
  23. data/schema/OFX2_Protocol.xsd +783 -0
  24. data/schema/OFX3_Protocol_dotNET.xsd +691 -0
  25. data/schema/OFX_Banking.xsd +119 -0
  26. data/schema/OFX_Banking_Message_Wrappers.xsd +399 -0
  27. data/schema/OFX_Banking_Messages.xsd +431 -0
  28. data/schema/OFX_BillPay.xsd +223 -0
  29. data/schema/OFX_BillPay_Message_Wrappers.xsd +343 -0
  30. data/schema/OFX_BillPay_Messages.xsd +412 -0
  31. data/schema/OFX_BillerDelivery.xsd +263 -0
  32. data/schema/OFX_BillerDelivery_Message_Wrappers.xsd +295 -0
  33. data/schema/OFX_BillerDelivery_Messages.xsd +259 -0
  34. data/schema/OFX_BillerDirectory.xsd +132 -0
  35. data/schema/OFX_BillerDirectory_Message_Wrappers.xsd +56 -0
  36. data/schema/OFX_BillerDirectory_Messages.xsd +86 -0
  37. data/schema/OFX_Common.xsd +2329 -0
  38. data/schema/OFX_CreditCard.xsd +45 -0
  39. data/schema/OFX_CreditCard_Message_Wrappers.xsd +88 -0
  40. data/schema/OFX_CreditCard_Messages.xsd +102 -0
  41. data/schema/OFX_Email.xsd +25 -0
  42. data/schema/OFX_Email_Message_Wrappers.xsd +129 -0
  43. data/schema/OFX_Email_Messages.xsd +72 -0
  44. data/schema/OFX_Image_Message_Wrappers.xsd +31 -0
  45. data/schema/OFX_Image_Messages.xsd +35 -0
  46. data/schema/OFX_InterTransfer.xsd +24 -0
  47. data/schema/OFX_InterTransfer_Message_Wrappers.xsd +195 -0
  48. data/schema/OFX_InterTransfer_Messages.xsd +256 -0
  49. data/schema/OFX_Investment.xsd +1358 -0
  50. data/schema/OFX_Investment_Message_Wrappers.xsd +162 -0
  51. data/schema/OFX_Investment_Messages.xsd +149 -0
  52. data/schema/OFX_Loan_Message_Wrappers.xsd +1 -0
  53. data/schema/OFX_Loan_Messages.xsd +124 -0
  54. data/schema/OFX_Loans.xsd +200 -0
  55. data/schema/OFX_Messages.xsd +18 -0
  56. data/schema/OFX_Profile.xsd +959 -0
  57. data/schema/OFX_Profile_Message_Wrappers.xsd +55 -0
  58. data/schema/OFX_Profile_Messages.xsd +96 -0
  59. data/schema/OFX_SecuritiesList.xsd +357 -0
  60. data/schema/OFX_SecuritiesList_Message_Wrappers.xsd +55 -0
  61. data/schema/OFX_SecuritiesList_Messages.xsd +55 -0
  62. data/schema/OFX_Signon.xsd +243 -0
  63. data/schema/OFX_Signon_Message_Wrappers.xsd +120 -0
  64. data/schema/OFX_Signon_Messages.xsd +211 -0
  65. data/schema/OFX_Signup.xsd +114 -0
  66. data/schema/OFX_Signup_Message_Wrappers.xsd +222 -0
  67. data/schema/OFX_Signup_Messages.xsd +153 -0
  68. data/schema/OFX_Tax1098.xsd +123 -0
  69. data/schema/OFX_Tax1098_Message_Wrappers.xsd +52 -0
  70. data/schema/OFX_Tax1098_Messages.xsd +65 -0
  71. data/schema/OFX_Tax1099.xsd +371 -0
  72. data/schema/OFX_Tax1099_Message_Wrappers.xsd +52 -0
  73. data/schema/OFX_Tax1099_Messages.xsd +50 -0
  74. data/schema/OFX_TaxW2.xsd +204 -0
  75. data/schema/OFX_TaxW2_Message_Wrappers.xsd +52 -0
  76. data/schema/OFX_TaxW2_Messages.xsd +58 -0
  77. data/schema/OFX_TypeDefinitions.xsd +98 -0
  78. data/schema/OFX_WireTransfer.xsd +88 -0
  79. data/schema/OFX_WireTransfer_Message_Wrappers.xsd +101 -0
  80. data/schema/OFX_WireTransfer_Messages.xsd +116 -0
  81. data/test/sample/ofx/invalid.xml +34 -0
  82. data/test/sample/ofx/malformed.xml +38 -0
  83. data/test/sample/ofx/test_result.xml +101 -0
  84. data/test/sample/ofx/valid.xml +38 -0
  85. data/test/sample/organization/invalid_format.txt +1 -0
  86. data/test/sample/organization/malformed.txt +1 -0
  87. data/test/sample/organization/valid_one_account.txt +1 -0
  88. data/test/sample/organization/valid_two_accounts.txt +1 -0
  89. data/test/sample/transactions/corp-1234-bank-account-1-FR0000000000000000000000001.txt +60 -0
  90. data/test/sample/transactions/corp-1234-bank-account-2-FR0000000000000000000000002-p1.txt +28 -0
  91. data/test/sample/transactions/corp-1234-bank-account-2-FR0000000000000000000000002-p2.txt +28 -0
  92. data/test/sample/transactions/invalid_format.txt +1 -0
  93. data/test/sample/transactions/malformed.txt +1 -0
  94. data/test/sample/transactions/valid.txt +1 -0
  95. data/test/test_converter.rb +51 -0
  96. data/test/test_ofx_validator.rb +25 -0
  97. data/test/test_organization_validator.rb +28 -0
  98. data/test/test_transactions_listing_validator.rb +23 -0
  99. metadata +314 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad86a6cf7dbc7277bd7d15a567a5a9ee39c86d0e
4
+ data.tar.gz: 3cb06c7c0d1b392c4be475d0c715c524a6fbae9a
5
+ SHA512:
6
+ metadata.gz: f9b80fdf46d5f40538633a53f19692bee51dcacda9f6f1286b04f3bc2ff2cd85a1b2baf7e8b21e5a7acfeebb883fee3a1223b07f8da489c1c42697bd2ff93cd8
7
+ data.tar.gz: fc6b6a8fb4d00beeee867d25d53b685b3faa712d1bc4ea6a5b9fe5d49c9a0919b8940d202f2b6cbb80c7ab16acff01473b8cb9c7cef2a005bc9c934016494088
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: .rubocop_todo.yml
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,68 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-07-08 11:09:07 +0200 using RuboCop version 0.57.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: AllowInHeredoc.
12
+ Layout/TrailingWhitespace:
13
+ Exclude:
14
+ - 'lib/converter.rb'
15
+
16
+ # Offense count: 3
17
+ Metrics/AbcSize:
18
+ Max: 32
19
+
20
+ # Offense count: 1
21
+ Metrics/CyclomaticComplexity:
22
+ Max: 8
23
+
24
+ # Offense count: 2
25
+ # Configuration parameters: CountComments.
26
+ Metrics/MethodLength:
27
+ Max: 27
28
+
29
+ # Offense count: 1
30
+ Metrics/PerceivedComplexity:
31
+ Max: 8
32
+
33
+ # Offense count: 1
34
+ Style/Documentation:
35
+ Exclude:
36
+ - 'spec/**/*'
37
+ - 'test/**/*'
38
+ - 'lib/qonto_ofx.rb'
39
+
40
+ # Offense count: 1
41
+ # Cop supports --auto-correct.
42
+ Style/ExpandPathArguments:
43
+ Exclude:
44
+ - 'qonto_ofx.gemspec'
45
+
46
+ # Offense count: 1
47
+ # Cop supports --auto-correct.
48
+ Style/MultilineIfModifier:
49
+ Exclude:
50
+ - 'lib/api_gateway.rb'
51
+
52
+
53
+ # Offense count: 4
54
+ # Cop supports --auto-correct.
55
+ # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
56
+ # SupportedStyles: single_quotes, double_quotes
57
+ Style/StringLiterals:
58
+ Exclude:
59
+ - 'Gemfile'
60
+ - 'lib/organization_validator.rb'
61
+ - 'lib/qonto_ofx/version.rb'
62
+ - 'test/test_converter.rb'
63
+
64
+ # Offense count: 4
65
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
66
+ # URISchemes: http, https
67
+ Metrics/LineLength:
68
+ Max: 123
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in qonto_ofx.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ qonto_ofx (1.0.1)
5
+ htmlentities (~> 4.3)
6
+ json (~> 1.8)
7
+ json-schema (~> 2.5)
8
+ nokogiri (~> 1.6)
9
+ rest-client (~> 2.0)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ addressable (2.5.2)
15
+ public_suffix (>= 2.0.2, < 4.0)
16
+ diffy (3.2.1)
17
+ domain_name (0.5.20180417)
18
+ unf (>= 0.0.5, < 1.0.0)
19
+ htmlentities (4.3.4)
20
+ http-cookie (1.0.3)
21
+ domain_name (~> 0.5)
22
+ json (1.8.6)
23
+ json-schema (2.8.0)
24
+ addressable (>= 2.4)
25
+ metaclass (0.0.4)
26
+ mime-types (3.1)
27
+ mime-types-data (~> 3.2015)
28
+ mime-types-data (3.2016.0521)
29
+ mini_portile2 (2.3.0)
30
+ minitest (5.11.3)
31
+ mocha (1.5.0)
32
+ metaclass (~> 0.0.1)
33
+ netrc (0.11.0)
34
+ nokogiri (1.8.4)
35
+ mini_portile2 (~> 2.3.0)
36
+ public_suffix (3.0.2)
37
+ rake (10.5.0)
38
+ rest-client (2.0.2)
39
+ http-cookie (>= 1.0.2, < 2.0)
40
+ mime-types (>= 1.16, < 4.0)
41
+ netrc (~> 0.8)
42
+ rubygems-tasks (0.2.4)
43
+ unf (0.1.4)
44
+ unf_ext
45
+ unf_ext (0.0.7.5)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ bundler (~> 1.16)
52
+ diffy (~> 3.1)
53
+ minitest (~> 5.8)
54
+ mocha (~> 1.2)
55
+ qonto_ofx!
56
+ rake (~> 10.0)
57
+ rubygems-tasks (~> 0.2)
58
+
59
+ BUNDLED WITH
60
+ 1.16.0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Simon
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,34 @@
1
+ # QontoOfx
2
+
3
+ Export your Qonto account into an OFX 2 file.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem install qonto_ofx
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```
14
+ qonto_ofx -s YOUR_COMPANY_SLUG -t INTEGRATION_TOKEN
15
+ ```
16
+
17
+ ## Development
18
+
19
+ This is an early stage version built for my own accounting needs.
20
+ I plan to improve this gem as I switch to Qonto.
21
+ As of today, it generates a valid OFX 2 file with all transactions for all
22
+ accounts.
23
+
24
+ Roadmap :
25
+ - Make sure all fields hold correct values
26
+ - Add filtering on transactions dates, and accounts
27
+
28
+ ## Contributing
29
+
30
+ Bug reports and pull requests are welcome on GitHub at https://github.com/simon-watiau/qonto_ofx.
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rake/testtask'
2
+ require 'rubygems/tasks'
3
+
4
+ Gem::Tasks.new
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ end
9
+
10
+ desc 'Run tests'
11
+ task default: :test
data/bin/qonto_ofx ADDED
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ require 'bundler/setup'
3
+ require 'converter'
4
+ require 'optparse'
5
+
6
+ options = {}
7
+ OptionParser.new do |opts|
8
+ opts.banner = "Usage: qonto_ofx [OPTIONS]"
9
+
10
+ opts.on("-t", "--token TOKEN", "Qonto API token") do |token|
11
+ options[:token] = token
12
+ end
13
+
14
+ opts.on("-s", "--slug SLUG", "Qonto account slug") do |slug|
15
+ options[:slug] = slug
16
+ end
17
+
18
+ opts.on("-n", "--[no-]namespace", "Exclude namespace") do |ns|
19
+ options[:namespace] = ns
20
+ end
21
+ end.parse!
22
+
23
+ converter = QontoOfx::Converter.new(options[:slug], options[:token])
24
+ print converter.convert options[:namespace]
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
@@ -0,0 +1,47 @@
1
+ require 'json'
2
+ require 'json-schema'
3
+ require 'organization_validator'
4
+ require 'transactions_listing_validator'
5
+
6
+ module QontoOfx
7
+ # Call and verify responses for Qonto API
8
+ class ApiGateway
9
+ def initialize(slug, token)
10
+ @slug = slug
11
+ @token = token
12
+ @organization_validator = OrganizationValidator.new
13
+ @transactions_listing_validator = TransactionsListingValidator.new
14
+ end
15
+
16
+ def fetch_organization
17
+ response = RestClient.get(
18
+ "https://thirdparty.qonto.eu/v2/organizations/#{@slug}",
19
+ Authorization: "#{@slug}:#{@token}"
20
+ )
21
+ check_against_validator response, @organization_validator
22
+
23
+ JSON.parse(response.body)
24
+ end
25
+
26
+ def fetch_transactions(url)
27
+ response = RestClient.get(
28
+ url,
29
+ Authorization: "#{@slug}:#{@token}"
30
+ )
31
+
32
+ check_against_validator response, @transactions_listing_validator
33
+
34
+ JSON.parse(response.body)
35
+ end
36
+
37
+ def check_against_validator(response, validator)
38
+ if response.code != 200
39
+ raise "Qonto API call failed \
40
+ (status: #{response.code}): #{response.body}"
41
+ end
42
+
43
+ raise "response does not match schema: \
44
+ #{response.body}" unless validator.valid? response.body
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+ require 'json-schema'
3
+
4
+ module QontoOfx
5
+ # Base class for API response validation
6
+ class BaseValidator
7
+ def valid?(input)
8
+ return false unless JSON::Validator.validate(
9
+ @schema,
10
+ JSON.parse(input)
11
+ )
12
+ true
13
+ rescue JSON::ParserError
14
+ false
15
+ end
16
+ end
17
+ end
data/lib/converter.rb ADDED
@@ -0,0 +1,158 @@
1
+ require 'json'
2
+ require 'api_gateway'
3
+ require 'rest-client'
4
+ require 'nokogiri'
5
+ require 'ofx_validator'
6
+ require 'htmlentities'
7
+
8
+ module QontoOfx
9
+ # Convert a JSON transactions listing into an OFX hash
10
+ class Converter
11
+ def initialize(slug, token)
12
+ @gateway = ApiGateway.new slug, token
13
+ @ofx_validator = OfxValidator.new
14
+ end
15
+
16
+ # valid_ofx = false removes the namespaces
17
+ def convert(remove_ns = false)
18
+ organization = @gateway.fetch_organization['organization']
19
+
20
+ builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8')
21
+ builder[:ofx].OFX('xmlns:ofx' => 'http://ofx.net/types/2003/04') do |xml|
22
+ add_signonmsgsrsv1_block xml
23
+
24
+ xml.BANKMSGSRSV1 do
25
+ xml.parent.namespace = nil
26
+ organization['bank_accounts'].each do |bank_account|
27
+ xml.STMTTRNRS do
28
+ xml.TRNUID 1
29
+ add_status_block xml
30
+
31
+ xml.STMTRS do
32
+ xml.CURDEF 'EUR'
33
+ add_bankacctfrom_block xml, bank_account
34
+
35
+ xml.BANKTRANLIST do
36
+ process_transactions xml, bank_account
37
+ end
38
+
39
+ xml.LEDGERBAL do
40
+ xml.BALAMT bank_account['balance']
41
+ xml.DTASOF Time.now.strftime('%Y%m%d%H%M%S')
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ move_to_first_position(builder, '//DTEND')
50
+ move_to_first_position(builder, '//DTSTART')
51
+
52
+
53
+ result = builder.to_xml
54
+ raise 'generation failed (invalid OFX)' unless @ofx_validator.valid? result
55
+ result = result.gsub(
56
+ 'ofx:OFX',
57
+ 'OFX'
58
+ ).gsub(' xmlns:ofx="http://ofx.net/types/2003/04"', '') if remove_ns
59
+ result
60
+ end
61
+
62
+ def move_to_first_position(builder, path)
63
+ builder.doc.xpath(path).each do |el|
64
+ el.parent.children.first.before(el)
65
+ end
66
+
67
+ end
68
+
69
+ def add_bankacctfrom_block(xml, bank_account)
70
+ xml.BANKACCTFROM do
71
+ xml.BANKID '0000'
72
+ xml.ACCTID bank_account['iban'][-21..-1]
73
+ xml.ACCTTYPE 'CHECKING'
74
+ end
75
+ end
76
+
77
+ def add_status_block(xml, code = 0, severity = 'INFO')
78
+ xml.STATUS do
79
+ xml.CODE code
80
+ xml.SEVERITY severity
81
+ end
82
+ end
83
+
84
+ def add_signonmsgsrsv1_block(xml)
85
+ xml.SIGNONMSGSRSV1 do
86
+ xml.parent.namespace = nil
87
+ xml.SONRS do
88
+ add_status_block xml
89
+ xml.DTSERVER Time.now.strftime('%Y%m%d%H%M%S')
90
+ xml.LANGUAGE 'FRE'
91
+ end
92
+ end
93
+ end
94
+
95
+ def compute_dates_range(transaction, dtstart, dtend)
96
+ unless transaction['settled_at'].nil?
97
+ tmp_dtstart = Time.parse(transaction['emitted_at'])
98
+ dtstart = tmp_dtstart if dtstart.nil? || tmp_dtstart < dtstart
99
+
100
+ tmp_dtend = Time.parse(transaction['emitted_at'])
101
+ dtend = tmp_dtend if dtend.nil? || tmp_dtend > dtend
102
+ end
103
+ [dtstart, dtend]
104
+
105
+ end
106
+
107
+ def process_transactions(xml, account)
108
+ url = "https://thirdparty.qonto.eu/v2/transactions?slug=#{account['slug']}&iban=#{account['iban']}"
109
+
110
+ dtstart = dtend = nil
111
+ loop do
112
+ response = @gateway.fetch_transactions url
113
+ transactions = response['transactions']
114
+
115
+ transactions.each do |transaction|
116
+ dtstart, dtend = compute_dates_range transaction, dtstart, dtend
117
+ next if transaction['settled_at'].nil?
118
+ xml.STMTTRN do
119
+ xml.TRNTYPE operation_type(transaction)
120
+ xml.DTPOSTED Time.parse(
121
+ transaction['settled_at']
122
+ ).strftime('%Y%m%d%H%M%S')
123
+ xml.TRNAMT correct_value(transaction, 'amount')
124
+ xml.FITID transaction['transaction_id']
125
+ xml.NAME transaction['label'][0..31]
126
+
127
+ xml.MEMO transaction['note'] unless transaction['note'].nil? || transaction['note'].empty?
128
+ end
129
+ end
130
+
131
+ url = response['meta']['next_page']
132
+ break if url.nil?
133
+ end
134
+ xml.DTEND((dtend || Time.now).strftime('%Y%m%d%H%M%S'))
135
+ xml.DTSTART((dtstart || Time.now).strftime('%Y%m%d%H%M%S'))
136
+ nil
137
+ end
138
+
139
+ def correct_value(transaction, key)
140
+ if transaction['side'] === 'debit'
141
+ -transaction[key]
142
+ else
143
+ transaction[key]
144
+ end
145
+ end
146
+
147
+ def operation_type(transaction)
148
+ case transaction['operation_type']
149
+ when 'income'
150
+ 'XFER'
151
+ when 'card'
152
+ 'POS'
153
+ else
154
+ transaction['side'].upcase
155
+ end
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+ require 'api_gateway'
3
+ require 'rest-client'
4
+
5
+ module QontoOfx
6
+ # Validate an OFX document against the schema
7
+ class OfxValidator
8
+ def valid?(input)
9
+ path = File.join(File.dirname(__FILE__), "../schema/OFX2_Protocol.xsd")
10
+ schema = Nokogiri::XML::Schema(File.open(path))
11
+ document = Nokogiri::XML(input)
12
+ schema.validate(document).empty?
13
+ rescue => e
14
+ false
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+ require 'json-schema'
3
+ require 'base_validator'
4
+
5
+ module QontoOfx
6
+ # Validate an organization JSON from Qonto API
7
+ class OrganizationValidator < BaseValidator
8
+ def initialize
9
+ path = File.join( File.dirname(__FILE__), '../qonto_organization_schema.json' )
10
+ @schema = JSON.parse(
11
+ File.read(
12
+ path
13
+ )
14
+ )
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module QontoOfx
2
+ VERSION = "1.0.1".freeze
3
+ end
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+ require 'json-schema'
3
+ require 'base_validator'
4
+
5
+ module QontoOfx
6
+ # Validate a transaction listing JSON from Qonto API
7
+ class TransactionsListingValidator < BaseValidator
8
+ def initialize
9
+ path = File.join( File.dirname(__FILE__), '../qonto_transactions_schema.json' )
10
+ @schema = JSON.parse(
11
+ File.read(
12
+ path
13
+ )
14
+ )
15
+ end
16
+ end
17
+ end
data/qonto_ofx.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'qonto_ofx/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'qonto_ofx'
7
+ spec.version = QontoOfx::VERSION
8
+ spec.authors = ['Simon Watiau']
9
+ spec.email = ['watiau.simon@gmail.com']
10
+
11
+ spec.summary = 'Parse Qonto transations listing into an OFX file'
12
+ spec.homepage = 'https://github.com/simon-watiau/qonto_ofx'
13
+ spec.license = 'MIT'
14
+
15
+ spec.executables = 'qonto_ofx'
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.require_paths = ['lib']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.16'
21
+ spec.add_development_dependency 'minitest', '~> 5.8'
22
+ spec.add_development_dependency 'mocha', '~> 1.2'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rubygems-tasks', '~> 0.2'
25
+ spec.add_development_dependency 'diffy', '~> 3.1'
26
+
27
+ spec.add_dependency 'json', '~> 1.8'
28
+ spec.add_dependency 'json-schema', '~> 2.5'
29
+ spec.add_dependency 'nokogiri', '~> 1.6'
30
+ spec.add_dependency 'rest-client', '~> 2.0'
31
+ spec.add_dependency 'htmlentities', '~> 4.3'
32
+ end
@@ -0,0 +1,63 @@
1
+ {
2
+ "type":"object",
3
+ "required":[
4
+ "organization"
5
+ ],
6
+ "properties":{
7
+ "organization":{
8
+ "type":"object",
9
+ "required":[
10
+ "slug",
11
+ "bank_accounts"
12
+ ],
13
+ "properties":{
14
+ "slug":{
15
+ "type":"string"
16
+ },
17
+ "bank_accounts":{
18
+ "type":"array",
19
+ "items":{
20
+ "type":"object",
21
+ "required":[
22
+ "slug",
23
+ "iban",
24
+ "bic",
25
+ "currency",
26
+ "balance",
27
+ "balance_cents",
28
+ "authorized_balance",
29
+ "authorized_balance_cents"
30
+ ],
31
+ "properties":{
32
+ "slug":{
33
+ "type":"string"
34
+ },
35
+ "iban":{
36
+ "type":"string",
37
+ "pattern":"^[A-Z]{2}[0-9]{25}$"
38
+ },
39
+ "bic":{
40
+ "type":"string"
41
+ },
42
+ "currency":{
43
+ "type":"string"
44
+ },
45
+ "balance":{
46
+ "type":"number"
47
+ },
48
+ "balance_cents":{
49
+ "type":"integer"
50
+ },
51
+ "authorized_balance":{
52
+ "type":"number"
53
+ },
54
+ "authorized_balance_cents":{
55
+ "type":"integer"
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+ }
63
+ }