SureClient

Struct SureClient 

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

The main Sure API client

This client provides access to all Sure API endpoints. It handles authentication, request execution, and error handling.

The API supports two authentication methods:

  • Bearer token (JWT) via Authorization header
  • API key via X-Api-Key header

§Example with API Key

use sure_client_rs::{SureClient, Auth};

let client = SureClient::new(
    reqwest::Client::new(),
    Auth::api_key("your_api_key"),
    "http://localhost:3000".to_string().parse().unwrap(),
);

let categories = client.get_categories().call().await?;

§Example with Bearer Token

use sure_client_rs::{SureClient, Auth};

let client = SureClient::new(
    reqwest::Client::new(),
    Auth::bearer("your_jwt_token"),
    "http://localhost:3000".to_string().parse().unwrap(),
);

let categories = client.get_categories().call().await?;

Implementations§

Source§

impl SureClient

Source

pub async fn get_account(&self, id: &AccountId) -> ApiResult<AccountDetail>

Get a specific account by ID

Retrieves detailed information about a single account.

§Arguments
  • id - The account ID to retrieve
§Returns

Detailed account information.

§Errors

Returns ApiError::NotFound if the account doesn’t exist. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, AccountId};
use uuid::Uuid;

let account_id = AccountId::new(Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap());
let account = client.get_account(&account_id).await?;

println!("Account: {}", account.name);
println!("Balance: {}", account.balance);
Source

pub fn get_accounts<'f1>(&'f1 self) -> SureClientGetAccountsBuilder<'f1>

List accounts

Retrieves a paginated list of accounts.

§Arguments
  • page - Page number (default: 1)
  • per_page - Items per page (default: 25, max: 100)
§Returns

A paginated response containing accounts and pagination metadata.

§Errors

Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};

// Use defaults (page 1, per_page 25)
let response = client.get_accounts().call().await?;

for account in response.items.accounts {
    println!("{}: {:?} {:?}", account.name, account.balance, account.currency);
}

// Or customize parameters using the builder
let response = client.get_accounts().page(2).per_page(50).call().await?;
Source§

impl SureClient

Source

pub async fn delete_account(&self, id: &AccountId) -> ApiResult<DeleteResponse>

Delete an account

Permanently deletes an account.

§Arguments
  • id - The account ID to delete
§Returns

A confirmation message.

§Errors

Returns ApiError::NotFound if the account doesn’t exist. Returns ApiError::ValidationError if the account cannot be deleted (e.g., linked account). Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, AccountId};
use uuid::Uuid;

let account_id = AccountId::new(Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap());
let response = client.delete_account(&account_id).await?;

println!("Deleted: {}", response.message);
Source

pub fn create_account<'f1>(&'f1 self) -> SureClientCreateAccountBuilder<'f1>

Create a new account

Creates a new account with type-specific attributes. The account kind is automatically derived from the attributes you provide.

§Arguments
  • name - The account name
  • balance - The initial account balance
  • attributes - Type-specific attributes that determine the account kind
  • currency - Optional currency code (defaults to family currency if not provided)
  • institution_name - Optional name of the financial institution
  • institution_domain - Optional domain of the financial institution
  • notes - Optional additional notes
§Returns

The newly created account with full details.

§Errors

Returns ApiError::ValidationError if required fields are missing or invalid. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use sure_client_rs::models::account::{
    AccountableAttributes, DepositoryAttributes, DepositorySubtype
};
use rust_decimal::Decimal;

let account = client.create_account()
    .name("Checking Account".to_string())
    .balance(Decimal::new(100000, 2)) // $1,000.00
    .attributes(AccountableAttributes::Depository(DepositoryAttributes {
        subtype: Some(DepositorySubtype::Checking),
        locked_attributes: None,
    }))
    .currency(iso_currency::Currency::USD)
    .institution_name("Bank of Example".to_string())
    .call()
    .await?;

println!("Created account: {}", account.name);
Source

pub fn update_account<'f1, 'f2>( &'f1 self, ) -> SureClientUpdateAccountBuilder<'f1, 'f2>

Update an account

Updates an existing account with new values. Only fields provided in the request will be updated. If updating attributes, the entire attributes object must be provided as it replaces the existing attributes.

§Arguments
  • id - The account ID to update
  • name - Optional new account name
  • balance - Optional new balance
  • institution_name - Optional new institution name
  • institution_domain - Optional new institution domain
  • notes - Optional new notes
  • attributes - Optional new account-specific attributes (replaces existing)
§Returns

The updated account.

§Errors

Returns ApiError::NotFound if the account doesn’t exist. Returns ApiError::ValidationError if the provided values are invalid. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, AccountId};
use sure_client_rs::models::account::{
    AccountableAttributes, DepositoryAttributes, DepositorySubtype
};
use rust_decimal::Decimal;
use uuid::Uuid;

