コード例 #1
0
 private function getCurlRequest()
 {
     if (!isset($this->generator)) {
         $this->generator = new RequestGenerator();
         $request = new CurlRequest(new Options());
         $request->setOptionArray($this->options);
         $this->generator->setRequest($request);
     }
     return $this->generator->getRequest();
 }
コード例 #2
0
ファイル: Client.php プロジェクト: unialteri/sellsy-client
 /**
  * Method to perform a request to the api.
  *
  * @param array $requestSettings
  *
  * @return \stdClass
  *
  * @throws RequestFailureException is the request can not be performed on the server
  * @throws ErrorException          if the server returned an error for this request
  */
 public function requestApi($requestSettings)
 {
     //Arguments for the Sellsy API
     $this->lastRequest = $requestSettings;
     $this->lastAnswer = null;
     $encodedRequest = array('request' => 1, 'io_mode' => 'json', 'do_in' => \json_encode($requestSettings));
     //Generate client request
     $request = $this->requestGenerator->getRequest();
     //Configure to contact the api with POST request and return value
     $request->setMethod('POST')->setUrl($this->apiUrl)->setReturnValue(true)->setOptionArray(array(CURLOPT_HTTPHEADER => $this->computeHeaders(), CURLOPT_POSTFIELDS => $encodedRequest, CURLOPT_SSL_VERIFYPEER => !\preg_match('!^https!i', $this->apiUrl)));
     //Execute the request
     try {
         $result = $request->execute();
     } catch (\Exception $e) {
         throw new RequestFailureException($e->getMessage(), $e->getCode(), $e);
     }
     //OAuth issue, throw an exception
     if (false !== \strpos($result, 'oauth_problem')) {
         throw new RequestFailureException($result);
     }
     $answer = \json_decode($result);
     //Bad request, error returned by the api, throw an error
     if (!empty($answer->status) && 'error' == $answer->status) {
         if (!empty($answer->error->message)) {
             //Retrieve error message like it's defined in Sellsy API documentation
             throw new ErrorException($answer->error->message);
         } elseif (\is_string($answer->error)) {
             //Retrieve error message (sometime, error is not an object...)
             throw new ErrorException($answer->error);
         } else {
             //Other case, return directly the answer
             throw new ErrorException($result);
         }
     }
     $this->lastAnswer = $answer;
     return $this->lastAnswer;
 }
コード例 #3
0
 /**
  * Check if external link is valid
  * @param string $url
  * @return boolean
  */
 private function checkExternalLink($url)
 {
     $valid = true;
     $generator = new RequestGenerator();
     $request = $generator->getRequest();
     $request->setUrl($url)->setMethod('GET');
     try {
         $request->execute();
     } catch (TeknooCurlException $e) {
         $valid = false;
     }
     return $valid;
 }