| 1 | mod channels; |
| 2 | mod chats; |
| 3 | mod folders; |
| 4 | mod pinbar; |
| 5 | mod posts; |
| 6 | mod state; |
| 7 | mod teams; |
| 8 | pub(crate) mod transport; |
| 9 | |
| 10 | use session::Session; |
| 11 | |
| 12 | pub use folders::{Folder, FolderKind, Folders}; |
| 13 | pub use pinbar::PinnedMessage; |
| 14 | pub use posts::{PINNED_POSTS_PAGE_SIZE, PinnedPostsPage, parse_pinned_posts}; |
| 15 | pub use state::{PinnedChannels, PinnedChats}; |
| 16 | pub use teams::{ |
| 17 | ChannelLayout, ChannelTab, TeamLayout, TeamRights, parse_team_layout, parse_team_rights, |
| 18 | }; |
| 19 | pub use transport::{CSA_RESOURCE, CSA_SCOPE, CsaTransport, SessionTransport, SkypeTokenTransport}; |
| 20 | |
| 21 | pub const DEFAULT_REGION: &str = "emea"; |
| 22 | |
| 23 | pub struct Pins<T: CsaTransport = SessionTransport> { |
| 24 | transport: T, |
| 25 | base_url: String, |
| 26 | api_url: String, |
| 27 | } |
| 28 | |
| 29 | impl Pins<SessionTransport> { |
| 30 | pub fn new(session: &Session) -> Self { |
| 31 | Self::with_region(session, DEFAULT_REGION) |
| 32 | } |
| 33 | |
| 34 | pub fn with_region(session: &Session, region: &str) -> Self { |
| 35 | Pins::with_transport(SessionTransport::new(session), region) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | impl Pins<SkypeTokenTransport> { |
| 40 | pub fn with_skype_token(session: &Session) -> Self { |
| 41 | Pins::with_transport(SkypeTokenTransport::new(session), DEFAULT_REGION) |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | impl<T: CsaTransport> Pins<T> { |
| 46 | pub fn with_transport(transport: T, region: &str) -> Self { |
| 47 | Pins { |
| 48 | transport, |
| 49 | base_url: format!( |
| 50 | "https://teams.cloud.microsoft/api/csa/{region}/api/v1/teams/users/me" |
| 51 | ), |
| 52 | api_url: format!("https://teams.cloud.microsoft/api/csa/{region}/api/v1"), |
| 53 | } |
| 54 | } |
| 55 | } |