let account_id = AccountId::new(Uuid::new_v4());

// Update just the name and balance
let account = client.update_account()
    .id(&account_id)
    .name("Updated Account Name".to_string())
    .balance(Decimal::new(150000, 2)) // $1,500.00
    .call()
    .await?;

// Update attributes
let updated = client.update_account()
    .id(&account_id)
    .attributes(AccountableAttributes::Depository(DepositoryAttributes {
        subtype: Some(DepositorySubtype::Savings),
        locked_attributes: None,
    }))
    .call()
    .await?;

println!("Updated account: {}", account.name);
Source§

impl SureClient

Source

pub fn signup<'f1>(&'f1 self) -> SureClientSignupBuilder<'f1>

Sign up a new user

Creates a new user account with the provided credentials.

§Arguments
  • user - User data (email, password, first_name, last_name)
  • device - Device information
  • invite_code - Invite code (required if invite codes are enabled)
§Returns

Authentication response with access token and user information.

§Errors

Returns ApiError::Forbidden if invite code is required or invalid. Returns ApiError::ValidationError if validation fails. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use sure_client_rs::models::auth::{SignupUserData, DeviceInfo};

let response = client.signup()
    .user(SignupUserData {
        email: "user@example.com".to_string(),
        password: "SecureP@ssw0rd".to_string(),
        first_name: "John".to_string(),
        last_name: "Doe".to_string(),
    })
    .device(DeviceInfo {
        device_id: "device123".to_string(),
        device_name: "My Device".to_string(),
        device_type: "web".to_string(),
        os_version: "macOS 12.0".to_string(),
        app_version: "1.0.0".to_string(),
    })
    .call()
    .await?;

println!("User created: {}", response.user.email);
Source

pub fn login<'f1>(&'f1 self) -> SureClientLoginBuilder<'f1>

Log in a user

Authenticates a user with email and password.

§Arguments
  • email - Email address
  • password - Password
  • device - Device information
  • otp_code - OTP code (required if user has MFA enabled)
§Returns

Authentication response with access token and user information.

§Errors

Returns ApiError::Unauthorized if credentials are invalid or MFA is required. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use sure_client_rs::models::auth::DeviceInfo;

let response = client.login()
    .email("user@example.com".to_string())
    .password("SecureP@ssw0rd".to_string())
    .device(DeviceInfo {
        device_id: "device123".to_string(),
        device_name: "My Device".to_string(),
        device_type: "web".to_string(),
        os_version: "macOS 12.0".to_string(),
        app_version: "1.0.0".to_string(),
    })
    .call()
    .await?;

println!("Logged in as: {}", response.user.email);
Source

pub fn refresh_token<'f1>(&'f1 self) -> SureClientRefreshTokenBuilder<'f1>

Refresh an access token

Refreshes an expired access token using a refresh token.

§Arguments
  • refresh_token - Refresh token
  • device - Device information
§Returns

New authentication tokens.

§Errors

Returns ApiError::BadRequest if refresh token is missing. Returns ApiError::Unauthorized if refresh token is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use sure_client_rs::models::auth::RefreshDeviceInfo;

let response = client.refresh_token()
    .refresh_token("refresh_token_here".to_string())
    .device(RefreshDeviceInfo {
        device_id: "device123".to_string(),
    })
    .call()
    .await?;

println!("Token refreshed, expires in: {}s", response.expires_in.as_secs());
Source§

impl SureClient

Source

pub async fn get_category(&self, id: &CategoryId) -> ApiResult<CategoryDetail>

Get a specific category by ID

Retrieves detailed information about a single category, including parent and subcategory information.

§Arguments
  • id - The category ID to retrieve
§Returns

Detailed category information including parent and subcategory count.

§Errors

Returns ApiError::NotFound if the category doesn’t exist. Returns ApiError::Unauthorized if the bearer token is invalid or expired. Returns ApiError::Network if the request fails due to network issues.

Source

