Class: LunchMoney::Calls::Categories
- Defined in:
- lib/lunchmoney/calls/categories.rb
Overview
https://lunchmoney.dev/#categories
Constant Summary collapse
- VALID_FORMATS =
Valid query parameter formats for categories
T.let( [ "flattened", "nested", ], T::Array[String], )
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#add_to_category_group(group_id, category_ids: [], new_categories: []) ⇒ LunchMoney::Objects::Category, LunchMoney::Errors
-
#categories(format: nil) ⇒ Array<LunchMoney::Objects::Category>, LunchMoney::Errors
-
#category(category_id) ⇒ LunchMoney::Objects::Category, LunchMoney::Errors
-
#create_category(name:, description: nil, is_income: false, exclude_from_budget: false, exclude_from_totals: false, archived: false, group_id: nil) ⇒ Hash{Symbol => Integer}, LunchMoney::Errors
-
#create_category_group(name:, description: nil, is_income: false, exclude_from_budget: false, exclude_from_totals: false, category_ids: [], new_categories: []) ⇒ Hash{Symbol => Integer}, LunchMoney::Errors
-
#delete_category(category_id) ⇒ Boolean, LunchMoney::Errors
-
#force_delete_category(category_id) ⇒ Boolean, LunchMoney::Errors
-
#update_category(category_id, name: nil, description: nil, is_income: nil, exclude_from_budget: nil, exclude_from_totals: nil, archived: nil, group_id: nil) ⇒ Boolean, LunchMoney::Errors
Methods inherited from Base
Constructor Details
This class inherits a constructor from LunchMoney::Calls::Base
Instance Method Details
#add_to_category_group(group_id, category_ids: [], new_categories: []) ⇒ LunchMoney::Objects::Category, LunchMoney::Errors
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/lunchmoney/calls/categories.rb', line 143 def add_to_category_group(group_id, category_ids: [], new_categories: []) params = { category_ids:, new_categories:, } response = post("categories/group/#{group_id}/add", params) handle_api_response(response) do |body| LunchMoney::Objects::Category.new(**body) end end |
#categories(format: nil) ⇒ Array<LunchMoney::Objects::Category>, LunchMoney::Errors
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lunchmoney/calls/categories.rb', line 24 def categories(format: nil) response = get("categories", query_params: categories_params(format:)) handle_api_response(response) do |body| body[:categories].map do |category| category[:children]&.map! { |child_category| LunchMoney::Objects::Category.new(**child_category) } LunchMoney::Objects::Category.new(**category) end end end |
#category(category_id) ⇒ LunchMoney::Objects::Category, LunchMoney::Errors
37 38 39 40 41 42 43 44 45 |
# File 'lib/lunchmoney/calls/categories.rb', line 37 def category(category_id) response = get("categories/#{category_id}") handle_api_response(response) do |body| body[:children]&.map! { |child_category| LunchMoney::Objects::ChildCategory.new(**child_category) } LunchMoney::Objects::Category.new(**body) end end |
#create_category(name:, description: nil, is_income: false, exclude_from_budget: false, exclude_from_totals: false, archived: false, group_id: nil) ⇒ Hash{Symbol => Integer}, LunchMoney::Errors
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/lunchmoney/calls/categories.rb', line 58 def create_category(name:, description: nil, is_income: false, exclude_from_budget: false, exclude_from_totals: false, archived: false, group_id: nil) params = clean_params({ name:, description:, is_income:, exclude_from_budget:, exclude_from_totals:, archived:, group_id:, }) response = post("categories", params) handle_api_response(response) do |body| body end end |
#create_category_group(name:, description: nil, is_income: false, exclude_from_budget: false, exclude_from_totals: false, category_ids: [], new_categories: []) ⇒ Hash{Symbol => Integer}, LunchMoney::Errors
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/lunchmoney/calls/categories.rb', line 87 def create_category_group(name:, description: nil, is_income: false, exclude_from_budget: false, exclude_from_totals: false, category_ids: [], new_categories: []) params = { name:, description:, is_income:, exclude_from_budget:, exclude_from_totals:, category_ids:, new_categories:, } response = post("categories/group", params) handle_api_response(response) do |body| body end end |
#delete_category(category_id) ⇒ Boolean, LunchMoney::Errors
157 158 159 160 161 162 163 |
# File 'lib/lunchmoney/calls/categories.rb', line 157 def delete_category(category_id) response = delete("categories/#{category_id}") handle_api_response(response) do |body| body end end |
#force_delete_category(category_id) ⇒ Boolean, LunchMoney::Errors
166 167 168 169 170 171 172 |
# File 'lib/lunchmoney/calls/categories.rb', line 166 def force_delete_category(category_id) response = delete("categories/#{category_id}/force") handle_api_response(response) do |body| body end end |
#update_category(category_id, name: nil, description: nil, is_income: nil, exclude_from_budget: nil, exclude_from_totals: nil, archived: nil, group_id: nil) ⇒ Boolean, LunchMoney::Errors
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/lunchmoney/calls/categories.rb', line 118 def update_category(category_id, name: nil, description: nil, is_income: nil, exclude_from_budget: nil, exclude_from_totals: nil, archived: nil, group_id: nil) params = clean_params({ name:, description:, is_income:, exclude_from_budget:, exclude_from_totals:, archived:, group_id:, }) response = put("categories/#{category_id}", params) handle_api_response(response) do |body| body end end |