Class: LunchMoney::Calls::Budgets
- Defined in:
- lib/lunchmoney/calls/budgets.rb
Overview
https://lunchmoney.dev/#budget
Constant Summary
Constants inherited from Base
LunchMoney::Calls::Base::BASE_URL
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#budgets(start_date:, end_date:, currency: nil) ⇒ Array<LunchMoney::Objects::Budget>, LunchMoney::Errors
-
#remove_budget(start_date:, category_id:) ⇒ Boolean, LunchMoney::Errors
-
#upsert_budget(start_date:, category_id:, amount:, currency: nil) ⇒ Hash{Symbol => Hash}, LunchMoney::Errors
Methods inherited from Base
Constructor Details
This class inherits a constructor from LunchMoney::Calls::Base
Instance Method Details
#budgets(start_date:, end_date:, currency: nil) ⇒ Array<LunchMoney::Objects::Budget>, LunchMoney::Errors
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lunchmoney/calls/budgets.rb', line 17 def budgets(start_date:, end_date:, currency: nil) params = clean_params({ start_date:, end_date:, currency: }) response = get("budgets", query_params: params) handle_api_response(response) do |body| body.map do |budget| if budget[:data] data_keys = budget[:data].keys data_keys.each do |data_key| budget[:data][data_key] = LunchMoney::Objects::Data.new(**budget[:data][data_key]) end end if budget[:config] config_keys = budget[:config].keys config_keys.each do |config_key| budget[:config][config_key] = LunchMoney::Objects::Data.new(**budget[:config][config_key]) end end if budget[:recurring] budget[:recurring][:list]&.map! { |recurring| LunchMoney::Objects::RecurringExpenseBase.new(**recurring) } end LunchMoney::Objects::Budget.new(**budget) end end end |
#remove_budget(start_date:, category_id:) ⇒ Boolean, LunchMoney::Errors
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/lunchmoney/calls/budgets.rb', line 67 def remove_budget(start_date:, category_id:) params = { start_date:, category_id:, } response = delete("budgets", query_params: params) handle_api_response(response) do |body| body end end |
#upsert_budget(start_date:, category_id:, amount:, currency: nil) ⇒ Hash{Symbol => Hash}, LunchMoney::Errors
57 58 59 60 61 62 63 64 |
# File 'lib/lunchmoney/calls/budgets.rb', line 57 def upsert_budget(start_date:, category_id:, amount:, currency: nil) params = clean_params({ start_date:, category_id:, amount:, currency: }) response = put("budgets", params) handle_api_response(response) do |body| body end end |