pub fn get_categories<'f1, 'f2>( &'f1 self, ) -> SureClientGetCategoriesBuilder<'f1, 'f2>

List categories with optional filters

Retrieves a paginated list of categories. Results can be filtered by classification, parent category, or limited to root categories only.

§Arguments
  • page - Page number (default: 1)
  • per_page - Items per page (default: 25, max: 100)
  • classification - Filter by classification (income or expense)
  • roots_only - Return only root categories (default: false)
  • parent_id - Filter by parent category ID
§Returns

A paginated response containing categories and pagination metadata.

§Errors

Returns ApiError::Unauthorized if the bearer token is invalid or expired. Returns ApiError::Network if the request fails due to network issues.

Source§

impl SureClient

Source

pub async fn delete_category( &self, id: &CategoryId, ) -> ApiResult<DeleteResponse>

Delete a category

Permanently deletes a category.

§Arguments
  • id - The category ID to delete
§Returns

A confirmation message.

§Errors

Returns ApiError::NotFound if the category doesn’t exist. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, CategoryId};
use uuid::Uuid;

let category_id = CategoryId::new(Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap());
let response = client.delete_category(&category_id).await?;

println!("Deleted: {}", response.message);
Source

pub fn create_category<'f1>(&'f1 self) -> SureClientCreateCategoryBuilder<'f1>

Create a new category

Creates a new category with the specified details.

§Arguments
  • request - The category creation request containing all required fields
§Returns

The newly created category with full details.

§Errors

Returns ApiError::ValidationError if required fields are missing or invalid. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use sure_client_rs::models::category::Classification;

let category = client.create_category()
    .name("Groceries".to_string())
    .classification(Classification::Expense)
    .color("#FF5733".to_string())
    .lucide_icon("shopping-cart".to_string())
    .call()
    .await?;

println!("Created category: {}", category.name);
Source

pub fn update_category<'f1, 'f2>( &'f1 self, ) -> SureClientUpdateCategoryBuilder<'f1, 'f2>

Update a category

Updates an existing category with new values. Only fields provided in the request will be updated.

§Arguments
  • id - The category ID to update
  • request - The category update request containing fields to update
§Returns

The updated category.

§Errors

Returns ApiError::NotFound if the category doesn’t exist. Returns ApiError::ValidationError if the provided values are invalid. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, CategoryId};
use uuid::Uuid;

let category_id = CategoryId::new(Uuid::new_v4());

let category = client.update_category()
    .id(&category_id)
    .name("Updated Category Name".to_string())
    .color("#00FF00".to_string())
    .call()
    .await?;

println!("Updated category: {}", category.name);
Source§

impl SureClient

Source

pub async fn get_chat(&self, id: &Uuid) -> ApiResult<ChatDetail>

Get a specific chat

Retrieves detailed information about a chat including its messages.

§Arguments
  • id - The chat ID to retrieve
§Returns

Detailed chat information including messages.

§Errors

Returns ApiError::NotFound if the chat doesn’t exist. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use uuid::Uuid;

let chat_id = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap();
let chat = client.get_chat(&chat_id).await?;

println!("Chat: {} with {} messages", chat.title, chat.messages.len());
Source

pub async fn delete_chat(&self, id: &Uuid) -> ApiResult<()>

Delete a chat

Permanently deletes a chat and all its messages.

§Arguments
  • id - The chat ID to delete
§Returns

Unit type on successful deletion.

§Errors

Returns ApiError::NotFound if the chat doesn’t exist. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use uuid::Uuid;

let chat_id = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap();
client.delete_chat(&chat_id).await?;
println!("Chat deleted");
Source

pub async fn retry_message(&self, chat_id: &Uuid) -> ApiResult<RetryResponse>

Retry the last assistant response

Retries generating the last assistant message in a chat.

§Arguments
  • chat_id - The chat ID to retry the response for
§Returns

Retry response with the new message ID.

§Errors

Returns ApiError::NotFound if the chat doesn’t exist. Returns ApiError::ValidationError if no assistant message is available to retry. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use uuid::Uuid;

let chat_id = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap();
let response = client.retry_message(&chat_id).await?;
println!("Retry started: {}", response.message);
Source

pub fn get_chats<'f1>(&'f1 self) -> SureClientGetChatsBuilder<'f1>

List chats

Retrieves a paginated list of chats.

§Arguments
  • page - Page number (default: 1)
  • per_page - Items per page (default: 25, max: 100)
§Returns

A paginated response containing chats and pagination metadata.

§Errors

Returns ApiError::Forbidden if AI features are disabled. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};

// Use defaults (page 1, per_page 25)
let response = client.get_chats().call().await?;

