BlueGit

ict rusty-teams

Files

rusty-teams / crates / chatsvc / src / pins / transport.rs

transport.rs

Initial commit
metis Daniel Däschle · pushed by metis · 7 weeks ago
06e0ae51 History
transport.rs 835 B Download Raw
1use session::{ApiResponse, Request, Scope, Session};
2
3use crate::error::Result;
4
5pub const CSA_RESOURCE: &str = "https://chatsvcagg.teams.microsoft.com";
6pub const CSA_SCOPE: &str = "user_impersonation";
7
8pub trait CsaTransport {
9 fn send(&self, request: Request) -> impl std::future::Future<Output = Result<ApiResponse>>;
10}
11
12pub struct SessionTransport {
13 session: Session,
14 scope: Scope,
15}
16
17impl SessionTransport {
18 pub fn new(session: &Session) -> Self {
19 SessionTransport {
20 session: session.clone(),
21 scope: Scope::new(CSA_RESOURCE, CSA_SCOPE),
22 }
23 }
24}
25
26impl CsaTransport for SessionTransport {
27 async fn send(&self, request: Request) -> Result<ApiResponse> {
28 let mut answers = self.session.batch(&[request], &self.scope).await?;
29 Ok(answers.remove(0))
30 }
31}