Skip to main content

Client

Struct Client 

Source
pub struct Client { /* private fields */ }
Expand description

Client is the YNAB API client. Use Client::new() to create one.

Implementations§

Source§

impl Client

Source

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

pub async fn get_account( &self, plan_id: PlanId, account_id: Uuid, ) -> Result<Account, Error>

Returns a single account.

Source§

impl Client

Source

pub async fn create_account( &self, plan_id: PlanId, account: SaveAccount, ) -> Result<Account, Error>

Creates a new account.

Source§

impl Client

Source

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

pub async fn get_category( &self, plan_id: PlanId, cat_id: Uuid, ) -> Result<Category, Error>

Returns a single category. Amounts (assigned, activity, available, etc.) are specific to the current plan month (UTC).

Source

pub async fn get_category_for_month( &self, plan_id: PlanId, month: NaiveDate, cat_id: Uuid, ) -> Result<Category, Error>

Returns a single category for a specific plan month. Amounts (assigned, activity, available, etc.) are specific to the current plan month (UTC).

Source§

impl Client

Source

pub async fn create_category( &self, plan_id: PlanId, category: NewCategory, ) -> Result<(Category, i64), Error>

Creates a new category.

Source

pub async fn create_category_group( &self, plan_id: PlanId, category_group: SaveCategoryGroup, ) -> Result<(CategoryGroup, i64), Error>

Creates a new category group.

Source

pub async fn update_category( &self, plan_id: PlanId, category_id: Uuid, category: SaveCategory, ) -> Result<(Category, i64), Error>

Update a category.

Source

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.`

Source

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

Source

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")?)?;
Source

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))?;
Source

pub fn with_base_url(self, base_url: impl AsRef<str>) -> Result<Self, Error>

Overrides the base URL. Primarily useful for testing.

Source

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

Source

pub fn get_months(&self, plan_id: PlanId) -> GetMonthsBuilder<'_>

Returns a builder for fetching all plan months. Chain .with_server_knowledge() for a delta request.

Source

pub async fn get_month( &self, plan_id: PlanId, month: NaiveDate, ) -> Result<Month, Error>

Returns a single plan month.

Source§

impl Client

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn get_payees(&self, plan_id: PlanId) -> GetPayeesBuilder<'_>

Returns a builder for fetching all payees. Chain .with_server_knowledge() for a delta request.

Source

pub async fn get_payee( &self, plan_id: PlanId, payee_id: Uuid, ) -> Result<Payee, Error>

Returns a single payee.

Source

pub async fn get_payee_locations( &self, plan_id: PlanId, ) -> Result<Vec<PayeeLocation>, Error>

Returns all payee locations.

Source

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.

Source

pub async fn get_payee_location( &self, plan_id: PlanId, location_id: Uuid, ) -> Result<PayeeLocation, Error>

Returns a single payee location.

Source§

impl Client

Source

pub async fn create_payee( &self, plan_id: PlanId, payee: PostPayee, ) -> Result<(Payee, i64), Error>

Creates a new payee. Returns the created payee and server knowledge for delta requests.

Source

pub async fn update_payee( &self, plan_id: PlanId, payee_id: Uuid, payee: SavePayee, ) -> Result<(Payee, i64), Error>

Updates an existing payee. Returns the updated payee and server knowledge for delta requests.

Source§

impl Client

Source

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());
}
Source

pub async fn get_plan_settings( &self, plan_id: PlanId, ) -> Result<PlanSettings, Error>

Returns settings for a plan.

Source

pub fn get_plan(&self, plan_id: PlanId) -> GetPlanBuilder<'_>

Returns a builder for fetching a single plan with all related entities (a full plan export). Chain .with_server_knowledge() for a delta request.

Source§

impl Client

Source

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?;
Source

pub async fn get_transaction( &self, plan_id: PlanId, transaction_id: &str, ) -> Result<(Transaction, i64), Error>

Returns a single transaction.

Source

pub fn get_transactions_by_account( &self, plan_id: PlanId, account_id: Uuid, ) -> GetTransactionsBuilder<'_>

Returns a builder for fetching transactions for a specified account.

Source

pub fn get_transactions_by_category( &self, plan_id: PlanId, category_id: Uuid, ) -> GetTransactionsBuilder<'_>

Returns a builder for fetching transactions for a specified category.

Source

pub fn get_transactions_by_payee( &self, plan_id: PlanId, payee_id: Uuid, ) -> GetTransactionsBuilder<'_>

Returns a builder for fetching transactions for a specified payee.

Source

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

Source

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.

Source

pub async fn get_scheduled_transaction( &self, plan_id: PlanId, transaction_id: Uuid, ) -> Result<ScheduledTransaction, Error>

Returns a single scheduled transaction.

Source§

impl Client

Source

pub async fn delete_transaction( &self, plan_id: PlanId, tx_id: &str, ) -> Result<(Transaction, i64), Error>

Delete a transaction. Returns deleted transaction and server_knowledge for delta requests

Source

pub async fn import_transactions( &self, plan_id: PlanId, ) -> Result<Vec<Uuid>, Error>

Imports available transactions on all linked accounts for the given plan. The response for this endpoint contains the transaction ids that have been imported.

Source§

impl Client

Source

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;
Source

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.

Source

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.

Source

pub async fn update_transaction( &self, plan_id: PlanId, tx_id: &str, transaction: ExistingTransaction, ) -> Result<(Transaction, i64), Error>

Updates a single transaction. Returns the updated transaction and server knowledge.

Source

pub async fn create_scheduled_transaction( &self, plan_id: PlanId, scheduled_transaction: SaveScheduledTransaction, ) -> Result<ScheduledTransaction, Error>

Creates a scheduled transaction.

Source

pub async fn update_scheduled_transaction( &self, plan_id: PlanId, scheduled_transaction_id: Uuid, scheduled_transaction: SaveScheduledTransaction, ) -> Result<ScheduledTransaction, Error>

Updates a scheduled transaction.

Source

pub async fn delete_scheduled_transaction( &self, plan_id: PlanId, scheduled_transaction_id: Uuid, ) -> Result<ScheduledTransaction, Error>

Deletes a scheduled transaction.

Source§

impl Client

Source

pub async fn get_user(&self) -> Result<User, Error>

Returns authenticated user information.

Trait Implementations§

Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more