Class: LunchMoney::Calls::Categories
- Defined in:
- lib/lunchmoney/calls/categories.rb
Overview
Constant Summary collapse
- VALID_FORMATS =
Valid query parameter formats for categories
[ "flattened", "nested", ]
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
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/lunchmoney/calls/categories.rb', line 140 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
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/lunchmoney/calls/categories.rb', line 21 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
34 35 36 37 38 39 40 41 42 |
# File 'lib/lunchmoney/calls/categories.rb', line 34 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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lunchmoney/calls/categories.rb', line 55 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
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/lunchmoney/calls/categories.rb', line 84 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
154 155 156 157 158 159 160 |
# File 'lib/lunchmoney/calls/categories.rb', line 154 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
163 164 165 166 167 168 169 |
# File 'lib/lunchmoney/calls/categories.rb', line 163 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
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/lunchmoney/calls/categories.rb', line 115 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 |