fn http_request(
        &self,
        url: &'static str,
        query: &[(&'static str, Cow<str>)],
    ) -> Result<ureq::Response, Error> {
        let url = match self.api_key.ends_with(":fx") {
            true => format!("https://api-free.deepl.com/v2{}", url),
            false => format!("https://api.deepl.com/v2{}", url),
        };

        let mut request = ureq::post(&url).query("auth_key", &self.api_key);

        for (key, value) in query {
            request = request.query(key, value);
        }

        match request.call() {
            Ok(response) => match response.status() {
                200..=299 => Ok(response),
                401 | 403 => Err(Error::AuthorizationError),
                status => {
                    // DeepL sends back error messages in the response body.
                    // Try to fetch them to construct more helpful exceptions.
                    match response.into_json::<ServerErrorMessage>() {
                        Ok(server_error) => Err(Error::ServerError(server_error.message)),
                        _ => Err(Error::ServerError(status.to_string())),
                    }
                }
            },

            Err(e) => Err(Error::ServerError(e.to_string())),
        }
    }
/// Private method that performs the HTTP calls.
Private method that performs the HTTP calls.
Private method that performs the HTTP calls .
fn http_request(
        &self,
        url: &'static str,
        query: &[(&'static str, Cow<str>)],
    ) -> Result<ureq::Response, Error> {
        let url = match self.api_key.ends_with(":fx") {
            true => format!("https://api-free.deepl.com/v2{}", url),
            false => format!("https://api.deepl.com/v2{}", url),
        };
        let mut request = ureq::post(&url).query("auth_key", &self.api_key);
        for (key, value) in query {
            request = request.query(key, value);
        }
        match request.call() {
            Ok(response) => match response.status() {
                200..=299 => Ok(response),
                401 | 403 => Err(Error::AuthorizationError),
                status => {
                    // DeepL sends back error messages in the response body.
                    // Try to fetch them to construct more helpful exceptions.
                    match response.into_json::<ServerErrorMessage>() {
                        Ok(server_error) => Err(Error::ServerError(server_error.message)),
                        _ => Err(Error::ServerError(status.to_string())),
                    }
                }
            },
            Err(e) => Err(Error::ServerError(e.to_string())),
        }
    }
fn http_request ( & self , url : & ' static str , query : & [ ( & ' static str , Cow < str > ) ] , ) -> Result < ureq :: Response , Error > { let url = match self . api_key . ends_with ( " " ) { true => format ! ( " " url ) , false => format ! ( " " url ) , } ; let mut request = ureq :: post ( & url ) . query ( " " , & self . api_key ) ; for ( key , value ) in query { request = request . query ( key , value ) ; } match request . call ( ) { Ok ( response ) => match response . status ( ) { 200 ..= 299 => Ok ( response ) , 401 | 403 => Err ( Error :: AuthorizationError ) , status => { // DeepL sends back error messages in the response body. // Try to fetch them to construct more helpful exceptions. match response . into_json :: < ServerErrorMessage > ( ) { Ok ( server_error ) => Err ( Error :: ServerError ( server_error . message ) ) , _ => Err ( Error :: ServerError ( status . to_string ( ) ) ) , } } } , Err ( e ) => Err ( Error :: ServerError ( e . to_string ( ) ) ) , } }
Private method that performs the HTTP calls.
Private method that performs the HTTP calls .
&self
url
&'static str
query
&[(&'static str, Cow<str>)]
&self
url
&'static str
query
&[(&'static str, Cow<str>)]