lunchmoney 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/publish_gem.yml +1 -0
  3. data/Gemfile.lock +1 -1
  4. data/lib/lunchmoney/api.rb +34 -34
  5. data/lib/lunchmoney/calls/assets.rb +98 -0
  6. data/lib/lunchmoney/calls/base.rb +112 -0
  7. data/lib/lunchmoney/calls/budgets.rb +84 -0
  8. data/lib/lunchmoney/calls/categories.rb +196 -0
  9. data/lib/lunchmoney/calls/crypto.rb +50 -0
  10. data/lib/lunchmoney/calls/plaid_accounts.rb +40 -0
  11. data/lib/lunchmoney/calls/recurring_expenses.rb +29 -0
  12. data/lib/lunchmoney/calls/tags.rb +21 -0
  13. data/lib/lunchmoney/calls/transactions.rb +220 -0
  14. data/lib/lunchmoney/calls/users.rb +21 -0
  15. data/lib/lunchmoney/objects/asset.rb +91 -0
  16. data/lib/lunchmoney/objects/budget.rb +76 -0
  17. data/lib/lunchmoney/objects/category.rb +55 -0
  18. data/lib/lunchmoney/objects/child_category.rb +44 -0
  19. data/lib/lunchmoney/objects/child_transaction.rb +35 -0
  20. data/lib/lunchmoney/objects/config.rb +40 -0
  21. data/lib/lunchmoney/objects/crypto.rb +46 -0
  22. data/lib/lunchmoney/objects/crypto_base.rb +67 -0
  23. data/lib/lunchmoney/objects/data.rb +44 -0
  24. data/lib/lunchmoney/objects/object.rb +28 -0
  25. data/lib/lunchmoney/objects/plaid_account.rb +75 -0
  26. data/lib/lunchmoney/objects/recurring_expense.rb +68 -0
  27. data/lib/lunchmoney/objects/recurring_expense_base.rb +31 -0
  28. data/lib/lunchmoney/objects/split.rb +28 -0
  29. data/lib/lunchmoney/objects/tag.rb +24 -0
  30. data/lib/lunchmoney/objects/tag_base.rb +23 -0
  31. data/lib/lunchmoney/objects/transaction.rb +160 -0
  32. data/lib/lunchmoney/objects/transaction_base.rb +54 -0
  33. data/lib/lunchmoney/objects/transaction_modification_base.rb +32 -0
  34. data/lib/lunchmoney/objects/update_transaction.rb +47 -0
  35. data/lib/lunchmoney/objects/user.rb +38 -0
  36. data/lib/lunchmoney/version.rb +1 -1
  37. metadata +32 -32
  38. data/lib/lunchmoney/api_call.rb +0 -109
  39. data/lib/lunchmoney/assets/asset.rb +0 -89
  40. data/lib/lunchmoney/assets/asset_calls.rb +0 -96
  41. data/lib/lunchmoney/budget/budget.rb +0 -74
  42. data/lib/lunchmoney/budget/budget_calls.rb +0 -82
  43. data/lib/lunchmoney/budget/config.rb +0 -38
  44. data/lib/lunchmoney/budget/data.rb +0 -42
  45. data/lib/lunchmoney/categories/category/category.rb +0 -52
  46. data/lib/lunchmoney/categories/category/child_category.rb +0 -42
  47. data/lib/lunchmoney/categories/category_calls.rb +0 -195
  48. data/lib/lunchmoney/crypto/crypto/crypto.rb +0 -43
  49. data/lib/lunchmoney/crypto/crypto/crypto_base.rb +0 -65
  50. data/lib/lunchmoney/crypto/crypto_calls.rb +0 -49
  51. data/lib/lunchmoney/data_object.rb +0 -25
  52. data/lib/lunchmoney/plaid_accounts/plaid_account.rb +0 -73
  53. data/lib/lunchmoney/plaid_accounts/plaid_account_calls.rb +0 -38
  54. data/lib/lunchmoney/recurring_expenses/recurring_expense/recurring_expense.rb +0 -65
  55. data/lib/lunchmoney/recurring_expenses/recurring_expense/recurring_expense_base.rb +0 -29
  56. data/lib/lunchmoney/recurring_expenses/recurring_expense_calls.rb +0 -28
  57. data/lib/lunchmoney/tags/tag/tag.rb +0 -20
  58. data/lib/lunchmoney/tags/tag/tag_base.rb +0 -21
  59. data/lib/lunchmoney/tags/tag_calls.rb +0 -20
  60. data/lib/lunchmoney/transactions/transaction/child_transaction.rb +0 -31
  61. data/lib/lunchmoney/transactions/transaction/split.rb +0 -24
  62. data/lib/lunchmoney/transactions/transaction/transaction.rb +0 -156
  63. data/lib/lunchmoney/transactions/transaction/transaction_base.rb +0 -52
  64. data/lib/lunchmoney/transactions/transaction/transaction_modification_base.rb +0 -30
  65. data/lib/lunchmoney/transactions/transaction/update_transaction.rb +0 -43
  66. data/lib/lunchmoney/transactions/transaction_calls.rb +0 -218
  67. data/lib/lunchmoney/user/user.rb +0 -36
  68. data/lib/lunchmoney/user/user_calls.rb +0 -19
