Example #1
0
 /**
  * @return mixed
  */
 protected function _fetchFromApi()
 {
     // create request
     $curl = \CURL::init($this->_getUrl())->addHttpHeader('Content-type', 'application/json')->setPost(TRUE)->setPostFields($this->_getDataAsJson())->setReturnTransfer(TRUE);
     // use proxy
     if ($this->hasProxy()) {
         $curl->setProxy($this->getProxyHost())->setProxyPort($this->getProxyPort());
     }
     // send request
     $response = $curl->execute();
     // decode json data
     $data = json_decode($response, TRUE);
     // response exception for not json object
     if (is_null($data)) {
         $data = $response;
     }
     // valid json-rpc response
     if (!isset($data['result'])) {
         // Log errors from service
         error_log(var_export($data, true));
         return ['error' => $data];
     }
     // and out
     return $data['result'];
 }
Example #2
0
 /**
  * @param $path
  * @param array $params
  *
  * @return array|bool
  * @throws GplusException
  */
 public static function post($path, $params = [])
 {
     if (!empty($params)) {
         $url = self::_getCleanDomain(GplusConstants::DOMAIN_ACCOUNTS) . '/' . self::_getCleanPath($path);
         // talk to google
         $responseJson = \CURL::init($url)->setPostFields(http_build_query($params))->setReturnTransfer(TRUE)->execute();
         // parse response
         $response = json_decode($responseJson, TRUE);
         if ($response !== NULL) {
             if (isset($response['error'])) {
                 throw new GplusException(GplusErrorConstants::REQUEST_ERROR_MESSAGE, GplusErrorConstants::REQUEST_ERROR_CODE, $response);
             }
             return (array) $response;
         }
     }
     return FALSE;
 }
Example #3
0
 /**
  * @param $url
  * @param $vars
  *
  * @return mixed
  * @throws CirrusException
  */
 protected function _putRemoteData($url, $vars)
 {
     $jsonResponse = \CURL::init($url)->setReturnTransfer(TRUE)->setCustomRequest('PUT')->setPostFields($vars)->execute();
     $data = json_decode($jsonResponse, TRUE);
     // handle errors
     if (isset($data['errors'])) {
         throw new CirrusException(__CLASS__ . ": Failed putting reote data at url={$url}", 500);
     }
     return $data;
 }
Example #4
0
<?php

include "../CURL.php";
// Example 1. Grab some JSON
$curl = CURL::init("http://www.reddit.com/r/php/.json")->setReturnTransfer(TRUE);
var_dump(json_decode($curl->execute()));
// Example 2. Use our existing CURL object, and retrieve some headers
$headers = $curl->setHeader(TRUE)->setNobody(TRUE)->setReturnTransfer(TRUE)->execute();
print $headers . "\n";
// Example 3. Using the `->get...` functions
print $curl->getHTTPCode() . "\n";
Example #5
0
 /**
  * @param $resourcePath
  * @param array $params
  *
  * @return array|mixed
  * @throws FacebookException
  */
 protected function _submitToGraph($resourcePath, array $params)
 {
     // make sure that we have what we need
     if (!$resourcePath) {
         throw new FacebookException("Cannot submit to graph due to missing resourcePath.", 'ClassError', $this->_classErrorCode);
     }
     // build URL
     $graphUrl = trim($this->_graphUrl, '/') . '/' . trim($resourcePath, '/');
     // request FB graph
     $response = \CURL::init($graphUrl)->setPost(TRUE)->setPostFields($params)->setReturnTransfer(TRUE)->execute();
     // parse response
     $data = $this->_parseGraphResponse($response);
     // handle error response
     if (isset($data['error'])) {
         $this->_handleErrorResponse($data);
     }
     return $data;
 }