Ejemplo n.º 1
0
 /**
  * @param string $url
  * @param string|array $data
  * @return \Kdyby\Curl\Response
  * @throws iDefendCurlException
  */
 public function send($url, $data = '')
 {
     try {
         $request = new Request($this->url . $url);
         $request->setSender($this->curlSender);
         return $request->post(Json::encode($data));
     } catch (CurlException $e) {
         throw new iDefendCurlException($e->getMessage());
     }
 }
Ejemplo n.º 2
0
 /** @return CUrl */
 private function createCurl($url, array $post, $filename)
 {
     $request = new Curl\Request($url);
     $request->setPost($post, array('file' => $filename));
     $curl = new Curl\CurlSender();
     $curl->setTimeout(30);
     $curl->options = array('verbose' => 0, 'ssl_verifypeer' => 0, 'ssl_verifyhost' => 2) + $curl->options;
     $request->setSender($curl);
     return $request;
 }
Ejemplo n.º 3
0
 /**
  * @param Request $request
  * @param string|array $query
  * @return mixed
  * @throws ChainException
  */
 private function sendRequest(Request $request, $query = NULL)
 {
     try {
         $response = NULL;
         if (!empty($query)) {
             $request->setSender($this->sender);
             $response = $request->get($query);
         } else {
             $response = $this->sender->send($request);
         }
         return Json::decode($response->getResponse(), Json::FORCE_ARRAY);
     } catch (\Kdyby\Curl\CurlException $ex) {
         $response = Json::decode($ex->getResponse()->getResponse());
         throw new ChainException($response->message, $ex->getCode());
     }
 }
Ejemplo n.º 4
0
 /**
  * @param array $data
  * @throws CommunicationFailedException
  * @return array
  */
 private function process($data)
 {
     $this->onRequest($data);
     $data = array('USER' => $this->username, 'PWD' => $this->password, 'SIGNATURE' => $this->signature, 'VERSION' => self::API_VERSION) + $data;
     $request = new Curl\Request($this->host, $data);
     $request->setSender($this->curlSender);
     $request->options['verbose'] = TRUE;
     if (strpos($request->getUrl()->getHost(), '.sandbox.') !== FALSE) {
         $request->setCertificationVerify(FALSE);
         $request->options['ssl_verifyHost'] = FALSE;
     }
     try {
         $response = $request->post(http_build_query($data));
         $resultData = self::parseNvp($response->getResponse());
         $this->onSuccess($resultData, $response->getInfo());
         return $resultData;
     } catch (Curl\FailedRequestException $e) {
         $this->onError($e, $e->getInfo());
         throw new CommunicationFailedException($e->getMessage(), 0, $e);
     } catch (Curl\CurlException $e) {
         $this->onError($e, $e->getResponse() ? $e->getResponse()->info : array());
         throw new CommunicationFailedException($e->getMessage(), 0, $e);
     }
 }
Ejemplo n.º 5
0
 /**
  * @param $url
  * @return CurlRequest
  */
 private static function prepareNewCurlRequest($url)
 {
     $curlRequest = new CurlRequest($url);
     $curlSender = new CurlSender();
     $curlSender->options['USERPWD'] = 'test:test';
     //TODO LM credentials!!!
     $curlSender->options['timeout'] = 300;
     //request timeout in seconds
     $curlRequest->setSender($curlSender);
     return $curlRequest;
 }
Ejemplo n.º 6
0
 /**
  * @param string $endpoint
  *
  * @return Request
  */
 private function createRequest($endpoint)
 {
     $request = new Request($this->url . $endpoint);
     $request->setSender($this->sender);
     $request->headers['Authorization'] = 'apikey ' . $this->apiKey;
     return $request;
 }