| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 | 
							- <?php
 - /**
 -  * Created by PhpStorm.
 -  * User: robin
 -  * Date: 11/24/15
 -  * Time: 12:15 AM
 -  */
 - 
 - namespace App\Http\Business\Commands;
 - 
 - use GuzzleHttp\Client;
 - use GuzzleHttp\Exception\ClientException;
 - use GuzzleHttp\Exception\RequestException;
 - use Luticate\Utils\LuLog;
 - 
 - class HttpRequestCommand extends AbstractCommand
 - {
 -     /**
 -      * @return bool
 -      */
 -     public function exec()
 -     {
 -         $data = $this->_command->getData();
 -         $url = $data["Url"];
 -         $method = isset($data["Method"]) ? $data["Method"] : "POST";
 -         $options = isset($data["Options"]) ? $data["Options"] : array();
 - 
 -         $client = new Client();
 - 
 -         try {
 -             $response = $client->request($method, $url, $options);
 -         } catch (ClientException $e) {
 -             $response = $e->getResponse();
 -             if (!is_null($response)) {
 -                 LuLog::log($response->getBody());
 -             }
 -             LuLog::log($e);
 -             abort(500, "Failed to execute request (client)");
 -         } catch (RequestException $e) {
 -             $response = $e->getResponse();
 -             if (!is_null($response)) {
 -                 LuLog::log($response->getBody());
 -             }
 -             LuLog::log($e);
 -             abort(500, "Failed to execute request (request)");
 -         } catch (\Exception $e) {
 -             LuLog::log($e);
 -             abort(500, "Failed to execute request (unknown)");
 -         }
 - 
 -         if ($response->getStatusCode() != 200)
 -         {
 -             abort(500, "Failed to execute request (" . $response->getStatusCode() . ")");
 -         }
 - 
 -         return true;
 -     }
 - }
 
 
  |