soap_client = new SoapClient($this->wsdl); } function authValid() { return (time() - $this->auth_time < $this->prosper_auth_timeout); } // See http://www.php.net/manual/en/function.mdecrypt-generic.php for sample encryption code function encrypt_init() { global $CONFIG; $this->td = mcrypt_module_open('des', '', 'ecb', ''); $key = substr($CONFIG['crypt_key'], 0, mcrypt_enc_get_key_size($this->td)); $iv_size = mcrypt_enc_get_iv_size($this->td); $this->iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); } function encryptKey() { global $CONFIG; return substr($CONFIG['crypt_key'], 0, mcrypt_enc_get_key_size($this->td)); } function encrypt($value) { $this->encrypt_init(); global $CONFIG; if (mcrypt_generic_init($this->td, $this->encryptKey(), $this->iv) != -1) { $ct = mcrypt_generic($this->td, $value); mcrypt_generic_deinit($this->td); return $ct; } } function decrypt($value) { global $CONFIG; $this->encrypt_init(); if (mcrypt_generic_init($this->td, $this->encryptKey(), $this->iv) != -1) { $pt = mdecrypt_generic($this->td, $value); mcrypt_generic_deinit($this->td); return $pt; } } // Attempt to authenticate to prosper. Returns true /false // If authentication is successful, save encrypted version of it to $this->auth_token // And the successful login credentials to $this->auth_email and $this->auth_pass function authenticate($email = '', $pass = '') { global $CONFIG; $email = empty($email) ? $this->decrypt($this->auth_email) : $email; $pass = empty($pass) ? $this->decrypt($this->auth_pass) : $pass; $result = $this->call('login', array('email' => $email, 'password' => $pass)); if (isset($result['LoginResult']->Success) && $result['LoginResult']->Success == 1) { // Authentication was successful $this->auth_email = $this->encrypt($email); $this->auth_pass = $this->encrypt($pass); $this->auth_token = $this->encrypt($result['LoginResult']->Message); $this->auth_time = time(); sleep(5); // Sometimes authentication doesn't seem to take return true; } return false; } function authToken() { return $this->decrypt($this->auth_token); } function call($operation, $params) { $this->errorMessage = ''; try { $result = (array) $this->soap_client->__soapCall($operation, array('Request' => $params)); } catch (Exception $e) { $this->error($operation, $params, $e); return false; } return $result; } function query($params = array()) { $result = $this->call('Query', $params); if ((isset($result['QueryResult']->Success)) && $result['QueryResult']->Success == 1) { return isset($result['QueryResult']->ProsperObjects->ProsperObject) ? $result['QueryResult']->ProsperObjects->ProsperObject : array(); } else { $this->error('query', $params, $result['QueryResult']->Message); return false; } } function retrieve($params = array()) { if (!isset($params['authenticationToken'])) { $params['authenticationToken'] = $this->authToken(); } $result = $this->call('Retrieve', $params); if ((isset($result['RetrieveResult']->Success)) && $result['RetrieveResult']->Success == 1) { return $result['RetrieveResult']->ProsperObjects->ProsperObject; } else { $this->error('retrieve', $params, $result['RetrieveResult']->Message); return false; } } function bid($params = array()) { if (!isset($params['authenticationToken'])) { $params['authenticationToken'] = $this->authToken(); } $result = $this->call('Bid', $params); sleep(6); // Must wait 5 seconds between bid attempts if ((isset($result['BidResult']->Success)) && $result['BidResult']->Success == 1) { return $result['BidResult']->ProsperObjects->ProsperObject; } else { $this->error('bid', $params, $result['BidResult']->Message); return false; } } function error($operation, $params, $error) { echo "An error occurred while trying to do operation = $operation\n"; echo "Error message: $error\n"; $this->errorMessage = $error; } } ?>