graph_http/blocking/
blocking_client.rs

1use crate::internal::GraphClientConfiguration;
2use graph_core::identity::ClientApplication;
3use reqwest::header::HeaderMap;
4use std::env::VarError;
5use std::ffi::OsStr;
6use std::fmt::{Debug, Formatter};
7
8#[derive(Clone)]
9pub struct BlockingClient {
10    pub(crate) inner: reqwest::blocking::Client,
11    pub(crate) client_application: Box<dyn ClientApplication>,
12    pub(crate) headers: HeaderMap,
13}
14
15impl BlockingClient {
16    pub fn new<AT: ToString>(access_token: AT) -> BlockingClient {
17        GraphClientConfiguration::new()
18            .access_token(access_token)
19            .build_blocking()
20    }
21
22    /// Create a new client and use the given environment variable
23    /// for the access token.
24    pub fn new_env<K: AsRef<OsStr>>(env_var: K) -> Result<BlockingClient, VarError> {
25        Ok(GraphClientConfiguration::new()
26            .access_token(std::env::var(env_var)?)
27            .build_blocking())
28    }
29
30    pub fn builder() -> GraphClientConfiguration {
31        GraphClientConfiguration::new()
32    }
33
34    pub fn headers(&self) -> &HeaderMap {
35        &self.headers
36    }
37}
38
39impl Default for BlockingClient {
40    fn default() -> Self {
41        GraphClientConfiguration::new().build_blocking()
42    }
43}
44
45impl Debug for BlockingClient {
46    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
47        f.debug_struct("BlockingClient")
48            .field("inner", &self.inner)
49            .field("headers", &self.headers)
50            .finish()
51    }
52}