1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//! # Sure API Client
//!
//! A type-safe Rust client for the Sure API, providing comprehensive access to
//! financial data including transactions, categories, accounts, chat functionality, and authentication.
//!
//! ## Features
//!
//! - **Type-safe API**: Compile-time guarantees prevent common errors
//! - **Comprehensive error handling**: Detailed, actionable error types
//! - **Full async/await support**: Built on tokio and reqwest
//! - **Complete API coverage**: Accounts, transactions, categories, chats, authentication, sync, and usage
//! - **UUID-based identifiers**: Type-safe wrappers for all IDs
//! - **Pagination support**: Built-in pagination handling for list endpoints
//!
//! ## Quick Start
//!
//! ### Using API Key Authentication
//! ```no_run
//! use sure_client_rs::{SureClient, Auth};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create a client with your API key
//! let client = SureClient::new(
//! reqwest::Client::new(),
//! Auth::api_key("your_api_key"),
//! "http://localhost:3000".to_string().parse().unwrap(),
//! );
//!
//! // List all categories
//! let categories = client.get_categories().call().await?;
//! for category in categories.items.categories {
//! println!("{}: {}", category.name, category.color);
//! }
//!
//! // List recent transactions
//! let transactions = client.get_transactions()
//! .page(1)
//! .per_page(25)
//! .call()
//! .await?;
//!
//! for transaction in transactions.items.transactions {
//! println!("{}: {} {}",
//! transaction.name,
//! transaction.amount,
//! transaction.currency
//! );
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ### Using Bearer Token Authentication
//! ```no_run
//! use sure_client_rs::{SureClient, Auth};
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create a client with a JWT bearer token
//! 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?;
//! for category in categories.items.categories {
//! println!("{}: {}", category.name, category.color);
//! }
//!
//! Ok(())
//! }
//! ```
//!
//! ## Authentication
//!
//! The Sure API supports two authentication methods:
//!
//! ### API Key Authentication (X-Api-Key header)
//! ```no_run
//! 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(),
//! );
//! ```
//!
//! ### Bearer Token Authentication (Authorization header)
//! ```no_run
//! 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(),
//! );
//! ```
//!
//! ## Working with Categories
//!
//! ```no_run
//! use sure_client_rs::{SureClient, BearerToken, CategoryId};
//! use uuid::Uuid;
//!
//! # async fn example(client: SureClient) -> Result<(), Box<dyn std::error::Error>> {
//! // List the first page of categories
//! let categories = client.get_categories()
//! .page(1)
//! .per_page(25)
//! .call()
//! .await?;
//!
//! // Get a specific category
//! let category_id = CategoryId::new(Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap());
//! let category = client.get_category(&category_id).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Working with Transactions
//!
//! ```no_run
//! use sure_client_rs::{SureClient, BearerToken, AccountId};
//! use chrono::{DateTime, TimeZone, Utc};
//! use rust_decimal::Decimal;
//! use uuid::Uuid;
//!
//! # async fn example(client: SureClient) -> Result<(), Box<dyn std::error::Error>> {
//! // Create a transaction using the builder pattern
//! 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?;
//!
//! // Update a transaction
//! let updated = client.update_transaction()
//! .id(&transaction.id)
//! .notes("Updated notes".to_string())
//! .call()
//! .await?;
//!
//! // Delete a transaction
//! let response = client.delete_transaction(&transaction.id).await?;
//! # Ok(())
//! # }
//! ```
//!
//! ## Error Handling
//!
//! The client uses a comprehensive error type that covers both API-level and
//! client-level errors:
//!
//! ```no_run
//! use sure_client_rs::{SureClient, ApiError};
//!
//! # async fn example(client: SureClient) -> Result<(), Box<dyn std::error::Error>> {
//! match client.get_categories().call().await {
//! Ok(categories) => {
//! // Handle success
//! }
//! Err(ApiError::Unauthorized { message }) => {
//! // Handle authentication error
//! }
//! Err(ApiError::NotFound { message }) => {
//! // Handle not found error
//! }
//! Err(ApiError::RateLimited { message }) => {
//! // Handle rate limiting
//! }
//! Err(e) => {
//! // Handle other errors
//! }
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ## Development and Testing
//!
//! For local development, you can configure the client to use a different base URL:
//!
//! ```no_run
//! use sure_client_rs::{SureClient, BearerToken};
//!
//! let client = SureClient::new(
//! reqwest::Client::new(),
//! BearerToken::new("your_api_key"),
//! "http://localhost:3000".to_string().parse().unwrap(),
//! );
//! ```
// Module declarations
pub
// Public re-exports
pub use SureClient;
pub use ;
pub use ;