Class: LunchMoney::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/lunchmoney/api.rb

Overview

The main API class that a user should interface through. The method of any individual call is delegated through here so that it is never necessary to go through things like LunchMoney::Calls::Users.new.user instead you can directly call the endpoint with LunchMoney::Api.new.user and it will be delegated to the correct call.

Examples:

api = LunchMoney::Api.new
api.categories # This will be delegated to LunchMoney::Calls::Categories#categories

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil) ⇒ void

Parameters:

  • api_key (String, nil) (defaults to: nil)


33
34
35
# File 'lib/lunchmoney/api.rb', line 33

def initialize(api_key: nil)
  @api_key = T.let(api_key || LunchMoney.configuration.api_key, T.nilable(String))
end

Instance Attribute Details

#api_keyString? (readonly)

Returns:

  • (String, nil)


30
31
32
# File 'lib/lunchmoney/api.rb', line 30

def api_key
  @api_key
end

Instance Method Details

#asset_callsLunchMoney::Calls::Base

All assets call types come through here.

Examples:

api = LunchMoney::Api.new
api.assets
api = LunchMoney::Api.new
api.create_asset(
  type_name: "cash",
  name: "Create Asset Test",
  balance: "10.00",
)
api = LunchMoney::Api.new
api.update_asset(93746, balance: "99.99")

Returns:



206
207
208
# File 'lib/lunchmoney/api.rb', line 206

def asset_calls
  memoized_call_instance(:@asset_calls, LunchMoney::Calls::Assets)
end

#budget_callsLunchMoney::Calls::Base

All budget call types come through here.

Examples:

api = LunchMoney::Api.new
api.budgets(start_date: "2023-01-01", end_date: "2024-01-01")
api = LunchMoney::Api.new
api.upsert_budget(start_date: "2023-01-01", category_id: 777052, amount: 400.99)
api = LunchMoney::Api.new
api.remove_budget(start_date: "2023-01-01", category_id: 777052)

Returns:



185
186
187
# File 'lib/lunchmoney/api.rb', line 185

def budget_calls
  memoized_call_instance(:@budget_calls, LunchMoney::Calls::Budgets)
end

#category_callsLunchMoney::Calls::Base

All category call types come through here. Reference the docs for available parameters for each call

Examples:

api = LunchMoney::Api.new
api.categories
api = LunchMoney::Api.new
api.category(1234567)
api = LunchMoney::Api.new
api.create_category(name: "New Category Name")
api = LunchMoney::Api.new
api.create_category_group(name: "New Category Group Name")
api = LunchMoney::Api.new
api.update_category(1234567, "Updated Category Name")
api = LunchMoney::Api.new
api.add_to_category_group(7654321, category_ids: [1234567], new_categories: ["Another Category"])
api = LunchMoney::Api.new
api.delete_category(1234567)
api = LunchMoney::Api.new
api.force_delete_category(1234567)

Returns:



85
86
87
# File 'lib/lunchmoney/api.rb', line 85

def category_calls
  memoized_call_instance(:@category_calls, LunchMoney::Calls::Categories)
end

#crypto_callsLunchMoney::Calls::Base

All crypto call types come through here.

Examples:

api = LunchMoney::Api.new
api.crypto
api = LunchMoney::Api.new
api.update_crypto(1234567, name: "New Crypto Name")

Returns:



234
235
236
# File 'lib/lunchmoney/api.rb', line 234

def crypto_calls
  memoized_call_instance(:@crypto_calls, LunchMoney::Calls::Crypto)
end

#plaid_account_callsLunchMoney::Calls::Base

All Plaid accounts call types come through here.

Examples:

api = LunchMoney::Api.new
api.plaid_accounts
api = LunchMoney::Api.new
api.plaid_accounts_fetch

Returns:



220
221
222
# File 'lib/lunchmoney/api.rb', line 220

def 
  memoized_call_instance(:@plaid_account_calls, LunchMoney::Calls::PlaidAccounts)
end

#recurring_expense_callsLunchMoney::Calls::Base

All recurring expenses call types come through here.

Examples:

api = LunchMoney::Api.new
api.recurring_expenses

Returns:



168
169
170
# File 'lib/lunchmoney/api.rb', line 168

def recurring_expense_calls
  memoized_call_instance(:@recurring_expense_calls, LunchMoney::Calls::RecurringExpenses)
end

#tag_callsLunchMoney::Calls::Base

All tags call types come through here.

Examples:

api = LunchMoney::Api.new
api.tags

Returns:



96
97
98
# File 'lib/lunchmoney/api.rb', line 96

def tag_calls
  memoized_call_instance(:@tag_calls, LunchMoney::Calls::Tags)
end

#transaction_callsLunchMoney::Calls::Base

All transaction call types come through here.

Examples:

api = LunchMoney::Api.new
api.transactions
api = LunchMoney::Api.new
api.transaction(123456789)
api = LunchMoney::Api.new
transaction = LunchMoney::Objects::UpdateTransaction.new(
  date: "2024-01-01",
  amount: "10.99",
  payee: "Example Payee",
  currency: "cad",
  status: "cleared"
)
api.insert_transactions([transaction])
api = LunchMoney::Api.new
transaction = LunchMoney::Objects::UpdateTransaction.new(
  date: "2024-01-01",
  amount: "10.99",
  payee: "Example Payee",
  currency: "cad",
  status: "cleared"
)
api.update_transaction(123456789, transaction: transaction)
api = LunchMoney::Api.new
split = [
  LunchMoney::Objects::Split.new(amount: "10.00"),
  LunchMoney::Objects::Split.new(amount: "47.54"),
]
api.update_transaction(12345678, split: split)
api = LunchMoney::Api.new
api.unsplit_transaction([123456789])
api = LunchMoney::Api.new
api.transaction_group(987654321)
api = LunchMoney::Api.new
api.create_transaction_group(date: "2024-01-01", payee: "Group", transactions: [123456789, 987654321])
api = LunchMoney::Api.new
api.delete_transaction_group(905483362)

Returns:



157
158
159
# File 'lib/lunchmoney/api.rb', line 157

def transaction_calls
  memoized_call_instance(:@transaction_calls, LunchMoney::Calls::Transactions)
end

#user_callsLunchMoney::Calls::Base

All user call types come through here.

Examples:

api = LunchMoney::Api.new
api.me

Returns:



44
45
46
# File 'lib/lunchmoney/api.rb', line 44

def user_calls
  memoized_call_instance(:@user_calls, LunchMoney::Calls::Users)
end