13 releases
new 0.1.0-alpha.4 | Mar 12, 2025 |
---|---|
0.1.0-alpha.3 | Mar 10, 2025 |
0.0.4-alpha.2 | Nov 25, 2024 |
0.0.1 | Nov 23, 2022 |
0.0.1-alpha.2 | Jul 29, 2021 |
#29 in Finance
536 downloads per month
115KB
2.5K
SLoC
xero-rs
Description
A Xero API client library for Rust. This library is in very early days and the API is not stable, it may change without notice.
This was put together as part of the requirements for a private project so I will be implementing features as-needed, but all contributions are welcome.
Features
- Client credential & code flow authorization support
- Generic GET, PUT, and POST methods for custom requests
- Type-safe API endpoint construction via
XeroEndpoint
enum - Uses rust_decimal for storing prices/decimal values
- Rich error diagnostics via miette integration
- Well tested (that's the goal, at least)
Error Handling
xero-rs
uses miette for rich error diagnostics. The Error
type implements the Diagnostic
trait, which means you get detailed error reports with context and help text.
// Example of handling errors with miette
use xero_rs::error::Result;
fn do_something() -> Result<()> {
// If this fails, you'll get a rich diagnostic error
let client = xero_rs::Client::from_client_credentials(...)?;
// No need to call .into_diagnostic() when using xero_rs::error::Result
Ok(())
}
When using with miette's own Result
type, you'll need to use .into_diagnostic()
:
use miette::{Result, IntoDiagnostic};
fn do_something() -> Result<()> {
// Converting to miette's Result requires .into_diagnostic()
let client = xero_rs::Client::from_client_credentials(...).into_diagnostic()?;
Ok(())
}
Currently Implemented
This has been implemented so far:
- OAuth2 Authentication (Client Credentials, Authorization Code Flow)
- Type-safe API URL construction with
XeroEndpoint
- List authorized connections (tennants)
- Quotes
- List
- Get by ID
- Invoices
- List
- Get by ID
- Purchase Orders
- List
- Get by ID
- Create
- Contacts
- List
Dependencies
~10–26MB
~311K SLoC