for chat in response.items.chats {
    println!("Chat: {} ({} messages)", chat.title, chat.message_count);
}

// Or customize parameters using the builder
let response = client.get_chats().page(2).per_page(50).call().await?;
Source

pub fn create_chat<'f1>(&'f1 self) -> SureClientCreateChatBuilder<'f1>

Create a new chat

Creates a new chat with an optional initial message.

§Arguments
  • title - Chat title (required)
  • message - Optional initial message
  • model - Optional OpenAI model identifier
§Returns

Detailed information about the created chat.

§Errors

Returns ApiError::ValidationError if validation fails. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};

let chat = client.create_chat()
    .title("Monthly budget review".to_string())
    .message("Help me analyze my spending".to_string())
    .call()
    .await?;

println!("Created chat: {}", chat.title);
Source

pub fn update_chat<'f1, 'f2>(&'f1 self) -> SureClientUpdateChatBuilder<'f1, 'f2>

Update a chat

Updates the title of an existing chat.

§Arguments
  • id - The chat ID to update
  • title - Updated chat title
§Returns

Updated chat information.

§Errors

Returns ApiError::NotFound if the chat doesn’t exist. Returns ApiError::ValidationError if validation fails. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use uuid::Uuid;

let chat_id = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap();

let chat = client.update_chat()
    .id(&chat_id)
    .title("Updated chat title".to_string())
    .call()
    .await?;

println!("Updated chat: {}", chat.title);
Source

pub fn create_message<'f1, 'f2>( &'f1 self, ) -> SureClientCreateMessageBuilder<'f1, 'f2>

Create a message in a chat

Sends a new message to a chat and triggers an AI response.

§Arguments
  • chat_id - The chat ID to send the message to
  • content - Message content
  • model - Optional model identifier
§Returns

The created message with response status.

§Errors

Returns ApiError::NotFound if the chat doesn’t exist. Returns ApiError::ValidationError if validation fails. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use uuid::Uuid;

let chat_id = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap();

let message = client.create_message()
    .chat_id(&chat_id)
    .content("What were my expenses last month?".to_string())
    .call()
    .await?;

println!("Message sent: {}", message.content);
Source§

impl SureClient

Source

pub async fn get_merchant(&self, id: &MerchantId) -> ApiResult<MerchantDetail>

Get a specific merchant by ID

Retrieves detailed information about a single merchant.

§Arguments
  • id - The merchant ID to retrieve
§Returns

Detailed merchant information.

§Errors

Returns ApiError::NotFound if the merchant doesn’t exist. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, MerchantId};
use uuid::Uuid;

let merchant_id = MerchantId::new(Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap());
let merchant = client.get_merchant(&merchant_id).await?;

println!("Merchant: {}", merchant.name);
Source

pub fn get_merchants<'f1>(&'f1 self) -> SureClientGetMerchantsBuilder<'f1>

List merchants

Retrieves a paginated list of merchants.

§Arguments
  • page - Page number (default: 1)
  • per_page - Items per page (default: 25, max: 100)
§Returns

A paginated response containing merchants and pagination metadata.

§Errors

Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};

// Use defaults (page 1, per_page 25)
let response = client.get_merchants().call().await?;

for merchant in response.items.merchants {
    println!("Merchant: {}", merchant.name);
}

// Or customize parameters using the builder
let response = client.get_merchants().page(2).per_page(50).call().await?;
Source§

impl SureClient

Source

pub async fn delete_merchant( &self, id: &MerchantId, ) -> ApiResult<DeleteResponse>

Delete a merchant

Permanently deletes a merchant.

§Arguments
  • id - The merchant ID to delete
§Returns

A confirmation message.

§Errors

Returns ApiError::NotFound if the merchant doesn’t exist. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, MerchantId};
use uuid::Uuid;

let merchant_id = MerchantId::new(Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap());
let response = client.delete_merchant(&merchant_id).await?;

println!("Deleted: {}", response.message);
Source

pub fn create_merchant<'f1>(&'f1 self) -> SureClientCreateMerchantBuilder<'f1>

Create a new merchant

Creates a new merchant with the specified details.

§Arguments
  • name - Merchant name (required)
  • color - Merchant color (hex code)
§Returns

The newly created merchant with full details.

§Errors

Returns ApiError::ValidationError if required fields are missing or invalid. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};

let merchant = client.create_merchant()
    .name("Starbucks".to_string())
    .color("#00704A".to_string())
    .call()
    .await?;