@@ -1,218 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require_relative "transaction/transaction_base"
5
- require_relative "transaction/child_transaction"
6
- require_relative "transaction/transaction"
7
- require_relative "transaction/transaction_modification_base"
8
- require_relative "transaction/split"
9
- require_relative "transaction/update_transaction"
10
-
11
- module LunchMoney
12
- # https://lunchmoney.dev/#transactions
13
- class TransactionCalls < ApiCall
14
- sig do
15
- params(
16
- tag_id: T.nilable(Integer),
17
- recurring_id: T.nilable(Integer),
18
- plaid_account_id: T.nilable(Integer),
19
- category_id: T.nilable(Integer),
20
- asset_id: T.nilable(Integer),
21
- is_group: T.nilable(T::Boolean),
22
- status: T.nilable(String),
23
- start_date: T.nilable(String),
24
- end_date: T.nilable(String),
25
- debit_as_negative: T.nilable(T::Boolean),
26
- pending: T.nilable(T::Boolean),
27
- offset: T.nilable(Integer),
28
- limit: T.nilable(Integer),
29
- ).returns(T.any(T::Array[LunchMoney::Transaction], LunchMoney::Errors))
30
- end
31
- def transactions(
32
- tag_id: nil,
33
- recurring_id: nil,
34
- plaid_account_id: nil,
35
- category_id: nil,
36
- asset_id: nil,
37
- is_group: nil,
38
- status: nil,
39
- start_date: nil,
40
- end_date: nil,
41
- debit_as_negative: nil,
42
- pending: nil,
43
- offset: nil,
44
- limit: nil
45
- )
46
-
47
- params = clean_params({
48
- tag_id:,
49
- recurring_id:,
50
- plaid_account_id:,
51
- category_id:,
52
- asset_id:,
53
- is_group:,
54
- status:,
55
- start_date:,
56
- end_date:,
57
- debit_as_negative:,
58
- pending:,
59
- offset:,
60
- limit:,
61
- })
62
- response = get("transactions", query_params: params)
63
-
64
- api_errors = errors(response)
65
- return api_errors if api_errors.present?
66
-
67
- response.body[:transactions].map do |transaction|
68
- transaction[:tags].map! { |tag| LunchMoney::TagBase.new(**tag) }
69
-
70
- transaction[:children]&.map! { |child_transaction| LunchMoney::ChildTransaction.new(**child_transaction) }
71
-
72
- LunchMoney::Transaction.new(**transaction)
73
- end
74
- end
75
-
76
- sig do
77
- params(
78
- transaction_id: Integer,
79
- debit_as_negative: T.nilable(T::Boolean),
80
- ).returns(T.any(LunchMoney::Transaction, LunchMoney::Errors))
81
- end
82
- def transaction(transaction_id, debit_as_negative: nil)
83
- params = clean_params({ debit_as_negative: })
84
- response = get("transactions/#{transaction_id}", query_params: params)
85
-
86
- api_errors = errors(response)
87
- return api_errors if api_errors.present?
88
-
89
- LunchMoney::Transaction.new(**response.body)
90
- end
91
-
92
- sig do
93
- params(
94
- transactions: T::Array[LunchMoney::UpdateTransaction],
95
- apply_rules: T.nilable(T::Boolean),
96
- skip_duplicates: T.nilable(T::Boolean),
97
- check_for_recurring: T.nilable(T::Boolean),
98
- debit_as_negative: T.nilable(T::Boolean),
99
- skip_balance_update: T.nilable(T::Boolean),
100
- ).returns(T.any(T::Hash[Symbol, T::Array[Integer]], LunchMoney::Errors))
101
- end
102
- def insert_transactions(transactions, apply_rules: nil, skip_duplicates: nil,
103
- check_for_recurring: nil, debit_as_negative: nil, skip_balance_update: nil)
104
- params = clean_params({
105
- transactions: transactions.map(&:serialize),
106
- apply_rules:,
107
- skip_duplicates:,
108
- check_for_recurring:,
109
- debit_as_negative:,
110
- skip_balance_update:,
111
- })
112
- response = post("transactions", params)
113
-
114
- api_errors = errors(response)
115
- return api_errors if api_errors.present?
116
-
117
- response.body
118
- end
119
-
120
- sig do
121
- params(
122
- transaction_id: Integer,
123
- transaction: T.nilable(LunchMoney::UpdateTransaction),
124
- split: T.nilable(T::Array[LunchMoney::Split]),
125
- debit_as_negative: T.nilable(T::Boolean),
126
- skip_balance_update: T.nilable(T::Boolean),
127
- ).returns(T.any({ updated: T::Boolean, split: T.nilable(T::Array[Integer]) }, LunchMoney::Errors))
128
- end
129
- def update_transaction(transaction_id, transaction: nil, split: nil,
130
- debit_as_negative: nil, skip_balance_update: nil)
131
- raise(
132
- LunchMoney::MissingArgument,
133
- "Either a transaction or split must be provided",
134
- ) if transaction.nil? && split.nil?
135
-
136
- params = clean_params({
137
- transaction: transaction&.serialize,
138
- split: split&.map!(&:serialize),
139
- debit_as_negative:,
140
- skip_balance_update:,
141
- })
142
- response = put("transactions/#{transaction_id}", params)
143
-
144
- api_errors = errors(response)
145
- return api_errors if api_errors.present?
146
-
147
- response.body
148
- end
149
-
150
- sig do
151
- params(
152
- parent_ids: T::Array[Integer],
153
- remove_parents: T.nilable(T::Boolean),
154
- ).returns(T.any(T::Array[Integer], LunchMoney::Errors))
155
- end
156
- def unsplit_transaction(parent_ids, remove_parents: false)
157
- params = { parent_ids:, remove_parents: }
158
- response = post("transactions/unsplit", params)
159
-
160
- api_errors = errors(response)
161
- return api_errors if api_errors.present?
162
-
163
- response.body
164
- end
165
-
166
- sig { params(transaction_id: Integer).returns(T.any(LunchMoney::Transaction, LunchMoney::Errors)) }
167
- def transaction_group(transaction_id)
168
- response = get("transactions/group", query_params: { transaction_id: })
169
-
170
- api_errors = errors(response)
171
- return api_errors if api_errors.present?
172
-
173
- LunchMoney::Transaction.new(**response.body)
174
- end
175
-
176
- sig do
177
- params(
178
- date: String,
179
- payee: String,
180
- transactions: T::Array[T.any(Integer, String)],
181
- category_id: T.nilable(Integer),
182
- notes: T.nilable(String),
183
- tags: T.nilable(T::Array[T.any(Integer, String)]),
184
- ).returns(T.any(Integer, LunchMoney::Errors))
185
- end
186
- def create_transaction_group(date:, payee:, transactions:, category_id: nil, notes: nil, tags: nil)
187
- params = clean_params({
188
- date:,
189
- payee:,
190
- transactions:,
191
- category_id:,
192
- notes:,
193
- tags:,
194
- })
195
- response = post("transactions/group", params)
196
-
197
- api_errors = errors(response)
198
- return api_errors if api_errors.present?
199
-
200
- response.body
201
- end
202
-
203
- sig do
204
- params(transaction_id: T.any(
205
- String,
206
- Integer,
207
- )).returns(T.any(T::Hash[Symbol, T::Array[Integer]], LunchMoney::Errors))
208
- end
209
- def delete_transaction_group(transaction_id)
210
- response = delete("transactions/group/#{transaction_id}")
211
-
212
- api_errors = errors(response)
213
- return api_errors if api_errors.present?
214
-
215
- response.body
216
- end
217
- end
218
- end
@@ -1,36 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- module LunchMoney
5
- # https://lunchmoney.dev/#user-object
6
- class User < LunchMoney::DataObject
7
- sig { returns(Integer) }
8
- attr_accessor :user_id, :account_id
9
-
10
- sig { returns(String) }
11
- attr_accessor :user_name, :user_email, :budget_name
12
-
13
- sig { returns(T.nilable(String)) }
14
- attr_accessor :api_key_label
15
-
16
- sig do
17
- params(
18
- user_id: Integer,
19
- user_name: String,
20
- user_email: String,
21
- account_id: Integer,
22
- budget_name: String,
23
- api_key_label: T.nilable(String),
24
- ).void
25
- end
26
- def initialize(user_id:, user_name:, user_email:, account_id:, budget_name:, api_key_label: nil)
27
- super()
28
- @user_id = user_id
29
- @user_name = user_name
30
- @user_email = user_email
31
- @account_id = account_id
32
- @budget_name = budget_name
33
- @api_key_label = api_key_label
34
- end
35
- end
36
- end
@@ -1,19 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require_relative "user"
5
-
6
- module LunchMoney
7
- # https://lunchmoney.dev/#user
8
- class UserCalls < ApiCall
9
- sig { returns(T.any(LunchMoney::User, LunchMoney::Errors)) }
10
- def me
11
- response = get("me")
12
-
13
- api_errors = errors(response)
14
- return api_errors if api_errors.present?
15
-
16
- LunchMoney::User.new(**response.body)
17
- end
18
- end
19
- end