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 a builder for fetching all accounts. Chain .with_server_knowledge() for a delta request.
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 a builder for fetching all categories grouped by category group. Chain
.with_server_knowledge() for a delta request.
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.
§Examples
use rust_ynab::Client;
let client = Client::new(&std::env::var("YNAB_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. Returns self for chaining.
§Examples
use rust_ynab::Client;
use std::time::Duration;
let client = Client::new(&std::env::var("YNAB_TOKEN")?)?
.with_timeout(Duration::from_secs(30))?;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. Returns self for chaining.
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.
§Examples
use rust_ynab::Client;
use std::time::Duration;
let client = Client::new(&std::env::var("YNAB_TOKEN")?)?
.with_rate_limiter(200, Some(10))? // 10 burst, then 190/hr
.with_timeout(Duration::from_secs(30))?;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 a builder for fetching all money movements. Chain .with_server_knowledge() for a delta request.
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 a builder for fetching all money movement groups. Chain .with_server_knowledge() for a delta request.
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 a builder for fetching all payees. Chain .with_server_knowledge() for a delta request.
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 fn get_plans(&self) -> GetPlansBuilder<'_>
pub fn get_plans(&self) -> GetPlansBuilder<'_>
Returns a builder for fetching all plans. Chain .include_accounts() to embed account
details inline.
§Examples
let client = Client::new(&std::env::var("YNAB_TOKEN")?)?;
let plans = client.get_plans().include_accounts().send().await?;
for plan in &plans {
println!("{}: {} accounts", plan.name, plan.accounts.len());
}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 a builder for fetching transactions. Chain .with_server_knowledge(),
.since_date(), or .transaction_type() before calling .send().
§Examples
// Full fetch
let (transactions, server_knowledge) = client
.get_transactions(PlanId::LastUsed)
.send()
.await?;
// Delta request — only changes since last sync
let (changes, new_sk) = client
.get_transactions(PlanId::LastUsed)
.with_server_knowledge(server_knowledge)
.send()
.await?;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 a builder for fetching transactions for a specified account.
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 a builder for fetching transactions for a specified category.
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 a builder for fetching transactions for a specified payee.
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 a builder for fetching transactions for a specified month.
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 a builder for fetching all scheduled transactions. Chain .with_server_knowledge()
for a delta request.
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.
§Examples
let resp = client.create_transaction(PlanId::LastUsed, NewTransaction {
account_id,
date: chrono::Local::now().date_naive(),
amount: Some(-15000), // -$15.00
memo: Some("Coffee".to_string()),
cleared: Some(ClearedStatus::Cleared),
approved: Some(true),
payee_id: None,
payee_name: None,
category_id: None,
flag_color: None,
import_id: None,
subtransactions: None,
}).await?;
let tx_id = resp.transaction.unwrap().id;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.