* @author Dennis Eichhorn * @copyright 2013 Dennis Eichhorn * @license OMS License 1.0 * @version 1.0.0 * @link http://orange-management.com */ namespace phpOMS\Message\Http; /** * Rest request class. * * @category Framework * @package phpOMS\Request * @author OMS Development Team * @author Dennis Eichhorn * @license OMS License 1.0 * @link http://orange-management.com * @since 1.0.0 */ class Rest { /** * Url. * * @var Request * @since 1.0.0 */ private $request = ''; /** * Set url. * * @param Request $request Request * * @since 1.0.0 * @author Dennis Eichhorn */ public function setRequest(Request $request) /* : void */ { $this->request = $request; } /** * Make request. * * @param mixed $data Data to pass * * @return string * * @since 1.0.0 * @author Dennis Eichhorn */ public function callApi($data = false) : string { $curl = curl_init(); switch ($this->request->getMethod()) { case RequestMethod::POST: curl_setopt($curl, CURLOPT_POST, 1); if ($data) { curl_setopt($curl, CURLOPT_POSTFIELDS, $data); } break; case RequestMethod::PUT: curl_setopt($curl, CURLOPT_PUT, 1); break; } curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "username:password"); curl_setopt($curl, CURLOPT_URL, $this->request->getUri()->__toString()); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); curl_close($curl); return $result; } }