pub struct Client { /* private fields */ }Expand description
Client is the YNAB API client. Use Client::new() to create one.
Implementations§
Source§impl Client
impl Client
Sourcepub fn get_accounts(&self, plan_id: PlanId) -> GetAccountsBuilder<'_>
pub fn get_accounts(&self, plan_id: PlanId) -> GetAccountsBuilder<'_>
Returns all accounts. The second return value is server knowledge for delta requests.
Source§impl Client
impl Client
Sourcepub async fn create_account(
&self,
plan_id: PlanId,
account: SaveAccount,
) -> Result<Account, Error>
pub async fn create_account( &self, plan_id: PlanId, account: SaveAccount, ) -> Result<Account, Error>
Creates a new account.
Source§impl Client
impl Client
Sourcepub fn get_categories(&self, plan_id: PlanId) -> GetCategoriesBuilder<'_>
pub fn get_categories(&self, plan_id: PlanId) -> GetCategoriesBuilder<'_>
Returns all categories grouped by category group. Amounts (assigned, activity, available, etc.) are specific to the current plan month (UTC). The second return value is server knowledge for delta requests.
Source§impl Client
impl Client
Sourcepub async fn create_category(
&self,
plan_id: PlanId,
category: NewCategory,
) -> Result<(Category, i64), Error>
pub async fn create_category( &self, plan_id: PlanId, category: NewCategory, ) -> Result<(Category, i64), Error>
Creates a new category.
Sourcepub async fn create_category_group(
&self,
plan_id: PlanId,
category_group: SaveCategoryGroup,
) -> Result<(CategoryGroup, i64), Error>
pub async fn create_category_group( &self, plan_id: PlanId, category_group: SaveCategoryGroup, ) -> Result<(CategoryGroup, i64), Error>
Creates a new category group.
Sourcepub async fn update_category(
&self,
plan_id: PlanId,
category_id: Uuid,
category: SaveCategory,
) -> Result<(Category, i64), Error>
pub async fn update_category( &self, plan_id: PlanId, category_id: Uuid, category: SaveCategory, ) -> Result<(Category, i64), Error>
Update a category.
Sourcepub async fn update_category_for_month(
&self,
plan_id: PlanId,
month: NaiveDate,
category_id: Uuid,
category: SaveMonthCategory,
) -> Result<(Category, i64), Error>
pub async fn update_category_for_month( &self, plan_id: PlanId, month: NaiveDate, category_id: Uuid, category: SaveMonthCategory, ) -> Result<(Category, i64), Error>
Update a category for a specific month. Only budgeted (assigned) amount can be updated.`
Sourcepub async fn update_category_group(
&self,
plan_id: PlanId,
category_group_id: Uuid,
category_group: SaveCategoryGroup,
) -> Result<(CategoryGroup, i64), Error>
pub async fn update_category_group( &self, plan_id: PlanId, category_group_id: Uuid, category_group: SaveCategoryGroup, ) -> Result<(CategoryGroup, i64), Error>
Update a category group.
Source§impl Client
impl Client
Sourcepub fn new(api_key: impl Into<String>) -> Result<Self, Error>
pub fn new(api_key: impl Into<String>) -> Result<Self, Error>
Creates a new Client with the given Personal Access Token.
Sourcepub fn with_timeout(self, timeout: Duration) -> Result<Self, Error>
pub fn with_timeout(self, timeout: Duration) -> Result<Self, Error>
Sets the request timeout. Rebuilds the underlying HTTP client.
Sourcepub fn with_base_url(self, base_url: impl AsRef<str>) -> Result<Self, Error>
pub fn with_base_url(self, base_url: impl AsRef<str>) -> Result<Self, Error>
Overrides the base URL. Primarily useful for testing.
Sourcepub fn with_rate_limiter(
self,
requests_per_hour: usize,
burst_volume: Option<usize>,
) -> Result<Self, Error>
pub fn with_rate_limiter( self, requests_per_hour: usize, burst_volume: Option<usize>, ) -> Result<Self, Error>
Configures a token bucket rate limiter on the client. The YNAB API enforces a rolling window of 200 requests per hour.
requests_per_hour is the total allowed requests per hour.
burst_volume optionally allows a number of requests to be made immediately
before throttling begins. The effective sustained rate becomes
requests_per_hour - burst_volume to account for burst consumption.
If None, no burst is allowed and the full rate is sustained evenly.
Example: with_rate_limiter(200, Some(10)) allows 10 immediate requests,
then throttles to 190 requests per hour.
Source§impl Client
impl Client
Sourcepub fn get_money_movements(
&self,
plan_id: PlanId,
) -> GetMoneyMovementsBuilder<'_>
pub fn get_money_movements( &self, plan_id: PlanId, ) -> GetMoneyMovementsBuilder<'_>
Returns all money movements. The second return value is server knowledge for delta requests.
Sourcepub async fn get_money_movements_by_month(
&self,
plan_id: PlanId,
month: NaiveDate,
) -> Result<(Vec<MoneyMovement>, i64), Error>
pub async fn get_money_movements_by_month( &self, plan_id: PlanId, month: NaiveDate, ) -> Result<(Vec<MoneyMovement>, i64), Error>
Returns all money movements for a specific month. The second return value is server knowledge for delta requests.
Sourcepub fn get_money_movement_groups(
&self,
plan_id: PlanId,
) -> GetMoneyMovementGroupsBuilder<'_>
pub fn get_money_movement_groups( &self, plan_id: PlanId, ) -> GetMoneyMovementGroupsBuilder<'_>
Returns all money movement groups. The second return value is server knowledge for delta requests.
Sourcepub async fn get_money_movement_groups_by_month(
&self,
plan_id: PlanId,
month: NaiveDate,
) -> Result<(Vec<MoneyMovementGroup>, i64), Error>
pub async fn get_money_movement_groups_by_month( &self, plan_id: PlanId, month: NaiveDate, ) -> Result<(Vec<MoneyMovementGroup>, i64), Error>
Returns all money movement groups for a specific month. The second return value is server knowledge for delta requests.
Source§impl Client
impl Client
Sourcepub fn get_payees(&self, plan_id: PlanId) -> GetPayeesBuilder<'_>
pub fn get_payees(&self, plan_id: PlanId) -> GetPayeesBuilder<'_>
Returns all payees. The second return value is server knowledge for delta requests.
Sourcepub async fn get_payee(
&self,
plan_id: PlanId,
payee_id: Uuid,
) -> Result<Payee, Error>
pub async fn get_payee( &self, plan_id: PlanId, payee_id: Uuid, ) -> Result<Payee, Error>
Returns a single payee.
Sourcepub async fn get_payee_locations(
&self,
plan_id: PlanId,
) -> Result<Vec<PayeeLocation>, Error>
pub async fn get_payee_locations( &self, plan_id: PlanId, ) -> Result<Vec<PayeeLocation>, Error>
Returns all payee locations.
Sourcepub async fn get_payee_locations_by_payee(
&self,
plan_id: PlanId,
payee_id: Uuid,
) -> Result<Vec<PayeeLocation>, Error>
pub async fn get_payee_locations_by_payee( &self, plan_id: PlanId, payee_id: Uuid, ) -> Result<Vec<PayeeLocation>, Error>
Returns all payee locations for a specified payee.
Sourcepub async fn get_payee_location(
&self,
plan_id: PlanId,
location_id: Uuid,
) -> Result<PayeeLocation, Error>
pub async fn get_payee_location( &self, plan_id: PlanId, location_id: Uuid, ) -> Result<PayeeLocation, Error>
Returns a single payee location.
Source§impl Client
impl Client
Source§impl Client
impl Client
Sourcepub async fn get_plan_settings(
&self,
plan_id: PlanId,
) -> Result<PlanSettings, Error>
pub async fn get_plan_settings( &self, plan_id: PlanId, ) -> Result<PlanSettings, Error>
Returns settings for a plan.
Source§impl Client
impl Client
Sourcepub fn get_transactions(&self, plan_id: PlanId) -> GetTransactionsBuilder<'_>
pub fn get_transactions(&self, plan_id: PlanId) -> GetTransactionsBuilder<'_>
Returns plan transactions, excluding any pending transactions. The second return value is server knowledge for delta requests.
Sourcepub async fn get_transaction(
&self,
plan_id: PlanId,
transaction_id: &Uuid,
) -> Result<(Transaction, i64), Error>
pub async fn get_transaction( &self, plan_id: PlanId, transaction_id: &Uuid, ) -> Result<(Transaction, i64), Error>
Returns a single transaction.
Sourcepub fn get_transactions_by_account(
&self,
plan_id: PlanId,
account_id: Uuid,
) -> GetTransactionsBuilder<'_>
pub fn get_transactions_by_account( &self, plan_id: PlanId, account_id: Uuid, ) -> GetTransactionsBuilder<'_>
Returns all transactions for a specified account, excluding any pending transactions.
Sourcepub fn get_transactions_by_category(
&self,
plan_id: PlanId,
category_id: Uuid,
) -> GetTransactionsBuilder<'_>
pub fn get_transactions_by_category( &self, plan_id: PlanId, category_id: Uuid, ) -> GetTransactionsBuilder<'_>
Returns all transactions for a specified category, excluding any pending transactions.
Sourcepub fn get_transactions_by_payee(
&self,
plan_id: PlanId,
payee_id: Uuid,
) -> GetTransactionsBuilder<'_>
pub fn get_transactions_by_payee( &self, plan_id: PlanId, payee_id: Uuid, ) -> GetTransactionsBuilder<'_>
Returns all transactions for a specified payee, excluding any pending transactions.
Sourcepub fn get_transactions_by_month(
&self,
plan_id: PlanId,
month: NaiveDate,
) -> GetTransactionsBuilder<'_>
pub fn get_transactions_by_month( &self, plan_id: PlanId, month: NaiveDate, ) -> GetTransactionsBuilder<'_>
Returns all transactions for a specified month, excluding any pending transactions.
Source§impl Client
impl Client
Sourcepub fn get_scheduled_transactions(
&self,
plan_id: PlanId,
) -> GetScheduledTransactionsBuilder<'_>
pub fn get_scheduled_transactions( &self, plan_id: PlanId, ) -> GetScheduledTransactionsBuilder<'_>
Returns all scheduled transactions. The second return value is server knowledge for delta requests.
Sourcepub async fn get_scheduled_transaction(
&self,
plan_id: PlanId,
transaction_id: Uuid,
) -> Result<ScheduledTransaction, Error>
pub async fn get_scheduled_transaction( &self, plan_id: PlanId, transaction_id: Uuid, ) -> Result<ScheduledTransaction, Error>
Returns a single scheduled transaction.
Source§impl Client
impl Client
Sourcepub async fn delete_transaction(
&self,
plan_id: PlanId,
tx_id: Uuid,
) -> Result<(Transaction, i64), Error>
pub async fn delete_transaction( &self, plan_id: PlanId, tx_id: Uuid, ) -> Result<(Transaction, i64), Error>
Delete a transaction. Returns deleted transaction and server_knowledge for delta requests
Source§impl Client
impl Client
Sourcepub async fn create_transaction(
&self,
plan_id: PlanId,
transaction: NewTransaction,
) -> Result<SaveTransactionsResponse, Error>
pub async fn create_transaction( &self, plan_id: PlanId, transaction: NewTransaction, ) -> Result<SaveTransactionsResponse, Error>
Creates a single transaction. Returns the full save response including server knowledge.
Sourcepub async fn create_transactions(
&self,
plan_id: PlanId,
transactions: Vec<NewTransaction>,
) -> Result<SaveTransactionsResponse, Error>
pub async fn create_transactions( &self, plan_id: PlanId, transactions: Vec<NewTransaction>, ) -> Result<SaveTransactionsResponse, Error>
Creates multiple transactions. Returns the full save response including server knowledge.
Sourcepub async fn update_transactions(
&self,
plan_id: PlanId,
transactions: Vec<SaveTransactionWithIdOrImportId>,
) -> Result<SaveTransactionsResponse, Error>
pub async fn update_transactions( &self, plan_id: PlanId, transactions: Vec<SaveTransactionWithIdOrImportId>, ) -> Result<SaveTransactionsResponse, Error>
Updates multiple transactions. Returns the full save response including server knowledge.
Sourcepub async fn update_transaction(
&self,
plan_id: PlanId,
tx_id: Uuid,
transaction: ExistingTransaction,
) -> Result<(Transaction, i64), Error>
pub async fn update_transaction( &self, plan_id: PlanId, tx_id: Uuid, transaction: ExistingTransaction, ) -> Result<(Transaction, i64), Error>
Updates a single transaction. Returns the updated transaction and server knowledge.
Sourcepub async fn create_scheduled_transaction(
&self,
plan_id: PlanId,
scheduled_transaction: SaveScheduledTransaction,
) -> Result<ScheduledTransaction, Error>
pub async fn create_scheduled_transaction( &self, plan_id: PlanId, scheduled_transaction: SaveScheduledTransaction, ) -> Result<ScheduledTransaction, Error>
Creates a scheduled transaction.
Sourcepub async fn update_scheduled_transaction(
&self,
plan_id: PlanId,
scheduled_transaction_id: Uuid,
scheduled_transaction: SaveScheduledTransaction,
) -> Result<ScheduledTransaction, Error>
pub async fn update_scheduled_transaction( &self, plan_id: PlanId, scheduled_transaction_id: Uuid, scheduled_transaction: SaveScheduledTransaction, ) -> Result<ScheduledTransaction, Error>
Updates a scheduled transaction.
Sourcepub async fn delete_scheduled_transaction(
&self,
plan_id: PlanId,
scheduled_transaction_id: Uuid,
) -> Result<ScheduledTransaction, Error>
pub async fn delete_scheduled_transaction( &self, plan_id: PlanId, scheduled_transaction_id: Uuid, ) -> Result<ScheduledTransaction, Error>
Deletes a scheduled transaction.