pub fn new(username: &str, password: &str) -> Result<Self> {
        let client = Client::new();
        let partner = Partner::default();
        let mut credentials = Credentials {
            username: username.to_owned(),
            password: password.to_owned(),

            encrypt_key: partner.encrypt_password.clone(),
            decrypt_key: partner.decrypt_password.clone(),

            partner_id: None,
            partner_auth_token: None,
            sync_time: None,

            user_id: None,
            user_auth_token: None,
        };

        let partner_login: PartnerLogin = try!(request(&client,
                                                       &HttpMethod::Post,
                                                       DEFAULT_ENDPOINT,
                                                       Method::AuthPartnerLogin,
                                                       Some(serde_json::to_value(&partner)),
                                                       None));
        credentials.set_partner_login(partner_login);

        let user_login_body = serde_json::to_value(&UserLoginRequest::new(username.to_owned(),
                                                                          password.to_owned()));
        let user_login: UserLogin = try!(request(&client,
                                                 &HttpMethod::Post,
                                                 DEFAULT_ENDPOINT,
                                                 Method::AuthUserLogin,
                                                 Some(user_login_body),
                                                 Some(&credentials)));
        credentials.set_user_login(user_login);

        // At this point we can assume credentials are correct.
        Ok(credentials)
    }
/// Creates new credentials from the given user and password.
Creates new credentials from the given user and password.
Creates new credentials from the given user and password .
pub fn new(username: &str, password: &str) -> Result<Self> {
        let client = Client::new();
        let partner = Partner::default();
        let mut credentials = Credentials {
            username: username.to_owned(),
            password: password.to_owned(),
            encrypt_key: partner.encrypt_password.clone(),
            decrypt_key: partner.decrypt_password.clone(),
            partner_id: None,
            partner_auth_token: None,
            sync_time: None,
            user_id: None,
            user_auth_token: None,
        };
        let partner_login: PartnerLogin = try!(request(&client,
                                                       &HttpMethod::Post,
                                                       DEFAULT_ENDPOINT,
                                                       Method::AuthPartnerLogin,
                                                       Some(serde_json::to_value(&partner)),
                                                       None));
        credentials.set_partner_login(partner_login);
        let user_login_body = serde_json::to_value(&UserLoginRequest::new(username.to_owned(),
                                                                          password.to_owned()));
        let user_login: UserLogin = try!(request(&client,
                                                 &HttpMethod::Post,
                                                 DEFAULT_ENDPOINT,
                                                 Method::AuthUserLogin,
                                                 Some(user_login_body),
                                                 Some(&credentials)));
        credentials.set_user_login(user_login);
        // At this point we can assume credentials are correct.
        Ok(credentials)
    }
pub fn new ( username : & str , password : & str ) -> Result < Self > { let client = Client :: new ( ) ; let partner = Partner :: default ( ) ; let mut credentials = Credentials { username : username . to_owned ( ) , password : password . to_owned ( ) , encrypt_key : partner . encrypt_password . clone ( ) , decrypt_key : partner . decrypt_password . clone ( ) , partner_id : None , partner_auth_token : None , sync_time : None , user_id : None , user_auth_token : None , } ; let partner_login : PartnerLogin = try ! ( request ( client HttpMethod Post DEFAULT_ENDPOINT Method AuthPartnerLogin Some ( serde_json to_value ( partner ) ) None ) ) ; credentials . set_partner_login ( partner_login ) ; let user_login_body = serde_json :: to_value ( & UserLoginRequest :: new ( username . to_owned ( ) , password . to_owned ( ) ) ) ; let user_login : UserLogin = try ! ( request ( client HttpMethod Post DEFAULT_ENDPOINT Method AuthUserLogin Some ( user_login_body ) Some ( credentials ) ) ) ; credentials . set_user_login ( user_login ) ; // At this point we can assume credentials are correct. Ok ( credentials ) }
Creates new credentials from the given user and password.
Creates new credentials from the given user and password .
username
&str
password
&str
username
&str
password
&str