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
impl SureClient
Sourcepub async fn get_account(&self, id: &AccountId) -> ApiResult<AccountDetail>
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);Sourcepub fn get_accounts<'f1>(&'f1 self) -> SureClientGetAccountsBuilder<'f1>
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
impl SureClient
Sourcepub async fn delete_account(&self, id: &AccountId) -> ApiResult<DeleteResponse>
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);Sourcepub fn create_account<'f1>(&'f1 self) -> SureClientCreateAccountBuilder<'f1>
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 namebalance- The initial account balanceattributes- Type-specific attributes that determine the account kindcurrency- Optional currency code (defaults to family currency if not provided)institution_name- Optional name of the financial institutioninstitution_domain- Optional domain of the financial institutionnotes- 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);Sourcepub fn update_account<'f1, 'f2>(
&'f1 self,
) -> SureClientUpdateAccountBuilder<'f1, 'f2>
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 updatename- Optional new account namebalance- Optional new balanceinstitution_name- Optional new institution nameinstitution_domain- Optional new institution domainnotes- Optional new notesattributes- 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
impl SureClient
Sourcepub fn signup<'f1>(&'f1 self) -> SureClientSignupBuilder<'f1>
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 informationinvite_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);Sourcepub fn login<'f1>(&'f1 self) -> SureClientLoginBuilder<'f1>
pub fn login<'f1>(&'f1 self) -> SureClientLoginBuilder<'f1>
Log in a user
Authenticates a user with email and password.
§Arguments
email- Email addresspassword- Passworddevice- Device informationotp_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);Sourcepub fn refresh_token<'f1>(&'f1 self) -> SureClientRefreshTokenBuilder<'f1>
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 tokendevice- 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
impl SureClient
Sourcepub async fn get_category(&self, id: &CategoryId) -> ApiResult<CategoryDetail>
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.
Sourcepub fn get_categories<'f1, 'f2>(
&'f1 self,
) -> SureClientGetCategoriesBuilder<'f1, 'f2>
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
impl SureClient
Sourcepub async fn delete_category(
&self,
id: &CategoryId,
) -> ApiResult<DeleteResponse>
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);Sourcepub fn create_category<'f1>(&'f1 self) -> SureClientCreateCategoryBuilder<'f1>
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);Sourcepub fn update_category<'f1, 'f2>(
&'f1 self,
) -> SureClientUpdateCategoryBuilder<'f1, 'f2>
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 updaterequest- 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
impl SureClient
Sourcepub async fn get_chat(&self, id: &Uuid) -> ApiResult<ChatDetail>
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());Sourcepub async fn delete_chat(&self, id: &Uuid) -> ApiResult<()>
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");Sourcepub async fn retry_message(&self, chat_id: &Uuid) -> ApiResult<RetryResponse>
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);Sourcepub fn get_chats<'f1>(&'f1 self) -> SureClientGetChatsBuilder<'f1>
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?;Sourcepub fn create_chat<'f1>(&'f1 self) -> SureClientCreateChatBuilder<'f1>
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 messagemodel- 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);Sourcepub fn update_chat<'f1, 'f2>(&'f1 self) -> SureClientUpdateChatBuilder<'f1, 'f2>
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 updatetitle- 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);Sourcepub fn create_message<'f1, 'f2>(
&'f1 self,
) -> SureClientCreateMessageBuilder<'f1, 'f2>
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 tocontent- Message contentmodel- 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
impl SureClient
Sourcepub async fn get_merchant(&self, id: &MerchantId) -> ApiResult<MerchantDetail>
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);Sourcepub fn get_merchants<'f1>(&'f1 self) -> SureClientGetMerchantsBuilder<'f1>
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
impl SureClient
Sourcepub async fn delete_merchant(
&self,
id: &MerchantId,
) -> ApiResult<DeleteResponse>
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);Sourcepub fn create_merchant<'f1>(&'f1 self) -> SureClientCreateMerchantBuilder<'f1>
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);Sourcepub fn update_merchant<'f1, 'f2>(
&'f1 self,
) -> SureClientUpdateMerchantBuilder<'f1, 'f2>
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 updatename- Updated merchant namecolor- 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
impl SureClient
Sourcepub async fn trigger_sync(&self) -> ApiResult<SyncResponse>
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
impl SureClient
Sourcepub async fn get_transaction(
&self,
id: &TransactionId,
) -> ApiResult<Transaction>
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);Sourcepub async fn delete_transaction(
&self,
id: &TransactionId,
) -> ApiResult<DeleteResponse>
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);Sourcepub 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>
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 IDaccount_ids- Filter by multiple account IDscategory_id- Filter by single category IDcategory_ids- Filter by multiple category IDsmerchant_id- Filter by single merchant IDmerchant_ids- Filter by multiple merchant IDstag_ids- Filter by tag IDsstart_date- Filter transactions from this date (inclusive)end_date- Filter transactions until this date (inclusive)min_amount- Filter by minimum amountmax_amount- Filter by maximum amounttransaction_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?;Sourcepub fn create_transaction<'f1>(
&'f1 self,
) -> SureClientCreateTransactionBuilder<'f1>
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 notescurrency- Currency code (defaults to family currency)category_id- Category IDmerchant_id- Merchant IDnature- 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);Sourcepub fn update_transaction<'f1, 'f2>(
&'f1 self,
) -> SureClientUpdateTransactionBuilder<'f1, 'f2>
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 updatedate- Transaction dateamount- Transaction amountname- Transaction name/descriptionnotes- Additional notescurrency- Currency codecategory_id- Category IDmerchant_id- Merchant IDnature- Transaction naturetag_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
impl SureClient
Sourcepub async fn get_usage(&self) -> ApiResult<UsageResponse>
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
impl SureClient
Sourcepub fn new<T: Into<Auth>>(client: Client, auth: T, base_url: Url) -> Self
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 requestsauth- 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
impl Clone for SureClient
Source§fn clone(&self) -> SureClient
fn clone(&self) -> SureClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more