pub fn _fetch<'a>(&self,
                      func: &str,
                      mut a: Easy)
                      -> impl Future<Item = String, Error = Error> + 'a {
        let result = Arc::new(Mutex::new(Vec::new()));

        a.url(&format!("https://api.telegram.org/bot{}/{}", self.key, func)).unwrap();

        let r2 = result.clone();
        a.write_function(move |data| {
                r2.lock().unwrap().extend_from_slice(data);
                Ok(data.len())
            })
            .unwrap();

        // print debug information
        a.debug_function(|info, data| {
                match info {
                    InfoType::DataOut => {
                        println!("DataOut");
                    }
                    InfoType::Text => {
                        println!("Text");
                    }
                    InfoType::HeaderOut => {
                        println!("HeaderOut");
                    }
                    InfoType::SslDataOut => {
                        println!("SslDataOut");
                    }
                    _ => println!("something else"),
                }

                println!("{:?}", String::from_utf8_lossy(data));
            })
            .unwrap();
        //a.verbose(true).unwrap();
        //a.show_header(true).unwrap();

        self.session
            .perform(a)
            .map_err(|_| Error::TokioCurl)
            .map(move |_| {
                let response = result.lock().unwrap();
                String::from(str::from_utf8(&response).unwrap())
            })
            .and_then(|x| {
                // try to parse the result as a JSON and find the OK field.
                // If the ok field is true, then the string in "result" will be returned
                if let Ok(req) = serde_json::from_str::<Value>(&x) {
                    if let (Some(ok), res) = (req.get("ok").and_then(Value::as_bool),
                                              req.get("result")) {
                        if ok {
                            if let Some(result) = res {
                                let answer = serde_json::to_string(result).unwrap();

                                return Ok(answer);
                            }
                        }

                        match req.get("description").and_then(Value::as_str) {
                            Some(err) => Err(Error::Telegram(err.into())),
                            None => Err(Error::Telegram("Unknown".into())),
                        }
                    } else {
                        return Err(Error::JSON);
                    }
                } else {
                    return Err(Error::JSON);
                }
            })
    }
/// calls cURL and parses the result for an error
calls cURL and parses the result for an error
calls cURL and parses the result for an error
pub fn _fetch<'a>(&self,
                      func: &str,
                      mut a: Easy)
                      -> impl Future<Item = String, Error = Error> + 'a {
        let result = Arc::new(Mutex::new(Vec::new()));
        a.url(&format!("https://api.telegram.org/bot{}/{}", self.key, func)).unwrap();
        let r2 = result.clone();
        a.write_function(move |data| {
                r2.lock().unwrap().extend_from_slice(data);
                Ok(data.len())
            })
            .unwrap();
        // print debug information
        a.debug_function(|info, data| {
                match info {
                    InfoType::DataOut => {
                        println!("DataOut");
                    }
                    InfoType::Text => {
                        println!("Text");
                    }
                    InfoType::HeaderOut => {
                        println!("HeaderOut");
                    }
                    InfoType::SslDataOut => {
                        println!("SslDataOut");
                    }
                    _ => println!("something else"),
                }
                println!("{:?}", String::from_utf8_lossy(data));
            })
            .unwrap();
        //a.verbose(true).unwrap();
        //a.show_header(true).unwrap();
        self.session
            .perform(a)
            .map_err(|_| Error::TokioCurl)
            .map(move |_| {
                let response = result.lock().unwrap();
                String::from(str::from_utf8(&response).unwrap())
            })
            .and_then(|x| {
                // try to parse the result as a JSON and find the OK field.
                // If the ok field is true, then the string in "result" will be returned
                if let Ok(req) = serde_json::from_str::<Value>(&x) {
                    if let (Some(ok), res) = (req.get("ok").and_then(Value::as_bool),
                                              req.get("result")) {
                        if ok {
                            if let Some(result) = res {
                                let answer = serde_json::to_string(result).unwrap();
                                return Ok(answer);
                            }
                        }
                        match req.get("description").and_then(Value::as_str) {
                            Some(err) => Err(Error::Telegram(err.into())),
                            None => Err(Error::Telegram("Unknown".into())),
                        }
                    } else {
                        return Err(Error::JSON);
                    }
                } else {
                    return Err(Error::JSON);
                }
            })
    }
pub fn _fetch < ' a > ( & self , func : & str , mut a : Easy ) -> impl Future < Item = String , Error = Error > + ' a { let result = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ; a . url ( & format ! ( " " self key func ) ) . unwrap ( ) ; let r2 = result . clone ( ) ; a . write_function ( move | data | { r2 . lock ( ) . unwrap ( ) . extend_from_slice ( data ) ; Ok ( data . len ( ) ) } ) . unwrap ( ) ; // print debug information a . debug_function ( | info , data | { match info { InfoType :: DataOut => { println ! ( " " ) ; } InfoType :: Text => { println ! ( " " ) ; } InfoType :: HeaderOut => { println ! ( " " ) ; } InfoType :: SslDataOut => { println ! ( " " ) ; } _ => println ! ( " " ) , } println ! ( " " String from_utf8_lossy ( data ) ) ; } ) . unwrap ( ) ; //a.verbose(true).unwrap(); //a.show_header(true).unwrap(); self . session . perform ( a ) . map_err ( | _ | Error :: TokioCurl ) . map ( move | _ | { let response = result . lock ( ) . unwrap ( ) ; String :: from ( str :: from_utf8 ( & response ) . unwrap ( ) ) } ) . and_then ( | x | { // try to parse the result as a JSON and find the OK field. // If the ok field is true, then the string in "result" will be returned if let Ok ( req ) = serde_json :: from_str :: < Value > ( & x ) { if let ( Some ( ok ) , res ) = ( req . get ( " " ) . and_then ( Value :: as_bool ) , req . get ( " " ) ) { if ok { if let Some ( result ) = res { let answer = serde_json :: to_string ( result ) . unwrap ( ) ; return Ok ( answer ) ; } } match req . get ( " " ) . and_then ( Value :: as_str ) { Some ( err ) => Err ( Error :: Telegram ( err . into ( ) ) ) , None => Err ( Error :: Telegram ( " " . into ( ) ) ) , } } else { return Err ( Error :: JSON ) ; } } else { return Err ( Error :: JSON ) ; } } ) }
calls cURL and parses the result for an error
calls cURL and parses the result for an error
&self
func
&str
a
Easy