papierkram_api_client 0.5.1 → 0.6.0

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
  SHA256:
3
- metadata.gz: d18cd169b3ebac8813460278153135597fe133183c79cd3cb76c391fb38c4ccf
4
- data.tar.gz: fd469628a71656d656a94d16d280999609d43c7cd8c9aae84fb51b158d314a55
3
+ metadata.gz: 2c9a175ef578cfbf1c6b5f584bd3ceb46a6fc49e895c3eadacf23eb6e7e55af1
4
+ data.tar.gz: 5562d7d36a1f757b040be4552f10f594c6923ba176528dfd822a3e7ed89076d1
5
5
  SHA512:
6
- metadata.gz: 81291b155d2b005b9b58feed69e3305366f849479ca1d9235335c1e6a5837e7b61951a9a2d70e4ff99df681b5160a869096b912c5185cafd827fe39bb5a0349e
7
- data.tar.gz: abf08a1354016bb16f2602ddba297d6510cb1c3b3703c171c50d3c8314cc0390ab24d4f061cb3bfc32a7dd5924fcf1b1e68ec3d2a7882c50de5dc1df98c88d56
6
+ metadata.gz: 15e29b762bba407492648b92adbee09fa201ba6163e273ddc222aa3593a43625892c9740a03cfea49be49e1de41588a8af4d1c6eaab092a53fd0b4da7de9f51b
7
+ data.tar.gz: 3870632bd739dea34bf89d33e9fcb65e6c875a483923d0e77973e9d5b3adec74596ade614a595eb170fecc84012e472491243c9c9ae82c34333c6e75f3a733bb
data/.rubocop.yml CHANGED
@@ -1,4 +1,4 @@
1
- require:
1
+ plugins:
2
2
  - rubocop-minitest
3
3
  - rubocop-performance
4
4
  - rubocop-rake
data/CHANGELOG.md CHANGED
@@ -10,9 +10,11 @@ Schema for new entries:
10
10
 
11
11
  ---
12
12
 
13
- ## [next] - YYYY-MM-DD
13
+ ## [0.6.0] - 2026-05-26
14
14
 
