/** * @param string $action * @param array $params * @return Response\Text|Response\XML|bool * @throws ParseException */ public function api($action = '', array $params) { $result = false; $url = $action ? 'http://' . $this->getIp() . '/' . $action : 'http://' . $this->getIp() . '/'; $this->request->setURL($url); $this->request->setGetParams($this->convertEncoding($params)); $response = $this->request->run(); if ($response) { if ($this->request->isXML()) { libxml_use_internal_errors(true); $result = simplexml_load_string($response); if (libxml_get_errors() && $this->errorReporting) { $errors = libxml_get_errors(); foreach ($errors as $error) { throw new ParseException($error->message, $error->code); } } else { $result = new Response\XML($result); } libxml_use_internal_errors(false); } else { if ($this->request->isText()) { $result = new Response\Text($response); } else { $result = new Response\Error($response); } } } else { $result = new Response\Error($response); } return $result; }