예제 #1
0
 protected function _httpRequest($url, $method = 'GET', $params = array())
 {
     $client = new Zend_Http_Client($url, array('timeout' => 60));
     switch ($method) {
         case 'GET':
             $client->setParameterGet($params);
             break;
         case 'POST':
             $client->setParameterPost($params);
             break;
         case 'DELETE':
             $client->setParameterGet($params);
             break;
         default:
             throw new Exception(Mage::helper('inchoo_socialconnect')->__('Required HTTP method is not supported.'));
     }
     $response = $client->request($method);
     Inchoo_SocialConnect_Helper_Data::log($response->getStatus() . ' - ' . $response->getBody());
     $decodedResponse = json_decode($response->getBody());
     /*
      * Per http://tools.ietf.org/html/draft-ietf-oauth-v2-27#section-5.1
      * Facebook should return data using the "application/json" media type.
      * Facebook violates OAuth2 specification and returns string. If this
      * ever gets fixed, following condition will not be used anymore.
      */
     if (empty($decodedResponse)) {
         $parsed_response = array();
         parse_str($response->getBody(), $parsed_response);
         $decodedResponse = json_decode(json_encode($parsed_response));
     }
     if ($response->isError()) {
         $status = $response->getStatus();
         if ($status == 400 || $status == 401) {
             if (isset($decodedResponse->error->message)) {
                 $message = $decodedResponse->error->message;
             } else {
                 $message = Mage::helper('inchoo_socialconnect')->__('Unspecified OAuth error occurred.');
             }
             throw new Inchoo_SocialConnect_Model_Facebook_Oauth2_Exception($message);
         } else {
             $message = sprintf(Mage::helper('inchoo_socialconnect')->__('HTTP error %d occurred while issuing request.'), $status);
             throw new Exception($message);
         }
     }
     return $decodedResponse;
 }
예제 #2
0
 protected function _httpRequest($url, $method = 'GET', $params = array())
 {
     $client = new Zend_Http_Client($url, array('timeout' => 60));
     switch ($method) {
         case 'GET':
             $client->setParameterGet($params);
             break;
         case 'POST':
             $client->setParameterPost($params);
             break;
         case 'DELETE':
             break;
         default:
             throw new Exception(Mage::helper('inchoo_socialconnect')->__('Required HTTP method is not supported.'));
     }
     $response = $client->request($method);
     Inchoo_SocialConnect_Helper_Data::log($response->getStatus() . ' - ' . $response->getBody());
     $decodedResponse = json_decode($response->getBody());
     if ($response->isError()) {
         $status = $response->getStatus();
         if ($status == 400 || $status == 401) {
             if (isset($decodedResponse->error->message)) {
                 $message = $decodedResponse->error->message;
             } else {
                 $message = Mage::helper('inchoo_socialconnect')->__('Unspecified OAuth error occurred.');
             }
             throw new Inchoo_SocialConnect_Model_Google_Oauth2_Exception($message);
         } else {
             $message = sprintf(Mage::helper('inchoo_socialconnect')->__('HTTP error %d occurred while issuing request.'), $status);
             throw new Exception($message);
         }
     }
     return $decodedResponse;
 }
예제 #3
0
 protected function _httpRequest($url, $method = 'GET', $params = array())
 {
     $client = $this->token->getHttpClient(array('callbackUrl' => $this->redirectUri, 'siteUrl' => self::OAUTH_URI, 'consumerKey' => $this->clientId, 'consumerSecret' => $this->clientSecret));
     $client->setUri($url);
     switch ($method) {
         case 'GET':
             $client->setMethod(Zend_Http_Client::GET);
             $client->setParameterGet($params);
             break;
         case 'POST':
             $client->setMethod(Zend_Http_Client::POST);
             $client->setParameterPost($params);
             break;
         case 'DELETE':
             $client->setMethod(Zend_Http_Client::DELETE);
             break;
         default:
             throw new Exception(Mage::helper('inchoo_socialconnect')->__('Required HTTP method is not supported.'));
     }
     $response = $client->request();
     Inchoo_SocialConnect_Helper_Data::log($response->getStatus() . ' - ' . $response->getBody());
     $decodedResponse = json_decode($response->getBody());
     if ($response->isError()) {
         $status = $response->getStatus();
         if ($status == 400 || $status == 401 || $status == 429) {
             if (isset($decodedResponse->error->message)) {
                 $message = $decodedResponse->error->message;
             } else {
                 $message = Mage::helper('inchoo_socialconnect')->__('Unspecified OAuth error occurred.');
             }
             throw new Inchoo_SocialConnect_Model_Twitter_Oauth_Exception($message);
         } else {
             $message = sprintf(Mage::helper('inchoo_socialconnect')->__('HTTP error %d occurred while issuing request.'), $status);
             throw new Exception($message);
         }
     }
     return $decodedResponse;
 }