nodesty_api_library/services/
user.rs

1use reqwest::{Error, Method};
2use std::sync::Arc;
3
4use crate::models::{
5    user::{
6        Invoice,
7        Service,
8        Session,
9        Ticket,
10        User,
11        UserInvoiceSummary,
12        UserTicketSummary,
13    },
14    ApiResponse,
15};
16
17use crate::NodestyApiClient;
18
19pub struct UserApiService {
20    client: Arc<NodestyApiClient>,
21}
22
23impl UserApiService {
24    pub fn new(client: Arc<NodestyApiClient>) -> Self {
25        Self {
26            client
27        }
28    }
29    pub async fn get_services(&self) -> Result<ApiResponse<Vec<Service>>, Error> {
30        self.client.send_request(Method::GET, "/services", None).await
31    }
32
33    pub async fn get_ticket_by_id(
34        &self,
35        ticket_id: &str,
36    ) -> Result<ApiResponse<Ticket>, Error> {
37        self.client.send_request(Method::GET, &format!("/tickets/{}", ticket_id), None).await
38    }
39
40    pub async fn get_tickets(&self) -> Result<ApiResponse<Vec<UserTicketSummary>>, Error> {
41        self.client.send_request(Method::GET, "/tickets", None).await
42    }
43
44    pub async fn get_current_user(&self) -> Result<ApiResponse<User>, Error> {
45        self.client.send_request(Method::GET, "/users/@me", None).await
46    }
47
48    pub async fn get_invoice_by_id(
49        &self,
50        invoice_id: &str,
51    ) -> Result<ApiResponse<Invoice>, Error> {
52        self.client.send_request(Method::GET, &format!("/users/@me/invoices/{}", invoice_id), None).await
53    }
54
55    pub async fn get_invoices(&self) -> Result<ApiResponse<Vec<UserInvoiceSummary>>, Error> {
56        self.client.send_request(Method::GET, "/users/@me/invoices", None).await
57    }
58
59    pub async fn get_sessions(&self) -> Result<ApiResponse<Vec<Session>>, Error> {
60        self.client.send_request(Method::GET, "/users/@me/sessions", None).await
61    }
62}