| 1 | use session::{ApiResponse, Request, Scope, Session}; |
| 2 | |
| 3 | use crate::error::Result; |
| 4 | |
| 5 | pub const CSA_RESOURCE: &str = "https://chatsvcagg.teams.microsoft.com"; |
| 6 | pub const CSA_SCOPE: &str = "user_impersonation"; |
| 7 | |
| 8 | pub trait CsaTransport { |
| 9 | fn send(&self, request: Request) -> impl std::future::Future<Output = Result<ApiResponse>>; |
| 10 | } |
| 11 | |
| 12 | pub struct SessionTransport { |
| 13 | session: Session, |
| 14 | scope: Scope, |
| 15 | } |
| 16 | |
| 17 | impl 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 | |
| 26 | impl 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 | } |