println!("Created merchant: {}", merchant.name);
Source

pub fn update_merchant<'f1, 'f2>( &'f1 self, ) -> SureClientUpdateMerchantBuilder<'f1, 'f2>

Update a merchant

Updates an existing merchant with new values. Only fields provided will be updated.

§Arguments
  • id - The merchant ID to update
  • name - Updated merchant name
  • color - Updated merchant color (hex code)
§Returns

The updated merchant.

§Errors

Returns ApiError::NotFound if the merchant doesn’t exist. Returns ApiError::ValidationError if the provided values are invalid. Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, MerchantId};
use uuid::Uuid;

let merchant_id = MerchantId::new(Uuid::new_v4());

let merchant = client.update_merchant()
    .id(&merchant_id)
    .name("Updated Merchant Name".to_string())
    .color("#FF0000".to_string())
    .call()
    .await?;

println!("Updated merchant: {}", merchant.name);
Source§

impl SureClient

Source

pub async fn trigger_sync(&self) -> ApiResult<SyncResponse>

Trigger a family sync

Triggers a sync operation that will apply all active rules, sync all accounts, and auto-match transfers.

§Returns

Sync response with status information.

§Errors

Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Forbidden if the API key has insufficient scope. Returns ApiError::InternalServerError if the sync fails to start. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};

let response = client.trigger_sync().await?;
println!("Sync queued: {}", response.message);
Source§

impl SureClient

Source

pub async fn get_transaction( &self, id: &TransactionId, ) -> ApiResult<Transaction>

Get a specific transaction by ID

Retrieves detailed information about a single transaction.

§Arguments
  • id - The transaction ID to retrieve
§Returns

Detailed transaction information.

§Errors

Returns ApiError::NotFound if the transaction doesn’t exist. Returns ApiError::Unauthorized if the bearer token is invalid or expired. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, TransactionId};
use uuid::Uuid;

let transaction_id = TransactionId::new(Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap());
let transaction = client.get_transaction(&transaction_id).await?;

println!("Transaction: {}", transaction.name);
println!("Amount: {} {}", transaction.amount, transaction.currency);
Source

pub async fn delete_transaction( &self, id: &TransactionId, ) -> ApiResult<DeleteResponse>

Delete a transaction

Permanently deletes a transaction.

§Arguments
  • id - The transaction ID to delete
§Returns

A confirmation message.

§Errors

Returns ApiError::NotFound if the transaction doesn’t exist. Returns ApiError::Unauthorized if the bearer token is invalid or expired. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, TransactionId};
use uuid::Uuid;

let transaction_id = TransactionId::new(Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap());
let response = client.delete_transaction(&transaction_id).await?;

println!("Deleted: {}", response.message);
Source

pub fn get_transactions<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8, 'f9, 'f10, 'f11>( &'f1 self, ) -> SureClientGetTransactionsBuilder<'f1, 'f2, 'f3, 'f4, 'f5, 'f6, 'f7, 'f8, 'f9, 'f10, 'f11>

List transactions with optional filters

Retrieves a paginated list of transactions. Results can be filtered by various criteria including date range, amount, account, category, merchant, tags, and search text.

§Arguments
  • page - Page number (default: 1)
  • per_page - Items per page (default: 25, max: 100)
  • account_id - Filter by single account ID
  • account_ids - Filter by multiple account IDs
  • category_id - Filter by single category ID
  • category_ids - Filter by multiple category IDs
  • merchant_id - Filter by single merchant ID
  • merchant_ids - Filter by multiple merchant IDs
  • tag_ids - Filter by tag IDs
  • start_date - Filter transactions from this date (inclusive)
  • end_date - Filter transactions until this date (inclusive)
  • min_amount - Filter by minimum amount
  • max_amount - Filter by maximum amount
  • transaction_type - Filter by transaction type (income or expense)
  • search - Search by name, notes, or merchant name
§Returns

A paginated response containing transactions and pagination metadata.

§Errors

Returns ApiError::Unauthorized if the bearer token is invalid or expired. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use chrono::{DateTime, Utc};

// Use defaults (page 1, per_page 25, no filters)
let response = client.get_transactions().call().await?;

// Or customize with builder
use chrono::TimeZone;
let start = Utc.with_ymd_and_hms(2024, 1, 1, 0, 0, 0).unwrap();
let end = Utc.with_ymd_and_hms(2024, 12, 31, 23, 59, 59).unwrap();
let response = client.get_transactions()
    .page(2)
    .per_page(50)
    .start_date(&start)
    .end_date(&end)
    .search("coffee")
    .call()
    .await?;
