Private
Public Access
1
0
Files
Kordophone/kordophone/src/api/mod.rs

64 lines
1.7 KiB
Rust
Raw Normal View History

2025-05-15 20:11:10 -07:00
pub use crate::model::{Conversation, ConversationID, Message, MessageID, OutgoingMessage};
2024-04-21 15:14:16 -07:00
use async_trait::async_trait;
2025-05-15 20:11:10 -07:00
use bytes::Bytes;
use futures_util::Stream;
pub mod auth;
pub use crate::api::auth::{AuthenticationStore, InMemoryAuthenticationStore};
use crate::model::JwtToken;
2024-04-20 18:17:55 -07:00
2024-04-24 23:41:42 -07:00
pub mod http_client;
pub use http_client::HTTPAPIClient;
pub mod event_socket;
pub use event_socket::EventSocket;
use self::http_client::Credentials;
2025-05-15 20:11:10 -07:00
use core::error::Error as StdError;
use std::{fmt::Debug, io::BufRead};
2024-04-24 23:41:42 -07:00
2024-04-21 15:14:16 -07:00
#[async_trait]
2024-04-20 18:17:55 -07:00
pub trait APIInterface {
2025-05-02 14:22:43 -07:00
type Error: Debug;
2025-05-15 20:11:10 -07:00
type ResponseStream: Stream<Item = Result<Bytes, Self::Error>>;
2024-04-20 18:17:55 -07:00
2024-04-21 15:14:16 -07:00
// (GET) /version
async fn get_version(&mut self) -> Result<String, Self::Error>;
2025-05-15 20:11:10 -07:00
2024-04-21 15:14:16 -07:00
// (GET) /conversations
async fn get_conversations(&mut self) -> Result<Vec<Conversation>, Self::Error>;
2025-01-20 19:43:21 -08:00
// (GET) /messages
async fn get_messages(
2025-05-15 20:11:10 -07:00
&mut self,
conversation_id: &ConversationID,
limit: Option<u32>,
before: Option<MessageID>,
after: Option<MessageID>,
) -> Result<Vec<Message>, Self::Error>;
2025-01-20 19:43:21 -08:00
2025-05-02 12:03:56 -07:00
// (POST) /sendMessage
async fn send_message(
2025-05-15 20:11:10 -07:00
&mut self,
2025-05-02 14:22:43 -07:00
outgoing_message: &OutgoingMessage,
2025-05-02 12:03:56 -07:00
) -> Result<Message, Self::Error>;
2025-05-15 20:11:10 -07:00
// (GET) /attachment
async fn fetch_attachment_data(
&mut self,
guid: &String,
preview: bool,
2025-05-15 20:11:10 -07:00
) -> Result<Self::ResponseStream, Self::Error>;
// (POST) /authenticate
async fn authenticate(&mut self, credentials: Credentials) -> Result<JwtToken, Self::Error>;
// (WS) /updates
2025-05-15 20:11:10 -07:00
async fn open_event_socket(
&mut self,
update_seq: Option<u64>,
) -> Result<impl EventSocket, Self::Error>;
}