Esempio n. 1
0
 /**
  * Make a call to the API
  * 
  * @param string $method HTTP method to use
  * @param string $url URL
  * @param array $params API parameters
  * @param boolean $throw_exception True to throw exceptoins
  * @throws APIException, APIAuthException
  * @return  \Instagram\Net\ApiResponse Returns teh API response
  * @access private
  */
 private function apiCall($method, $url, array $params = null, $throw_exception = true)
 {
     $raw_response = $this->client->{$method}($url, array('access_token' => $this->access_token, 'client_id' => isset($params['client_id']) ? $params['client_id'] : $this->client_id) + (array) $params);
     $response = new \Instagram\Net\ApiResponse($raw_response);
     if (!$response->isValid()) {
         if ($throw_exception) {
             if ($response->getErrorType() == 'OAuthAccessTokenException') {
                 throw new \Instagram\Core\ApiAuthException($response->getErrorMessage(), $response->getErrorCode(), $response->getErrorType());
             } else {
                 throw new \Instagram\Core\ApiException($response->getErrorMessage(), $response->getErrorCode(), $response->getErrorType());
             }
         } else {
             return false;
         }
     }
     return $response;
 }
Esempio n. 2
0
 private function apiCall($method, $url, array $params = null, $throw_exception = true)
 {
     $url = str_replace('/', '_', $url);
     $url = str_replace('&', '_', $url);
     $url = str_replace('?', '_', $url);
     $url = trim($method . $url . '_' . implode('_', $params), '_');
     $FAUX_DATA_PATH = THINKUP_WEBAPP_PATH . 'plugins/instagram/tests/testdata/';
     if ($this->access_token !== 'fauxaccesstokeninvalid') {
         $response = new \Instagram\Net\ApiResponse(self::decodeFileContents($FAUX_DATA_PATH . $url));
     } else {
         $response = new \Instagram\Net\ApiResponse(self::decodeFileContents($FAUX_DATA_PATH . 'invalid_access_token'));
     }
     if (!$response->isValid()) {
         if ($throw_exception) {
             if ($response->getErrorType() == 'OAuthAccessTokenException') {
                 throw new \Instagram\Core\ApiAuthException($response->getErrorMessage(), $response->getErrorCode(), $response->getErrorType());
             } else {
                 throw new \Instagram\Core\ApiException($response->getErrorMessage(), $response->getErrorCode(), $response->getErrorType());
             }
         } else {
             return false;
         }
     }
     return $response;
 }