lunchmoney 0.10.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/publish_gem.yml +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +41 -4
- data/lib/lunchmoney/api.rb +34 -34
- data/lib/lunchmoney/calls/assets.rb +98 -0
- data/lib/lunchmoney/calls/base.rb +112 -0
- data/lib/lunchmoney/calls/budgets.rb +84 -0
- data/lib/lunchmoney/calls/categories.rb +196 -0
- data/lib/lunchmoney/calls/crypto.rb +50 -0
- data/lib/lunchmoney/calls/plaid_accounts.rb +40 -0
- data/lib/lunchmoney/calls/recurring_expenses.rb +29 -0
- data/lib/lunchmoney/calls/tags.rb +21 -0
- data/lib/lunchmoney/calls/transactions.rb +220 -0
- data/lib/lunchmoney/calls/users.rb +21 -0
- data/lib/lunchmoney/objects/asset.rb +91 -0
- data/lib/lunchmoney/objects/budget.rb +76 -0
- data/lib/lunchmoney/objects/category.rb +55 -0
- data/lib/lunchmoney/objects/child_category.rb +44 -0
- data/lib/lunchmoney/objects/child_transaction.rb +35 -0
- data/lib/lunchmoney/objects/config.rb +40 -0
- data/lib/lunchmoney/objects/crypto.rb +46 -0
- data/lib/lunchmoney/objects/crypto_base.rb +67 -0
- data/lib/lunchmoney/objects/data.rb +44 -0
- data/lib/lunchmoney/objects/object.rb +28 -0
- data/lib/lunchmoney/objects/plaid_account.rb +75 -0
- data/lib/lunchmoney/objects/recurring_expense.rb +68 -0
- data/lib/lunchmoney/objects/recurring_expense_base.rb +31 -0
- data/lib/lunchmoney/objects/split.rb +28 -0
- data/lib/lunchmoney/objects/tag.rb +24 -0
- data/lib/lunchmoney/objects/tag_base.rb +23 -0
- data/lib/lunchmoney/objects/transaction.rb +160 -0
- data/lib/lunchmoney/objects/transaction_base.rb +54 -0
- data/lib/lunchmoney/objects/transaction_modification_base.rb +32 -0
- data/lib/lunchmoney/objects/update_transaction.rb +47 -0
- data/lib/lunchmoney/objects/user.rb +38 -0
- data/lib/lunchmoney/version.rb +1 -1
- data/lunchmoney.gemspec +1 -0
- data/sorbet/rbi/gems/activesupport@7.1.3.rbi +122 -22
- metadata +33 -32
- data/lib/lunchmoney/api_call.rb +0 -109
- data/lib/lunchmoney/assets/asset.rb +0 -89
- data/lib/lunchmoney/assets/asset_calls.rb +0 -96
- data/lib/lunchmoney/budget/budget.rb +0 -74
- data/lib/lunchmoney/budget/budget_calls.rb +0 -82
- data/lib/lunchmoney/budget/config.rb +0 -38
- data/lib/lunchmoney/budget/data.rb +0 -42
- data/lib/lunchmoney/categories/category/category.rb +0 -52
- data/lib/lunchmoney/categories/category/child_category.rb +0 -42
- data/lib/lunchmoney/categories/category_calls.rb +0 -195
- data/lib/lunchmoney/crypto/crypto/crypto.rb +0 -43
- data/lib/lunchmoney/crypto/crypto/crypto_base.rb +0 -65
- data/lib/lunchmoney/crypto/crypto_calls.rb +0 -49
- data/lib/lunchmoney/data_object.rb +0 -25
- data/lib/lunchmoney/plaid_accounts/plaid_account.rb +0 -73
- data/lib/lunchmoney/plaid_accounts/plaid_account_calls.rb +0 -38
- data/lib/lunchmoney/recurring_expenses/recurring_expense/recurring_expense.rb +0 -65
- data/lib/lunchmoney/recurring_expenses/recurring_expense/recurring_expense_base.rb +0 -29
- data/lib/lunchmoney/recurring_expenses/recurring_expense_calls.rb +0 -28
- data/lib/lunchmoney/tags/tag/tag.rb +0 -20
- data/lib/lunchmoney/tags/tag/tag_base.rb +0 -21
- data/lib/lunchmoney/tags/tag_calls.rb +0 -20
- data/lib/lunchmoney/transactions/transaction/child_transaction.rb +0 -31
- data/lib/lunchmoney/transactions/transaction/split.rb +0 -24
- data/lib/lunchmoney/transactions/transaction/transaction.rb +0 -156
- data/lib/lunchmoney/transactions/transaction/transaction_base.rb +0 -52
- data/lib/lunchmoney/transactions/transaction/transaction_modification_base.rb +0 -30
- data/lib/lunchmoney/transactions/transaction/update_transaction.rb +0 -43
- data/lib/lunchmoney/transactions/transaction_calls.rb +0 -218
- data/lib/lunchmoney/user/user.rb +0 -36
- data/lib/lunchmoney/user/user_calls.rb +0 -19
@@ -0,0 +1,196 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative "../objects/category"
|
5
|
+
|
6
|
+
module LunchMoney
|
7
|
+
module Calls
|
8
|
+
# https://lunchmoney.dev/#categories
|
9
|
+
class Categories < LunchMoney::Calls::Base
|
10
|
+
# Valid query parameter formets for categories
|
11
|
+
VALID_FORMATS = T.let(
|
12
|
+
[
|
13
|
+
"flattened",
|
14
|
+
"nested",
|
15
|
+
],
|
16
|
+
T::Array[String],
|
17
|
+
)
|
18
|
+
|
19
|
+
sig do
|
20
|
+
params(
|
21
|
+
format: T.nilable(T.any(String, Symbol)),
|
22
|
+
).returns(T.any(T::Array[LunchMoney::Objects::Category], LunchMoney::Errors))
|
23
|
+
end
|
24
|
+
def categories(format: nil)
|
25
|
+
response = get("categories", query_params: categories_params(format:))
|
26
|
+
|
27
|
+
api_errors = errors(response)
|
28
|
+
return api_errors if api_errors.present?
|
29
|
+
|
30
|
+
response.body[:categories].map do |category|
|
31
|
+
category[:children]&.map! { |child_category| LunchMoney::Objects::Category.new(**child_category) }
|
32
|
+
|
33
|
+
LunchMoney::Objects::Category.new(**category)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
sig { params(category_id: Integer).returns(T.any(LunchMoney::Objects::Category, LunchMoney::Errors)) }
|
38
|
+
def category(category_id)
|
39
|
+
response = get("categories/#{category_id}")
|
40
|
+
|
41
|
+
api_errors = errors(response)
|
42
|
+
return api_errors if api_errors.present?
|
43
|
+
|
44
|
+
response.body[:children]&.map! { |child_category| LunchMoney::Objects::ChildCategory.new(**child_category) }
|
45
|
+
|
46
|
+
LunchMoney::Objects::Category.new(**response.body)
|
47
|
+
end
|
48
|
+
|
49
|
+
sig do
|
50
|
+
params(
|
51
|
+
name: String,
|
52
|
+
description: T.nilable(String),
|
53
|
+
is_income: T::Boolean,
|
54
|
+
exclude_from_budget: T::Boolean,
|
55
|
+
exclude_from_totals: T::Boolean,
|
56
|
+
archived: T::Boolean,
|
57
|
+
group_id: T.nilable(Integer),
|
58
|
+
).returns(T.any(T::Hash[Symbol, Integer], LunchMoney::Errors))
|
59
|
+
end
|
60
|
+
def create_category(name:, description: nil, is_income: false, exclude_from_budget: false,
|
61
|
+
exclude_from_totals: false, archived: false, group_id: nil)
|
62
|
+
params = clean_params({
|
63
|
+
name:,
|
64
|
+
description:,
|
65
|
+
is_income:,
|
66
|
+
exclude_from_budget:,
|
67
|
+
exclude_from_totals:,
|
68
|
+
archived:,
|
69
|
+
group_id:,
|
70
|
+
})
|
71
|
+
response = post("categories", params)
|
72
|
+
|
73
|
+
api_errors = errors(response)
|
74
|
+
return api_errors if api_errors.present?
|
75
|
+
|
76
|
+
response.body
|
77
|
+
end
|
78
|
+
|
79
|
+
sig do
|
80
|
+
params(
|
81
|
+
name: String,
|
82
|
+
description: T.nilable(String),
|
83
|
+
is_income: T::Boolean,
|
84
|
+
exclude_from_budget: T::Boolean,
|
85
|
+
exclude_from_totals: T::Boolean,
|
86
|
+
category_ids: T::Array[Integer],
|
87
|
+
new_categories: T::Array[String],
|
88
|
+
).returns(T.any(T::Hash[Symbol, Integer], LunchMoney::Errors))
|
89
|
+
end
|
90
|
+
def create_category_group(name:, description: nil, is_income: false, exclude_from_budget: false,
|
91
|
+
exclude_from_totals: false, category_ids: [], new_categories: [])
|
92
|
+
|
93
|
+
params = {
|
94
|
+
name:,
|
95
|
+
description:,
|
96
|
+
is_income:,
|
97
|
+
exclude_from_budget:,
|
98
|
+
exclude_from_totals:,
|
99
|
+
category_ids:,
|
100
|
+
new_categories:,
|
101
|
+
}
|
102
|
+
|
103
|
+
response = post("categories/group", params)
|
104
|
+
|
105
|
+
api_errors = errors(response)
|
106
|
+
return api_errors if api_errors.present?
|
107
|
+
|
108
|
+
response.body
|
109
|
+
end
|
110
|
+
|
111
|
+
sig do
|
112
|
+
params(
|
113
|
+
category_id: Integer,
|
114
|
+
name: T.nilable(String),
|
115
|
+
description: T.nilable(String),
|
116
|
+
is_income: T.nilable(T::Boolean),
|
117
|
+
exclude_from_budget: T.nilable(T::Boolean),
|
118
|
+
exclude_from_totals: T.nilable(T::Boolean),
|
119
|
+
archived: T.nilable(T::Boolean),
|
120
|
+
group_id: T.nilable(Integer),
|
121
|
+
).returns(T.any(T::Boolean, LunchMoney::Errors))
|
122
|
+
end
|
123
|
+
def update_category(category_id, name: nil, description: nil, is_income: nil, exclude_from_budget: nil,
|
124
|
+
exclude_from_totals: nil, archived: nil, group_id: nil)
|
125
|
+
|
126
|
+
params = clean_params({
|
127
|
+
name:,
|
128
|
+
description:,
|
129
|
+
is_income:,
|
130
|
+
exclude_from_budget:,
|
131
|
+
exclude_from_totals:,
|
132
|
+
archived:,
|
133
|
+
group_id:,
|
134
|
+
})
|
135
|
+
response = put("categories/#{category_id}", params)
|
136
|
+
|
137
|
+
api_errors = errors(response)
|
138
|
+
return api_errors if api_errors.present?
|
139
|
+
|
140
|
+
response.body
|
141
|
+
end
|
142
|
+
|
143
|
+
sig do
|
144
|
+
params(
|
145
|
+
group_id: Integer,
|
146
|
+
category_ids: T::Array[Integer],
|
147
|
+
new_categories: T::Array[String],
|
148
|
+
).returns(T.any(LunchMoney::Objects::Category, LunchMoney::Errors))
|
149
|
+
end
|
150
|
+
def add_to_category_group(group_id, category_ids: [], new_categories: [])
|
151
|
+
params = {
|
152
|
+
category_ids:,
|
153
|
+
new_categories:,
|
154
|
+
}
|
155
|
+
|
156
|
+
response = post("categories/group/#{group_id}/add", params)
|
157
|
+
|
158
|
+
api_errors = errors(response)
|
159
|
+
return api_errors if api_errors.present?
|
160
|
+
|
161
|
+
LunchMoney::Objects::Category.new(**response.body)
|
162
|
+
end
|
163
|
+
|
164
|
+
sig { params(category_id: Integer).returns(T.any(T::Boolean, LunchMoney::Errors)) }
|
165
|
+
def delete_category(category_id)
|
166
|
+
response = delete("categories/#{category_id}")
|
167
|
+
|
168
|
+
api_errors = errors(response)
|
169
|
+
return api_errors if api_errors.present?
|
170
|
+
|
171
|
+
response.body
|
172
|
+
end
|
173
|
+
|
174
|
+
sig { params(category_id: Integer).returns(T.any(T::Boolean, LunchMoney::Errors)) }
|
175
|
+
def force_delete_category(category_id)
|
176
|
+
response = delete("categories/#{category_id}/force")
|
177
|
+
|
178
|
+
api_errors = errors(response)
|
179
|
+
return api_errors if api_errors.present?
|
180
|
+
|
181
|
+
response.body
|
182
|
+
end
|
183
|
+
|
184
|
+
private
|
185
|
+
|
186
|
+
sig { params(format: T.nilable(T.any(String, Symbol))).returns(T.nilable(T::Hash[Symbol, String])) }
|
187
|
+
def categories_params(format:)
|
188
|
+
return unless format
|
189
|
+
|
190
|
+
raise(InvalidQueryParameter, "format must be either flattened or nested") if VALID_FORMATS.exclude?(format.to_s)
|
191
|
+
|
192
|
+
{ format: format.to_s }
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative "../objects/crypto"
|
5
|
+
|
6
|
+
module LunchMoney
|
7
|
+
module Calls
|
8
|
+
# https://lunchmoney.dev/#crypto
|
9
|
+
class Crypto < LunchMoney::Calls::Base
|
10
|
+
sig { returns(T.any(T::Array[LunchMoney::Objects::Crypto], LunchMoney::Errors)) }
|
11
|
+
def crypto
|
12
|
+
response = get("crypto")
|
13
|
+
|
14
|
+
api_errors = errors(response)
|
15
|
+
return api_errors if api_errors.present?
|
16
|
+
|
17
|
+
response.body[:crypto].map do |crypto|
|
18
|
+
LunchMoney::Objects::Crypto.new(**crypto)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
sig do
|
23
|
+
params(
|
24
|
+
crypto_id: Integer,
|
25
|
+
name: T.nilable(String),
|
26
|
+
display_name: T.nilable(String),
|
27
|
+
institution_name: T.nilable(String),
|
28
|
+
balance: T.nilable(String),
|
29
|
+
currency: T.nilable(String),
|
30
|
+
).returns(T.any(LunchMoney::Objects::CryptoBase, LunchMoney::Errors))
|
31
|
+
end
|
32
|
+
def update_crypto(crypto_id, name: nil, display_name: nil, institution_name: nil, balance: nil, currency: nil)
|
33
|
+
params = clean_params({
|
34
|
+
name:,
|
35
|
+
display_name:,
|
36
|
+
institution_name:,
|
37
|
+
balance:,
|
38
|
+
currency:,
|
39
|
+
})
|
40
|
+
|
41
|
+
response = put("crypto/manual/#{crypto_id}", params)
|
42
|
+
|
43
|
+
api_errors = errors(response)
|
44
|
+
return api_errors if api_errors.present?
|
45
|
+
|
46
|
+
LunchMoney::Objects::CryptoBase.new(**response.body)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative "../objects/plaid_account"
|
5
|
+
|
6
|
+
module LunchMoney
|
7
|
+
module Calls
|
8
|
+
# https://lunchmoney.dev/#plaid-accounts
|
9
|
+
class PlaidAccounts < LunchMoney::Calls::Base
|
10
|
+
sig { returns(T.any(T::Array[LunchMoney::Objects::PlaidAccount], LunchMoney::Errors)) }
|
11
|
+
def plaid_accounts
|
12
|
+
response = get("plaid_accounts")
|
13
|
+
|
14
|
+
api_errors = errors(response)
|
15
|
+
return api_errors if api_errors.present?
|
16
|
+
|
17
|
+
response.body[:plaid_accounts].map do |plaid_account|
|
18
|
+
LunchMoney::Objects::PlaidAccount.new(**plaid_account)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
sig do
|
23
|
+
params(
|
24
|
+
start_date: T.nilable(String),
|
25
|
+
end_date: T.nilable(String),
|
26
|
+
plaid_account_id: T.nilable(Integer),
|
27
|
+
).returns(T.any(T::Boolean, LunchMoney::Errors))
|
28
|
+
end
|
29
|
+
def plaid_accounts_fetch(start_date: nil, end_date: nil, plaid_account_id: nil)
|
30
|
+
params = clean_params({ start_date:, end_date:, plaid_account_id: })
|
31
|
+
response = post("plaid_accounts/fetch", params)
|
32
|
+
|
33
|
+
api_errors = errors(response)
|
34
|
+
return api_errors if api_errors.present?
|
35
|
+
|
36
|
+
response.body
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative "../objects/recurring_expense"
|
5
|
+
|
6
|
+
module LunchMoney
|
7
|
+
module Calls
|
8
|
+
# https://lunchmoney.dev/#recurring-expenses
|
9
|
+
class RecurringExpenses < LunchMoney::Calls::Base
|
10
|
+
sig do
|
11
|
+
params(
|
12
|
+
start_date: T.nilable(String),
|
13
|
+
end_date: T.nilable(String),
|
14
|
+
).returns(T.any(T::Array[LunchMoney::Objects::RecurringExpense], LunchMoney::Errors))
|
15
|
+
end
|
16
|
+
def recurring_expenses(start_date: nil, end_date: nil)
|
17
|
+
params = clean_params({ start_date:, end_date: })
|
18
|
+
response = get("recurring_expenses", query_params: params)
|
19
|
+
|
20
|
+
api_errors = errors(response)
|
21
|
+
return api_errors if api_errors.present?
|
22
|
+
|
23
|
+
response.body[:recurring_expenses].map do |recurring_expense|
|
24
|
+
LunchMoney::Objects::RecurringExpense.new(**recurring_expense)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative "../objects/tag"
|
5
|
+
|
6
|
+
module LunchMoney
|
7
|
+
module Calls
|
8
|
+
# https://lunchmoney.dev/#tags
|
9
|
+
class Tags < LunchMoney::Calls::Base
|
10
|
+
sig { returns(T.any(T::Array[LunchMoney::Objects::Tag], LunchMoney::Errors)) }
|
11
|
+
def tags
|
12
|
+
response = get("tags")
|
13
|
+
|
14
|
+
api_errors = errors(response)
|
15
|
+
return api_errors if api_errors.present?
|
16
|
+
|
17
|
+
response.body.map { |tag| LunchMoney::Objects::Tag.new(**tag) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative "../objects/child_transaction"
|
5
|
+
require_relative "../objects/transaction"
|
6
|
+
require_relative "../objects/split"
|
7
|
+
require_relative "../objects/update_transaction"
|
8
|
+
|
9
|
+
module LunchMoney
|
10
|
+
module Calls
|
11
|
+
# https://lunchmoney.dev/#transactions
|
12
|
+
class Transactions < LunchMoney::Calls::Base
|
13
|
+
sig do
|
14
|
+
params(
|
15
|
+
tag_id: T.nilable(Integer),
|
16
|
+
recurring_id: T.nilable(Integer),
|
17
|
+
plaid_account_id: T.nilable(Integer),
|
18
|
+
category_id: T.nilable(Integer),
|
19
|
+
asset_id: T.nilable(Integer),
|
20
|
+
is_group: T.nilable(T::Boolean),
|
21
|
+
status: T.nilable(String),
|
22
|
+
start_date: T.nilable(String),
|
23
|
+
end_date: T.nilable(String),
|
24
|
+
debit_as_negative: T.nilable(T::Boolean),
|
25
|
+
pending: T.nilable(T::Boolean),
|
26
|
+
offset: T.nilable(Integer),
|
27
|
+
limit: T.nilable(Integer),
|
28
|
+
).returns(T.any(T::Array[LunchMoney::Objects::Transaction], LunchMoney::Errors))
|
29
|
+
end
|
30
|
+
def transactions(
|
31
|
+
tag_id: nil,
|
32
|
+
recurring_id: nil,
|
33
|
+
plaid_account_id: nil,
|
34
|
+
category_id: nil,
|
35
|
+
asset_id: nil,
|
36
|
+
is_group: nil,
|
37
|
+
status: nil,
|
38
|
+
start_date: nil,
|
39
|
+
end_date: nil,
|
40
|
+
debit_as_negative: nil,
|
41
|
+
pending: nil,
|
42
|
+
offset: nil,
|
43
|
+
limit: nil
|
44
|
+
)
|
45
|
+
|
46
|
+
params = clean_params({
|
47
|
+
tag_id:,
|
48
|
+
recurring_id:,
|
49
|
+
plaid_account_id:,
|
50
|
+
category_id:,
|
51
|
+
asset_id:,
|
52
|
+
is_group:,
|
53
|
+
status:,
|
54
|
+
start_date:,
|
55
|
+
end_date:,
|
56
|
+
debit_as_negative:,
|
57
|
+
pending:,
|
58
|
+
offset:,
|
59
|
+
limit:,
|
60
|
+
})
|
61
|
+
response = get("transactions", query_params: params)
|
62
|
+
|
63
|
+
api_errors = errors(response)
|
64
|
+
return api_errors if api_errors.present?
|
65
|
+
|
66
|
+
response.body[:transactions].map do |transaction|
|
67
|
+
transaction[:tags].map! { |tag| LunchMoney::Objects::TagBase.new(**tag) }
|
68
|
+
|
69
|
+
transaction[:children]&.map! do |child_transaction|
|
70
|
+
LunchMoney::Objects::ChildTransaction.new(**child_transaction)
|
71
|
+
end
|
72
|
+
|
73
|
+
LunchMoney::Objects::Transaction.new(**transaction)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
sig do
|
78
|
+
params(
|
79
|
+
transaction_id: Integer,
|
80
|
+
debit_as_negative: T.nilable(T::Boolean),
|
81
|
+
).returns(T.any(LunchMoney::Objects::Transaction, LunchMoney::Errors))
|
82
|
+
end
|
83
|
+
def transaction(transaction_id, debit_as_negative: nil)
|
84
|
+
params = clean_params({ debit_as_negative: })
|
85
|
+
response = get("transactions/#{transaction_id}", query_params: params)
|
86
|
+
|
87
|
+
api_errors = errors(response)
|
88
|
+
return api_errors if api_errors.present?
|
89
|
+
|
90
|
+
LunchMoney::Objects::Transaction.new(**response.body)
|
91
|
+
end
|
92
|
+
|
93
|
+
sig do
|
94
|
+
params(
|
95
|
+
transactions: T::Array[LunchMoney::Objects::UpdateTransaction],
|
96
|
+
apply_rules: T.nilable(T::Boolean),
|
97
|
+
skip_duplicates: T.nilable(T::Boolean),
|
98
|
+
check_for_recurring: T.nilable(T::Boolean),
|
99
|
+
debit_as_negative: T.nilable(T::Boolean),
|
100
|
+
skip_balance_update: T.nilable(T::Boolean),
|
101
|
+
).returns(T.any(T::Hash[Symbol, T::Array[Integer]], LunchMoney::Errors))
|
102
|
+
end
|
103
|
+
def insert_transactions(transactions, apply_rules: nil, skip_duplicates: nil,
|
104
|
+
check_for_recurring: nil, debit_as_negative: nil, skip_balance_update: nil)
|
105
|
+
params = clean_params({
|
106
|
+
transactions: transactions.map(&:serialize),
|
107
|
+
apply_rules:,
|
108
|
+
skip_duplicates:,
|
109
|
+
check_for_recurring:,
|
110
|
+
debit_as_negative:,
|
111
|
+
skip_balance_update:,
|
112
|
+
})
|
113
|
+
response = post("transactions", params)
|
114
|
+
|
115
|
+
api_errors = errors(response)
|
116
|
+
return api_errors if api_errors.present?
|
117
|
+
|
118
|
+
response.body
|
119
|
+
end
|
120
|
+
|
121
|
+
sig do
|
122
|
+
params(
|
123
|
+
transaction_id: Integer,
|
124
|
+
transaction: T.nilable(LunchMoney::Objects::UpdateTransaction),
|
125
|
+
split: T.nilable(T::Array[LunchMoney::Objects::Split]),
|
126
|
+
debit_as_negative: T.nilable(T::Boolean),
|
127
|
+
skip_balance_update: T.nilable(T::Boolean),
|
128
|
+
).returns(T.any({ updated: T::Boolean, split: T.nilable(T::Array[Integer]) }, LunchMoney::Errors))
|
129
|
+
end
|
130
|
+
def update_transaction(transaction_id, transaction: nil, split: nil,
|
131
|
+
debit_as_negative: nil, skip_balance_update: nil)
|
132
|
+
raise(
|
133
|
+
LunchMoney::MissingArgument,
|
134
|
+
"Either a transaction or split must be provided",
|
135
|
+
) if transaction.nil? && split.nil?
|
136
|
+
|
137
|
+
params = clean_params({
|
138
|
+
transaction: transaction&.serialize,
|
139
|
+
split: split&.map!(&:serialize),
|
140
|
+
debit_as_negative:,
|
141
|
+
skip_balance_update:,
|
142
|
+
})
|
143
|
+
response = put("transactions/#{transaction_id}", params)
|
144
|
+
|
145
|
+
api_errors = errors(response)
|
146
|
+
return api_errors if api_errors.present?
|
147
|
+
|
148
|
+
response.body
|
149
|
+
end
|
150
|
+
|
151
|
+
sig do
|
152
|
+
params(
|
153
|
+
parent_ids: T::Array[Integer],
|
154
|
+
remove_parents: T.nilable(T::Boolean),
|
155
|
+
).returns(T.any(T::Array[Integer], LunchMoney::Errors))
|
156
|
+
end
|
157
|
+
def unsplit_transaction(parent_ids, remove_parents: false)
|
158
|
+
params = { parent_ids:, remove_parents: }
|
159
|
+
response = post("transactions/unsplit", params)
|
160
|
+
|
161
|
+
api_errors = errors(response)
|
162
|
+
return api_errors if api_errors.present?
|
163
|
+
|
164
|
+
response.body
|
165
|
+
end
|
166
|
+
|
167
|
+
sig { params(transaction_id: Integer).returns(T.any(LunchMoney::Objects::Transaction, LunchMoney::Errors)) }
|
168
|
+
def transaction_group(transaction_id)
|
169
|
+
response = get("transactions/group", query_params: { transaction_id: })
|
170
|
+
|
171
|
+
api_errors = errors(response)
|
172
|
+
return api_errors if api_errors.present?
|
173
|
+
|
174
|
+
LunchMoney::Objects::Transaction.new(**response.body)
|
175
|
+
end
|
176
|
+
|
177
|
+
sig do
|
178
|
+
params(
|
179
|
+
date: String,
|
180
|
+
payee: String,
|
181
|
+
transactions: T::Array[T.any(Integer, String)],
|
182
|
+
category_id: T.nilable(Integer),
|
183
|
+
notes: T.nilable(String),
|
184
|
+
tags: T.nilable(T::Array[T.any(Integer, String)]),
|
185
|
+
).returns(T.any(Integer, LunchMoney::Errors))
|
186
|
+
end
|
187
|
+
def create_transaction_group(date:, payee:, transactions:, category_id: nil, notes: nil, tags: nil)
|
188
|
+
params = clean_params({
|
189
|
+
date:,
|
190
|
+
payee:,
|
191
|
+
transactions:,
|
192
|
+
category_id:,
|
193
|
+
notes:,
|
194
|
+
tags:,
|
195
|
+
})
|
196
|
+
response = post("transactions/group", params)
|
197
|
+
|
198
|
+
api_errors = errors(response)
|
199
|
+
return api_errors if api_errors.present?
|
200
|
+
|
201
|
+
response.body
|
202
|
+
end
|
203
|
+
|
204
|
+
sig do
|
205
|
+
params(transaction_id: T.any(
|
206
|
+
String,
|
207
|
+
Integer,
|
208
|
+
)).returns(T.any(T::Hash[Symbol, T::Array[Integer]], LunchMoney::Errors))
|
209
|
+
end
|
210
|
+
def delete_transaction_group(transaction_id)
|
211
|
+
response = delete("transactions/group/#{transaction_id}")
|
212
|
+
|
213
|
+
api_errors = errors(response)
|
214
|
+
return api_errors if api_errors.present?
|
215
|
+
|
216
|
+
response.body
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative "../objects/user"
|
5
|
+
|
6
|
+
module LunchMoney
|
7
|
+
module Calls
|
8
|
+
# https://lunchmoney.dev/#user
|
9
|
+
class Users < LunchMoney::Calls::Base
|
10
|
+
sig { returns(T.any(LunchMoney::Objects::User, LunchMoney::Errors)) }
|
11
|
+
def me
|
12
|
+
response = get("me")
|
13
|
+
|
14
|
+
api_errors = errors(response)
|
15
|
+
return api_errors if api_errors.present?
|
16
|
+
|
17
|
+
LunchMoney::Objects::User.new(**response.body)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# typed: strict
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module LunchMoney
|
5
|
+
module Objects
|
6
|
+
# https://lunchmoney.dev/#assets-object
|
7
|
+
class Asset < LunchMoney::Objects::Object
|
8
|
+
include LunchMoney::Validators
|
9
|
+
|
10
|
+
sig { returns(Integer) }
|
11
|
+
attr_accessor :id
|
12
|
+
|
13
|
+
sig { returns(String) }
|
14
|
+
attr_reader :type_name, :balance_as_of, :created_at
|
15
|
+
|
16
|
+
sig { returns(String) }
|
17
|
+
attr_accessor :name, :balance, :currency
|
18
|
+
|
19
|
+
sig { returns(T.nilable(String)) }
|
20
|
+
attr_accessor :display_name, :closed_on, :institution_name, :subtype_name
|
21
|
+
|
22
|
+
sig { returns(T::Boolean) }
|
23
|
+
attr_accessor :exclude_transactions
|
24
|
+
|
25
|
+
# Valid asset type names
|
26
|
+
VALID_TYPE_NAMES = T.let(
|
27
|
+
[
|
28
|
+
"cash",
|
29
|
+
"credit",
|
30
|
+
"investment",
|
31
|
+
"real estate",
|
32
|
+
"loan",
|
33
|
+
"vehicle",
|
34
|
+
"cryptocurrency",
|
35
|
+
"employee compensation",
|
36
|
+
"other liability",
|
37
|
+
"other asset",
|
38
|
+
],
|
39
|
+
T::Array[String],
|
40
|
+
)
|
41
|
+
|
42
|
+
sig do
|
43
|
+
params(
|
44
|
+
created_at: String,
|
45
|
+
type_name: String,
|
46
|
+
name: String,
|
47
|
+
balance: String,
|
48
|
+
balance_as_of: String,
|
49
|
+
currency: String,
|
50
|
+
exclude_transactions: T::Boolean,
|
51
|
+
id: Integer,
|
52
|
+
subtype_name: T.nilable(String),
|
53
|
+
display_name: T.nilable(String),
|
54
|
+
closed_on: T.nilable(String),
|
55
|
+
institution_name: T.nilable(String),
|
56
|
+
).void
|
57
|
+
end
|
58
|
+
def initialize(created_at:, type_name:, name:, balance:, balance_as_of:, currency:, exclude_transactions:, id:,
|
59
|
+
subtype_name: nil, display_name: nil, closed_on: nil, institution_name: nil)
|
60
|
+
super()
|
61
|
+
@created_at = T.let(validate_iso8601!(created_at), String)
|
62
|
+
@type_name = T.let(validate_one_of!(type_name, VALID_TYPE_NAMES), String)
|
63
|
+
@name = name
|
64
|
+
@balance = balance
|
65
|
+
@balance_as_of = T.let(validate_iso8601!(balance_as_of), String)
|
66
|
+
@currency = currency
|
67
|
+
@exclude_transactions = exclude_transactions
|
68
|
+
@id = id
|
69
|
+
@subtype_name = subtype_name
|
70
|
+
@display_name = display_name
|
71
|
+
@closed_on = closed_on
|
72
|
+
@institution_name = institution_name
|
73
|
+
end
|
74
|
+
|
75
|
+
sig { params(name: String).void }
|
76
|
+
def type_name=(name)
|
77
|
+
@type_name = validate_one_of!(name, VALID_TYPE_NAMES)
|
78
|
+
end
|
79
|
+
|
80
|
+
sig { params(time: String).void }
|
81
|
+
def balance_as_of=(time)
|
82
|
+
@balance_as_of = validate_iso8601!(time)
|
83
|
+
end
|
84
|
+
|
85
|
+
sig { params(time: String).void }
|
86
|
+
def created_at=(time)
|
87
|
+
@created_at = validate_iso8601!(time)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|