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)


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

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)


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

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:



223
224
225
226
227
# File 'lib/lunchmoney/api.rb', line 223

def asset_calls
  with_valid_api_key do
    @asset_calls ||= T.let(LunchMoney::Calls::Assets.new(api_key:), T.nilable(LunchMoney::Calls::Assets))
  end
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:



200
201
202
203
204
# File 'lib/lunchmoney/api.rb', line 200

def budget_calls
  with_valid_api_key do
    @budget_calls ||= T.let(LunchMoney::Calls::Budgets.new(api_key:), T.nilable(LunchMoney::Calls::Budgets))
  end
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:



86
87
88
89
90
# File 'lib/lunchmoney/api.rb', line 86

def category_calls
  with_valid_api_key do
    @category_calls ||= T.let(LunchMoney::Calls::Categories.new(api_key:), T.nilable(LunchMoney::Calls::Categories))
  end
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:



258
259
260
261
262
# File 'lib/lunchmoney/api.rb', line 258

def crypto_calls
  with_valid_api_key do
    @crypto_calls ||= T.let(LunchMoney::Calls::Crypto.new(api_key:), T.nilable(LunchMoney::Calls::Crypto))
  end
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:



239
240
241
242
243
244
245
246
# File 'lib/lunchmoney/api.rb', line 239

def 
  with_valid_api_key do
    @plaid_account_calls ||= T.let(
      LunchMoney::Calls::PlaidAccounts.new(api_key:),
      T.nilable(LunchMoney::Calls::PlaidAccounts),
    )
  end
end

#recurring_expense_callsLunchMoney::Calls::Base

All recurring expenses call types come through here.

Examples:

api = LunchMoney::Api.new
api.recurring_expenses

Returns:



178
179
180
181
182
183
184
185
# File 'lib/lunchmoney/api.rb', line 178

def recurring_expense_calls
  with_valid_api_key do
    @recurring_expense_calls ||= T.let(
      LunchMoney::Calls::RecurringExpenses.new(api_key:),
      T.nilable(LunchMoney::Calls::RecurringExpenses),
    )
  end
end

#tag_callsLunchMoney::Calls::Base

All tags call types come through here.

Examples:

api = LunchMoney::Api.new
api.tags

Returns:



99
100
101
102
103
# File 'lib/lunchmoney/api.rb', line 99

def tag_calls
  with_valid_api_key do
    @tag_calls ||= T.let(LunchMoney::Calls::Tags.new(api_key:), T.nilable(LunchMoney::Calls::Tags))
  end
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:



162
163
164
165
166
167
168
169
# File 'lib/lunchmoney/api.rb', line 162

def transaction_calls
  with_valid_api_key do
    @transaction_calls ||= T.let(
      LunchMoney::Calls::Transactions.new(api_key:),
      T.nilable(LunchMoney::Calls::Transactions),
    )
  end
end

#user_callsLunchMoney::Calls::Base

All user call types come through here.

Examples:

api = LunchMoney::Api.new
api.me

Returns:



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

def user_calls
  with_valid_api_key do
    @user_calls ||= T.let(LunchMoney::Calls::Users.new(api_key:), T.nilable(LunchMoney::Calls::Users))
  end
end