async fn request<T: Serialize>(
        &self,
        method: Method,
        path: &str,
        body: T,
        query_params: Option<Vec<(&str, &str)>>,
    ) -> Request {
        // confirm URL can parse before continuing
        let url = Url::parse(BASE_ENDPOINT).unwrap().join(&path).unwrap();

        // TODO-- use `self.token = Sheets::authenticate().await.unwrap()` to attempt to read token from cache
        // Note: this would require a mutable reference to `&mut self` in practically every method for `google_sheets::Sheets`
        if self.token.is_expired() {
            panic!("Token is expired");
        }

        let bearer_token =
            header::HeaderValue::from_str(&format!("Bearer {}", &self.token.as_str())).unwrap();

        // Set the default headers.
        let mut headers = header::HeaderMap::new();
        headers.append(header::AUTHORIZATION, bearer_token);
        headers.append(
            header::CONTENT_TYPE,
            header::HeaderValue::from_static("application/json"),
        );

        let mut request_builder = self
            .client
            .request(Method::from(&method), url)
            .headers(headers);

        if let Some(val) = query_params {
            request_builder = request_builder.query(&val);
        }

        if method != Method::GET && method != Method::DELETE {
            request_builder = request_builder.json(&body);
        }

        request_builder.build().unwrap()
    }
/// Makes a request to the Google Sheets API
///
/// # Arguments
///
/// - `method`: The type of request to make (GET, POST, etc.)
/// - `path`: The path to the endpoint (for example: `spreadsheets/{spreadsheetId}/values/{range}:append`)
/// - `body`: The body of the request
/// - `query_params`: The query parameters to add on to the request, in a list of tuples with `Vec<(parameter_name, parameter_value)>`
Makes a request to the Google Sheets API
Makes a request to the Google Sheets API
async fn request<T: Serialize>(
        &self,
        method: Method,
        path: &str,
        body: T,
        query_params: Option<Vec<(&str, &str)>>,
    ) -> Request {
        // confirm URL can parse before continuing
        let url = Url::parse(BASE_ENDPOINT).unwrap().join(&path).unwrap();
        // TODO-- use `self.token = Sheets::authenticate().await.unwrap()` to attempt to read token from cache
        // Note: this would require a mutable reference to `&mut self` in practically every method for `google_sheets::Sheets`
        if self.token.is_expired() {
            panic!("Token is expired");
        }
        let bearer_token =
            header::HeaderValue::from_str(&format!("Bearer {}", &self.token.as_str())).unwrap();
        // Set the default headers.
        let mut headers = header::HeaderMap::new();
        headers.append(header::AUTHORIZATION, bearer_token);
        headers.append(
            header::CONTENT_TYPE,
            header::HeaderValue::from_static("application/json"),
        );
        let mut request_builder = self
            .client
            .request(Method::from(&method), url)
            .headers(headers);
        if let Some(val) = query_params {
            request_builder = request_builder.query(&val);
        }
        if method != Method::GET && method != Method::DELETE {
            request_builder = request_builder.json(&body);
        }
        request_builder.build().unwrap()
    }
async fn request < T : Serialize > ( & self , method : Method , path : & str , body : T , query_params : Option < Vec < ( & str , & str ) > > , ) -> Request { // confirm URL can parse before continuing let url = Url :: parse ( BASE_ENDPOINT ) . unwrap ( ) . join ( & path ) . unwrap ( ) ; // TODO-- use `self.token = Sheets::authenticate().await.unwrap()` to attempt to read token from cache // Note: this would require a mutable reference to `&mut self` in practically every method for `google_sheets::Sheets` if self . token . is_expired ( ) { panic ! ( " " ) ; } let bearer_token = header :: HeaderValue :: from_str ( & format ! ( " " self token as_str ( ) ) ) . unwrap ( ) ; // Set the default headers. let mut headers = header :: HeaderMap :: new ( ) ; headers . append ( header :: AUTHORIZATION , bearer_token ) ; headers . append ( header :: CONTENT_TYPE , header :: HeaderValue :: from_static ( " " ) , ) ; let mut request_builder = self . client . request ( Method :: from ( & method ) , url ) . headers ( headers ) ; if let Some ( val ) = query_params { request_builder = request_builder . query ( & val ) ; } if method != Method :: GET && method != Method :: DELETE { request_builder = request_builder . json ( & body ) ; } request_builder . build ( ) . unwrap ( ) }
Makes a request to the Google Sheets API
Makes a request to the Google Sheets API
&self
method
Method
path
&str
body
T
query_params
Option<Vec<(&str, &str)>>
&self
method
Method
The type of request to make (GET, POST, etc.)
The type of request to make ( GET POST etc . )
path
&str
The path to the endpoint (for example: `spreadsheets/{spreadsheetId}/values/{range}:append`)
The path to the endpoint ( for example : ` spreadsheets / { spreadsheetId } / values / { range } : append ` )
body
T
The body of the request
The body of the request
query_params
Option<Vec<(&str, &str)>>
The query parameters to add on to the request, in a list of tuples with `Vec<(parameter_name, parameter_value)>`
The query parameters to add on to the request in a list of tuples with ` Vec< ( parameter_name parameter_value ) > `