Source

pub fn create_transaction<'f1>( &'f1 self, ) -> SureClientCreateTransactionBuilder<'f1>

Create a new transaction

Creates a new transaction with the specified details.

§Arguments
  • account_id - Account ID (required)
  • date - Transaction date (required)
  • amount - Transaction amount (required)
  • name - Transaction name/description (required)
  • notes - Additional notes
  • currency - Currency code (defaults to family currency)
  • category_id - Category ID
  • merchant_id - Merchant ID
  • nature - Transaction nature (determines sign)
  • tag_ids - Tag IDs
§Returns

The newly created transaction.

§Errors

Returns ApiError::ValidationError if required fields are missing or invalid. Returns ApiError::Unauthorized if the bearer token is invalid or expired. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, AccountId};
use chrono::{DateTime, TimeZone, Utc};
use rust_decimal::Decimal;
use uuid::Uuid;

let transaction = client.create_transaction()
    .account_id(AccountId::new(Uuid::new_v4()))
    .date(Utc.with_ymd_and_hms(2024, 1, 15, 12, 0, 0).unwrap())
    .amount(Decimal::new(4250, 2)) // $42.50
    .name("Grocery Store".to_string())
    .currency(iso_currency::Currency::USD)
    .call()
    .await?;

println!("Created transaction: {}", transaction.id);
Source

pub fn update_transaction<'f1, 'f2>( &'f1 self, ) -> SureClientUpdateTransactionBuilder<'f1, 'f2>

Update a transaction

Updates an existing transaction with new values. Only fields provided will be updated.

§Arguments
  • id - The transaction ID to update
  • date - Transaction date
  • amount - Transaction amount
  • name - Transaction name/description
  • notes - Additional notes
  • currency - Currency code
  • category_id - Category ID
  • merchant_id - Merchant ID
  • nature - Transaction nature
  • tag_ids - Tag IDs
§Returns

The updated transaction.

§Errors

Returns ApiError::NotFound if the transaction doesn’t exist. Returns ApiError::ValidationError if the provided values are invalid. Returns ApiError::Unauthorized if the bearer token is invalid or expired. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken, TransactionId};
use rust_decimal::Decimal;
use uuid::Uuid;

let transaction_id = TransactionId::new(Uuid::new_v4());

let transaction = client.update_transaction()
    .id(&transaction_id)
    .amount(Decimal::new(5000, 2)) // Update to $50.00
    .notes("Updated notes".to_string())
    .call()
    .await?;

println!("Updated transaction: {}", transaction.id);
Source§

impl SureClient

Source

pub async fn get_usage(&self) -> ApiResult<UsageResponse>

Get API usage information

Returns usage statistics for API key authentication or a message for OAuth authentication.

§Returns

Usage response containing either API key usage information or OAuth authentication message.

§Errors

Returns ApiError::Unauthorized if the API key is invalid. Returns ApiError::Network if the request fails due to network issues.

§Example
use sure_client_rs::{SureClient, BearerToken};
use sure_client_rs::models::usage::UsageResponse;

let response = client.get_usage().await?;

match response {
    UsageResponse::ApiKey(usage) => {
        println!("API Key: {}", usage.api_key.name);
        println!("Current count: {}", usage.rate_limit.current_count);
        if let Some(remaining) = usage.rate_limit.remaining {
            println!("Remaining requests: {}", remaining);
        }
    }
    UsageResponse::OAuth(info) => {
        println!("OAuth: {}", info.message);
    }
}
Source§

impl SureClient

Source

pub fn new<T: Into<Auth>>(client: Client, auth: T, base_url: Url) -> Self

Create a new Sure API client

§Arguments
  • client - A configured reqwest::Client for making HTTP requests
  • auth - Authentication method (Bearer token or API key)
  • base_url - base url to target
§Example with API Key
use sure_client_rs::{SureClient, Auth};

let client = SureClient::new(
    reqwest::Client::new(),
    Auth::api_key("your_api_key"),
    "http://localhost:3000".to_string().parse().unwrap()
);
§Example with Bearer Token
use sure_client_rs::{SureClient, Auth};

let client = SureClient::new(
    reqwest::Client::new(),
    Auth::bearer("your_token"),
    "http://localhost:3000".to_string().parse().unwrap()
);

Trait Implementations§

Source§

impl Clone for SureClient

Source§

fn clone(&self) -> SureClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SureClient

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<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