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 all accounts. The second return value is server knowledge for delta requests.

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

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.

Source

pub fn with_timeout(self, timeout: Duration) -> Result<Self, Error>

Sets the request timeout. Rebuilds the underlying HTTP client.

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

Source

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

Returns all plan months. The second return value is server knowledge for delta requests.

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 all money movements. The second return value is server knowledge for delta requests.

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 all money movement groups. The second return value is server knowledge for delta requests.

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 all payees. The second return value is server knowledge for delta requests.

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 plans list with summary information.

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 single plan with all related entities. This resource is effectively a full plan export. The second return value is server knowledge for delta requests.

Source§

impl Client

Source

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.

Source

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

Returns a single transaction.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn get_scheduled_transactions( &self, plan_id: PlanId, ) -> GetScheduledTransactionsBuilder<'_>

Returns all scheduled transactions. The second return value is server knowledge for delta requests.

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: Uuid, ) -> 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.

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: Uuid, 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