/** * Make the call * * @param string $url API url to call * @param array $parameters Parameters for the request * @param bool $authenticate Shall we use authentication? * @param bool $usePost Uses POST method instead of GET * * @return mixed * * @throws InvalidArgumentException if the type provided is not supported * @throws TwitterApiServerException if the request fails for any reason * @throws RuntimeException if the xml response is invalid */ protected function doCall($url, $parameters = array(), $authenticate = false, $usePost = true, $type = 'entity') { $response = $this->server->request(sprintf('%s.xml', $url), $parameters, $usePost ? 'POST' : 'GET'); switch ($type) { case 'entity': $dom = new DOMDocument(); $dom->loadXML($response); return TwitterEntity::createFromXml($dom); break; case 'boolean': if (!($xml = @simplexml_load_string($response))) { throw new RuntimeException('XML error'); } return (bool) ((string) $xml === 'true'); break; case 'hash': if (!($xml = @simplexml_load_string($response))) { throw new RuntimeException('XML error'); } return (array) $xml; break; case 'search_results': return TweetCollection::createFromJSON($response); break; default: throw new InvalidArgumentException(sprintf('Type "%s" is not supported', $type)); break; } }