Skip to content
halorrr edited this page Nov 15, 2023 · 2 revisions

Asset calls were made in reference to the LunchMoney Developer documentation for Assets.

Assets Object

The LunchMoney::Asset Object is implemented with a few validations based on the developer documentation.

  1. type_name must be one of the valid type names for this field
  2. subtype_name must be one of the valid subtype names for this field
  3. balance_as_of must be in ISO 8601 extended format
  4. created_at must be in ISO 8601 extended format

Like all LunchMoney::DataObject descendants, this class can be serialized into a hash with the .serialize method, and optionally have the keys symbolized with .serialize(symbolize_keys: true).

Get All Assets

You can get all assets using the assets method:

api = LunchMoney::Api.new
api.assets

Unless there are errors returned this will return an array of LunchMoney::Asset.

Create Asset

You can create an asset using the create_asset method, passing the required type_name, name, and balance attributes, as well as any optional attributes you might want to create the asset with:

api = LunchMoney::Api.new
api.create_asset(type_name: "cash", name: "Test Asset", balance: "1234.5678")
api = LunchMoney::Api.new
api.create_asset(
  type_name: "cash",
  subtype_name: "retirement",
  name: "Test Asset",
  balance: "1234.5678",
  currency: "cad",
  institution_name: "Bank of Me",
  exclude_transactions: false,
)

This will return a LunchMoney::Asset.

Update Asset

You can create an update using the update_asset method, passing the required asset_id attribute, as well as any attributes you want to update on the asset:

api = LunchMoney::Api.new
api.update_asset(
  asset_id: 1
  type_name: "other asset",
  subtype_name: nil,
  name: "Test Asset Updated",
  balance: "8765.4321",
  currency: "usd",
  institution_name: "Piggy Bank",
  exclude_transactions: true,
)

Unless there are errors returned this will return a LunchMoney::Asset.

Clone this wiki locally