public function makeRequest($apiMethod, $params, $apiUsername = null)
{
$this->apiMethod = $apiMethod;
if (is_string($apiUsername) || is_null($apiUsername)) {
// $apiUsername is optional, if null the default account in config file is taken
$credMgr = PPCredentialManager::getInstance($this->config);
$apiCredential = clone $credMgr->getCredentialObject($apiUsername);
} else {
$apiCredential = $apiUsername;
//TODO: Aargh
}
if (isset($this->config['accessToken']) && isset($this->config['tokenSecret'])) {
$apiCredential->setThirdPartyAuthorization(new PPTokenAuthorization($this->config['accessToken'], $this->config['tokenSecret']));
}
$request = new PPRequest($params, $this->serviceBinding);
$request->setCredential($apiCredential);
$httpConfig = new PPHttpConfig(null, PPHttpConfig::HTTP_POST);
$this->runHandlers($httpConfig, $request);
$formatter = FormatterFactory::factory($this->serviceBinding);
$payload = $formatter->toString($request);
$connection = PPConnectionManager::getInstance()->getConnection($httpConfig, $this->config);
$this->logger->info("Request: {$payload}");
$response = $connection->execute($payload);
$this->logger->info("Response: {$response}");
return array('request' => $payload, 'response' => $response);
}