15
- - [#<PR_NUMBER>](https://github.com/simonneutert/papierkram_api_client/pull/<PR_NUMBER>) Description. [@<username>](https://github.com/<username>)
15
+ - Bumps minimal ruby version to 3.3.0. [@simonneutert](https://github.com/simonneutert)
16
+ - DEPRECATION WARNING 🚨 This gem is no longer maintained.
17
+ - [#102](https://github.com/simonneutert/papierkram_api_client/pull/102) Removes deprecated Business Intelligence Module. [@simonneutert](https://github.com/simonneutert)
16
18
 
17
19
  ## [0.5.1] - 2025-03-04
18
20
 
data/Gemfile CHANGED
@@ -5,13 +5,13 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in papierkram_api_client.gemspec
6
6
  gemspec
7
7
 
8
- gem 'minitest', '~> 5.25'
8
+ gem 'minitest', '~> 6.0'
9
9
  gem 'minitest-vcr', '~> 1.4'
10
- gem 'pry', '~> 0.15.2'
11
- gem 'rake', '~> 13.2'
12
- gem 'rubocop', '~> 1.69', require: false
13
- gem 'rubocop-minitest', '~> 0.36.0', require: false
14
- gem 'rubocop-performance', '~> 1.23', require: false
15
- gem 'rubocop-rake', '~> 0.6.0', require: false
16
- gem 'vcr', '~> 6.3'
17
- gem 'webmock', '~> 3.24'
10
+ gem 'pry', '~> 0.16.0'
11
+ gem 'rake', '~> 13.4'
12
+ gem 'rubocop', '~> 1.75', require: false
13
+ gem 'rubocop-minitest', '~> 0.39.1', require: false
14
+ gem 'rubocop-performance', '~> 1.26', require: false
15
+ gem 'rubocop-rake', '~> 0.7.1', require: false
16
+ gem 'vcr', '~> 6.4'
17
+ gem 'webmock', '~> 3.26'
data/Gemfile.lock CHANGED
@@ -1,90 +1,102 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- papierkram_api_client (0.5.1)
4
+ papierkram_api_client (0.6.0)
5
5
  faraday (~> 2.7)
6
- faraday-multipart (= 1.1.0)
7
- httpx (>= 0.22.5, < 1.5.0)
6
+ faraday-multipart (= 1.2.0)
7
+ httpx (>= 0.22.5, < 1.8.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- addressable (2.8.7)
13
- public_suffix (>= 2.0.2, < 7.0)
14
- ast (2.4.2)
15
- base64 (0.2.0)
16
- bigdecimal (3.1.8)
12
+ addressable (2.9.0)
13
+ public_suffix (>= 2.0.2, < 8.0)
14
+ ast (2.4.3)
15
+ bigdecimal (4.1.2)
17
16
  coderay (1.1.3)
18
- crack (1.0.0)
17
+ crack (1.0.1)
19
18
  bigdecimal
20
19
  rexml
21
- faraday (2.12.2)
20
+ drb (2.2.3)
21
+ faraday (2.14.2)
22
22
  faraday-net_http (>= 2.0, < 3.5)
23
23
  json
24
24
  logger
25
- faraday-multipart (1.1.0)
25
+ faraday-multipart (1.2.0)
26
26
  multipart-post (~> 2.0)
27
- faraday-net_http (3.4.0)
28
- net-http (>= 0.5.0)
29
- hashdiff (1.1.1)
30
- http-2 (1.0.2)
31
- httpx (1.4.0)
32
- http-2 (>= 1.0.0)
33
- json (2.9.1)
34
- language_server-protocol (3.17.0.3)
35
- logger (1.6.4)
27
+ faraday-net_http (3.4.3)
28
+ net-http (~> 0.5)
29
+ hashdiff (1.2.1)
30
+ http-2 (1.1.3)
31
+ httpx (1.7.8)
32
+ http-2 (>= 1.1.3)
33
+ io-console (0.8.2)
34
+ json (2.19.5)
35
+ language_server-protocol (3.17.0.5)
36
+ lint_roller (1.1.0)
37
+ logger (1.7.0)
36
38
  method_source (1.1.0)
37
39
  minispec-metadata (2.0.0)
38
40
  minitest
39
- minitest (5.25.4)
41
+ minitest (6.0.6)
42
+ drb (~> 2.0)
43
+ prism (~> 1.5)
40
44
  minitest-vcr (1.4.0)
41
45
  minispec-metadata (~> 2.0)
42
46
  minitest (>= 4.7.5)
43
47
  vcr (>= 2.9)
44
48
  multipart-post (2.4.1)
45
- net-http (0.6.0)
46
- uri
47
- parallel (1.26.3)
48
- parser (3.3.6.0)
49
+ net-http (0.9.1)
50
+ uri (>= 0.11.1)
51
+ parallel (2.1.0)
52
+ parser (3.3.11.1)
49
53
  ast (~> 2.4.1)
50
54
  racc
51
- pry (0.15.2)
55
+ prism (1.9.0)
56
+ pry (0.16.0)
52
57
  coderay (~> 1.1)
53
58
  method_source (~> 1.0)
54
- public_suffix (6.0.1)
59
+ reline (>= 0.6.0)
60
+ public_suffix (7.0.5)
55
61
  racc (1.8.1)
56
62
  rainbow (3.1.1)
57
- rake (13.2.1)
58
- regexp_parser (2.9.3)
59
- rexml (3.3.9)
60
- rubocop (1.69.2)
63
+ rake (13.4.2)
64
+ regexp_parser (2.12.0)
65
+ reline (0.6.3)
66
+ io-console (~> 0.5)
67
+ rexml (3.4.4)
68
+ rubocop (1.86.2)
61
69
  json (~> 2.3)
62
- language_server-protocol (>= 3.17.0)
63
- parallel (~> 1.10)
70
+ language_server-protocol (~> 3.17.0.2)
71
+ lint_roller (~> 1.1.0)
72
+ parallel (>= 1.10)
64
73
  parser (>= 3.3.0.2)
65
74
  rainbow (>= 2.2.2, < 4.0)
66
75
  regexp_parser (>= 2.9.3, < 3.0)
67
- rubocop-ast (>= 1.36.2, < 2.0)
76
+ rubocop-ast (>= 1.49.0, < 2.0)
68
77
  ruby-progressbar (~> 1.7)
69
78
  unicode-display_width (>= 2.4.0, < 4.0)
70
- rubocop-ast (1.37.0)
71
- parser (>= 3.3.1.0)
72
- rubocop-minitest (0.36.0)
73
- rubocop (>= 1.61, < 2.0)
74
- rubocop-ast (>= 1.31.1, < 2.0)
75
- rubocop-performance (1.23.0)
76
- rubocop (>= 1.48.1, < 2.0)
77
- rubocop-ast (>= 1.31.1, < 2.0)
78
- rubocop-rake (0.6.0)
79
- rubocop (~> 1.0)
79
+ rubocop-ast (1.49.1)
80
+ parser (>= 3.3.7.2)
81
+ prism (~> 1.7)
82
+ rubocop-minitest (0.39.1)
83
+ lint_roller (~> 1.1)
84
+ rubocop (>= 1.75.0, < 2.0)
85
+ rubocop-ast (>= 1.38.0, < 2.0)
86
+ rubocop-performance (1.26.1)
87
+ lint_roller (~> 1.1)
88
+ rubocop (>= 1.75.0, < 2.0)
89
+ rubocop-ast (>= 1.47.1, < 2.0)
90
+ rubocop-rake (0.7.1)
91
+ lint_roller (~> 1.1)
92
+ rubocop (>= 1.72.1)
80
93
  ruby-progressbar (1.13.0)
81
- unicode-display_width (3.1.2)
82
- unicode-emoji (~> 4.0, >= 4.0.4)
83
- unicode-emoji (4.0.4)
84
- uri (1.0.3)
85
- vcr (6.3.1)
86
- base64
87
- webmock (3.24.0)
94
+ unicode-display_width (3.2.0)
95
+ unicode-emoji (~> 4.1)
96
+ unicode-emoji (4.2.0)
97
+ uri (1.1.1)
98
+ vcr (6.4.0)
99
+ webmock (3.26.2)
88
100
  addressable (>= 2.8.0)
89
101
  crack (>= 0.3.2)
90
102
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -95,17 +107,17 @@ PLATFORMS
95
107
  x86_64-linux
96
108
 
97
109
  DEPENDENCIES
98
- minitest (~> 5.25)
110
+ minitest (~> 6.0)
99
111
  minitest-vcr (~> 1.4)
100
112
  papierkram_api_client!
101
- pry (~> 0.15.2)
102
- rake (~> 13.2)
103
- rubocop (~> 1.69)
104
- rubocop-minitest (~> 0.36.0)
105
- rubocop-performance (~> 1.23)
106
- rubocop-rake (~> 0.6.0)
107
- vcr (~> 6.3)
108
- webmock (~> 3.24)
113
+ pry (~> 0.16.0)
114
+ rake (~> 13.4)
115
+ rubocop (~> 1.75)
116
+ rubocop-minitest (~> 0.39.1)
117
+ rubocop-performance (~> 1.26)
118
+ rubocop-rake (~> 0.7.1)
119
+ vcr (~> 6.4)
120
+ webmock (~> 3.26)
109
121
 
110
122
  BUNDLED WITH
111
123
  2.5.19
data/README.md CHANGED
@@ -1,3 +1,13 @@
1
+ # Deprecated / Unmaintained
2
+
3
+ This package is no longer maintained as of 2026-05-26.
4
+
5
+ Existing versions remain available on rubygems.org for compatibility, but no new features, bug fixes, or security fixes are planned.
6
+
7
+ Please migrate away, replace it, or fork it under a new package name.
8
+
9
+ ---
10
+
1
11
  # Papierkram API Client<!-- omit in toc -->
2
12
 
3
13
  [![Ruby](https://github.com/simonneutert/papierkram_api_client/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/simonneutert/papierkram_api_client/actions/workflows/main.yml)
@@ -149,10 +159,6 @@ Ziele:
149
159
  - [archiviere einen Zeiteintrag](#archiviere-einen-zeiteintrag)
150
160
  - [unarchiviere einen Zeiteintrag](#unarchiviere-einen-zeiteintrag)
151
161
  - [Verbleibendes Quota](#verbleibendes-quota)
152
- - [Business Intelligence](#business-intelligence)
153
- - [Business::Intelligence (BI) ExpenseByCategory (Ausgaben nach Kategorie)](#businessintelligence-bi-expensebycategory-ausgaben-nach-kategorie)
154
- - [alle Ausgaben eines Monats nach Kategorie](#alle-ausgaben-eines-monats-nach-kategorie)
155
- - [alle Ausgaben eines Monats nach Kategorie gefiltert nach Steuersatz](#alle-ausgaben-eines-monats-nach-kategorie-gefiltert-nach-steuersatz)
156
162
  - [Helpers](#helpers)
157
163
  - [Generiere ein PDF aus Response](#generiere-ein-pdf-aus-response)
158
164
  - [Development / Mitentwickeln](#development--mitentwickeln)
@@ -1146,91 +1152,6 @@ response = client.info.details
1146
1152
  quota = client.info.remaining_quota(response)
1147
1153
  ```
1148
1154
 
1149
- ## Business Intelligence
1150
-
1151
- > **DEPRECATED** Bitte verwende dieses Modul nicht mehr, es wird in Zukunft entfernt werden.
1152
-
1153
- Ich lasse diesen ersten Ausflug in Auswertungen erstmal hier im Gem. Aber sollte ich die Zeit finden und weitere KPIs wichtig finden, dann gehören die Auswertungen eigentlich in ein eigenes Package.
1154
-
1155
- TODO ergänzen wie man `SmartQueries` erstellt und verwendet.
1156
- TODO ergänzen wie man `SmartQueries` funktioneren.
1157
- TODO ergänzen wie die Rückgabewerte von `SmartQueries` gestaltet werden sollten.
1158
-
1159
- ### Business::Intelligence (BI) ExpenseByCategory (Ausgaben nach Kategorie)
1160
-
1161
- > **DEPRECATED** Bitte verwende dieses Modul nicht mehr, es wird in Zukunft entfernt werden.
1162
-
1163
- Der Endpunkt `/papierkram_api/v1/business_intelligence/expense_by_categories` liefert Informationen über die Ausgaben nach Kategorie. Die Informationen werden als `Hash` zurückgegeben.
1164
-
1165
- #### alle Ausgaben eines Monats nach Kategorie
1166
-
1167
- ```ruby
1168
- client = PapierkramApi::Client.new
1169
- expense_voucher_data_service = client.expense_vouchers.data_service(:for_month_in_year_service)
1170
- expense_vouchers_in_date_range = expense_voucher_data_service.for_month_in_year(year: 2020, month: 8)
1171
-
1172
- service = client.business_intelligence.expenses_by_category
1173
- result = service.call(expense_vouchers: expense_vouchers_in_date_range)
1174
- puts result
1175
- ```
1176
-
1177
- ```ruby
1178
- {"Betriebsbedarf"=>
1179
- {"amount"=>476.0,
1180
- "amount_by_creditor"=>{nil=>476.0},
1181
- "line_items"=>
1182
- [{"name"=>"2020-01-03",
1183
- "amount"=>119.0,
1184
- "category"=>"Betriebsbedarf",
1185
- "vat_rate"=>"19%",
1186
- "billing"=>nil,
1187
- "depreciation"=>nil,
1188
- "voucher_name"=>"B-00214 - 2020-08-01",
1189
- "voucher_id"=>641,
1190
- "creditor"=>nil},
1191
- {"name"=>"2020-01-03",
1192
- "amount"=>119.0,
1193
- "category"=>"Betriebsbedarf",
1194
- "vat_rate"=>"19%",
1195
- "billing"=>nil,
1196
- "depreciation"=>nil,
1197
- "voucher_name"=>"B-00215 - 2020-08-02",
1198
- "voucher_id"=>644,
1199
- "creditor"=>nil},
1200
- {"name"=>"2020-01-03",
1201
- "amount"=>119.0,
1202
- "category"=>"Betriebsbedarf",
1203
- "vat_rate"=>"19%",
1204
- "billing"=>nil,
1205
- "depreciation"=>nil,
1206
- "voucher_name"=>"B-00216 - 2020-08-03",
1207
- "voucher_id"=>647,
1208
- "creditor"=>nil},
1209
- {"name"=>"2020-01-03",
1210
- "amount"=>119.0,
1211
- "category"=>"Betriebsbedarf",
1212
- "vat_rate"=>"19%",
1213
- "billing"=>nil,
1214
- "depreciation"=>nil,
1215
- "voucher_name"=>"B-00217 - 2020-08-04",
1216
- "voucher_id"=>650,
1217
- "creditor"=>nil}]}}
1218
- ```
1219
-
1220
- #### alle Ausgaben eines Monats nach Kategorie gefiltert nach Steuersatz
1221
-
1222
- ```ruby
1223
- client = PapierkramApi::Client.new
1224
- expense_voucher_data_service = client.expense_vouchers.data_service(:for_month_in_year_service)
1225
- expense_vouchers_in_date_range = expense_voucher_data_service.for_month_in_year(year: 2020, month: 8)
1226
-
1227
- service = client.business_intelligence.expenses_by_category
1228
- result = service.call(expense_vouchers: expense_vouchers_in_date_range) do |line_items|
1229
- line_items.select { |v| v['vat_rate'] == '19%' }
1230
- end
1231
- puts result
1232
- ```
1233
-
1234
1155
  ## Helpers
1235
1156
 
1236
1157
  Es gibt einige Helper, die dir das Leben leichter machen.
@@ -10,6 +10,7 @@ module PapierkramApi
10
10
  :remaining_quota
11
11
 
12
12
  extend Forwardable
13
+
13
14
  def_delegators :@client, :get, :post, :put, :patch, :delete
14
15
 
15
16
  def initialize(subdomain = nil, api_key = nil)
@@ -32,11 +33,6 @@ module PapierkramApi
32
33
  end
33
34
  end
34
35
 
35
- def business_intelligence
36
- @business_intelligence ||=
37
- PapierkramApi::V1::BusinessIntelligence::Base.new
38
- end
39
-
40
36
  def banking_bank_connections
41
37
  @banking_bank_connections ||=
42
38
  PapierkramApi::V1::Endpoints::Banking::BankConnections.new(@client)
@@ -91,7 +91,7 @@ module PapierkramApi
91
91
  }.freeze
92
92
  SWAGGER_SAMPLE_KEYS_STRINGIFIED = SWAGGER_SAMPLE.keys.map(&:to_s).sort.freeze
93
93
 
94
- def validate!(expense_voucher)
94
+ def validate!(expense_voucher) # rubocop:disable Naming/PredicateMethod
95
95
  unless expense_voucher['type'] == 'expense_voucher' &&
96
96
  expense_voucher.keys.sort == SWAGGER_SAMPLE_KEYS_STRINGIFIED
97
97
  raise ArgumentError, 'expense_voucher does not match the expected format'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PapierkramApiClient
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.0'
5
5
  end
@@ -24,8 +24,5 @@ require_relative 'papierkram_api/v1/endpoints/info'
24
24
  require_relative 'papierkram_api/v1/endpoints/projects'
25
25
  require_relative 'papierkram_api/v1/endpoints/tracker/tasks'
26
26
  require_relative 'papierkram_api/v1/endpoints/tracker/time_entries'
27
- require_relative 'papierkram_api/v1/business_intelligence/base'
28
- require_relative 'papierkram_api/v1/business_intelligence/expenses_by_category'
29
- require_relative 'papierkram_api/v1/business_intelligence/smart_queries/expense_vouchers_for_month_in_year'
30
27
 
31
28
  require_relative 'papierkram_api/client'
data/mise.toml ADDED
File without changes
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papierkram_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Neutert
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-04 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: faraday
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - '='
31
31
  - !ruby/object:Gem::Version
32
- version: 1.1.0
32
+ version: 1.2.0
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 1.1.0
39
+ version: 1.2.0
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: httpx
42
42
  requirement: !ruby/object:Gem::Requirement
@@ -46,7 +46,7 @@ dependencies:
46
46
  version: 0.22.5
47
47
  - - "<"
48
48
  - !ruby/object:Gem::Version
49
- version: 1.5.0
49
+ version: 1.8.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
@@ -56,9 +56,9 @@ dependencies:
56
56
  version: 0.22.5
57
57
  - - "<"
58
58
  - !ruby/object:Gem::Version
59
- version: 1.5.0
60
- description: Papierkram API Client, um deine Buchhaltung auf das nächste Level zu
61
- bringen.
59
+ version: 1.8.0
60
+ description: 'DEPRECATED AND UNMAINTAINED: Papierkram API Client, um deine Buchhaltung
61
+ auf das nächste Level zu bringen.'
62
62
  email:
63
63
  - simonneutert@users.noreply.github.com
64
64
  executables: []
@@ -77,9 +77,6 @@ files:
77
77
  - Rakefile
78
78
  - UPGRADING.md
79
79
  - lib/papierkram_api/client.rb
80
- - lib/papierkram_api/v1/business_intelligence/base.rb
81
- - lib/papierkram_api/v1/business_intelligence/expenses_by_category.rb
82
- - lib/papierkram_api/v1/business_intelligence/smart_queries/expense_vouchers_for_month_in_year.rb
83
80
  - lib/papierkram_api/v1/endpoints/banking/bank_connections.rb
84
81
  - lib/papierkram_api/v1/endpoints/banking/transactions.rb
85
82
  - lib/papierkram_api/v1/endpoints/base.rb
@@ -100,6 +97,7 @@ files:
100
97
  - lib/papierkram_api_client.rb
101
98
  - lib/papierkram_api_client/version.rb
102
99
  - logo.svg
100
+ - mise.toml
103
101
  - pac.svg
104
102
  - sig/papierkram_api_client.rbs
105
103
  homepage: https://github.com/simonneutert/papierkram_api_client
@@ -117,14 +115,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
115
  requirements:
118
116
  - - ">="
119
117
  - !ruby/object:Gem::Version
120
- version: 3.0.0
118
+ version: 3.3.0
121
119
  required_rubygems_version: !ruby/object:Gem::Requirement
122
120
  requirements:
123
121
  - - ">="
124
122
  - !ruby/object:Gem::Version
125
123
  version: '0'
126
124
  requirements: []
127
- rubygems_version: 3.6.2
125
+ rubygems_version: 3.6.9
128
126
  specification_version: 4
129
- summary: Papierkram API Client
127
+ summary: 'DEPRECATED AND UNMAINTAINED: Papierkram API Client'
130
128
  test_files: []
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PapierkramApi
4
- module V1
5
- module BusinessIntelligence
6
- # Business Intelligence Base Class
7
- #
8
- # Business Intelligence is a set of services that can be used to gain
9
- # insights into the data stored in the system.
10
- #
11
- # Therefor you should pass data to the service and get back a result.
12
- #
13
- # IMPORTANT no calls to the API should be made in this class.
14
- # This is an intentional design decision! To seperate logic from the data source.
15
- #
16
- class Base
17
- def expenses_by_category
18
- warning = <<~MSG
19
- [DEPRECATION] `expenses_by_category` is deprecated. #{' '}
20
- It will be removed in a version after 0.4.0, most probably in 0.5.0.
21
-
22
- [DEPRECATION] Support for RUBY 2.7 will be dropped#{' '}
23
- in a version after 0.4.0, most probably in 0.5.0.
24
- MSG
25
- warn(warning)
26
-
27
- @expenses_by_category ||= PapierkramApi::V1::BusinessIntelligence::ExpensesByCategory.new
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,96 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PapierkramApi
4
- module V1
5
- module BusinessIntelligence
6
- # Business Intelligence for Expenses
7
- class ExpensesByCategory
8
- #
9
- # Calculate the expenses by category
10
- #
11
- # @param [Array<Hash>] expense_vouchers represents a list of expense vouchers in the format:
12
- #
13
- # @param [<Type>] &block <description>
14
- #
15
- # @return [<Type>] <description>
16
- #
17
- def call(expense_vouchers:, &block)
18
- return {} if expense_vouchers.is_a?(Array) && expense_vouchers.empty?
19
-
20
- validate_expense_vouchers!(expense_vouchers)
21
- return results(expense_vouchers, &block) if block
22
-
23
- results(expense_vouchers)
24
- end
25
-
26
- private
27
-
28
- def results(expense_vouchers)
29
- coll = prepare_voucher_data(expense_vouchers)
30
- coll = yield(coll) if block_given?
31
- line_items_grouped_by_category = coll.group_by { |v| v['category'] }
32
- sum_categories!(line_items_grouped_by_category)
33
- end
34
-
35
- def sum_categories!(line_items_grouped_by_category)
36
- lookup_table = {}
37
- line_items_grouped_by_category.each do |category_name, line_items|
38
- line_items_by_creditor_lot = {}
39
- line_items_by_creditor = line_items.group_by { |v| v['creditor'] }
40
- sum_up_creditor!(line_items_by_creditor, line_items_by_creditor_lot)
41
- build_result_lookup_table!(lookup_table, category_name, line_items, line_items_by_creditor_lot)
42
- end
43
- lookup_table
44
- end
45
-
46
- def sum_up_creditor!(line_items_by_creditor, line_items_by_creditor_lot)
47
- line_items_by_creditor.each do |category_name, line_items|
48
- line_items_by_creditor_lot[category_name] = line_items.reduce(0) do |sum, creditor|
49
- sum + creditor['amount']
50
- end
51
- end
52
- line_items_by_creditor_lot
53
- end
54
-
55
- def build_result_lookup_table!(lookup_table, category_name, line_items, line_items_by_creditor_lot)
56
- lookup_table[category_name] = {
57
- 'amount' => line_items.reduce(0) { |sum, line_item| sum + line_item['amount'] },
58
- 'amount_by_creditor' => line_items_by_creditor_lot,
59
- 'line_items' => line_items
60
- }
61
- end
62
-
63
- def prepare_voucher_data(vouchers)
64
- coll = []
65
- vouchers.flat_map do |voucher|
66
- voucher['line_items'].each do |line_item|
67
- res = line_item.merge(
68
- { 'voucher_name' => voucher['name'] },
69
- { 'voucher_id' => voucher['id'] },
70
- 'creditor' => voucher['creditor']
71
- )
72
- coll.push(res)
73
- end
74
- end
75
- coll
76
- end
77
-
78
- # TODO: move to a validator class forPapierkramApi::V1::Validators::ExpenseVouchers
79
- def validate_expense_vouchers!(expense_vouchers)
80
- raise ArgumentError, 'expense_vouchers must be an Array' unless expense_vouchers.is_a?(Array)
81
- raise ArgumentError, 'expense_vouchers must not be empty' if expense_vouchers.empty?
82
- raise ArgumentError, 'expense_vouchers must contain Hashes' unless expense_vouchers.all?(Hash)
83
-
84
- validator = PapierkramApi::V1::Validators::ExpenseVoucher.new
85
- expense_vouchers.all? do |voucher|
86
- validate_expense_voucher!(validator, voucher)
87
- end
88
- end
89
-
90
- def validate_expense_voucher!(validator, expense_voucher)
91
- validator.validate!(expense_voucher)
92
- end
93
- end
94
- end
95
- end
96
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module PapierkramApi
4
- module V1
5
- module BusinessIntelligence
6
- module SmartQueries
7
- # This class is responsible for all the API calls related to expense vouchers.
8
- class ExpenseVouchersForMonthInYear
9
- include PapierkramApi::V1::Helper::DateHelper
10
-
11
- def initialize(expense_voucher_api)
12
- @expense_voucher_api = expense_voucher_api
13
- end
14
-
15
- def for_month_in_year(year:, month:)
16
- @year = year
17
- @month = month
18
- @start_date = Date.new(@year, @month, 1)
19
- @end_date = Date.new(@year, @month + 1, 1) - 1
20
- collect_expense_vouchers
21
- end
22
-
23
- private
24
-
25
- def collect_expense_vouchers
26
- all_expense_vouchers_in_date_range.map do |voucher|
27
- @expense_voucher_api.find_by(id: voucher['id']).body
28
- end
29
- end
30
-
31
- def all_expense_vouchers_in_date_range
32
- page = 1
33
- res = expense_vouchers(page: page)
34
- vouchers = res.body['entries'].map { |v| v }
35
- while res.body['page'] != res.body['total_pages']
36
- res = expense_vouchers(page: page)
37
- res.body['entries'].each { |v| vouchers << v }
38
- end
39
- vouchers
40
- end
41
-
42
- def expense_vouchers(page: 1)
43
- @expense_voucher_api.all(
44
- page: page,
45
- document_date_range_start: build_date_string_for_api(@start_date),
46
- document_date_range_end: build_date_string_for_api(@end_date)
47
- )
48
- end
49
-
50
- def expense_voucher(id)
51
- @expense_voucher_api.find_by(id: id)
52
- end
53
- end
54
- end
55
- end
56
- end
57
- end