/**
  * Get the response from a client and request
  *
  * @param Client $client a guzzle client
  * @param object $request a guzzle request object
  * @return array the response
  */
 private function _getResponse(Client $client, $request)
 {
     try {
         $response = $client->send($request);
     } catch (RequestException $e) {
         PlacidPlugin::log($e->getMessage(), LogLevel::Error);
         $message = array('failed' => true);
         if (method_exists($e, 'getResponse')) {
             $response = $e->getResponse();
             $message['statusCode'] = $response->getStatusCode();
         }
         if (craft()->request->isAjaxRequest()) {
             return $message;
         } else {
             return null;
         }
     }
     $contentType = preg_match('/.+?(?=;)/', $response->getContentType(), $matches);
     $contentType = implode($matches, '');
     if ($contentType == 'text/xml') {
         try {
             $output = $response->xml();
         } catch (\Guzzle\Common\Exception\RuntimeException $e) {
             PlacidPlugin::log($e->getMessage(), LogLevel::Error);
             $output = null;
         }
     } else {
         try {
             $output = $response->json();
         } catch (\Guzzle\Common\Exception\RuntimeException $e) {
             PlacidPlugin::log($e->getMessage(), LogLevel::Error);
             $output = null;
         }
     }
     if ($this->config['cache']) {
         craft()->placid_cache->set($this->_getCacheId(), $output, $this->config['duration']);
     }
     return $output;
 }
Example #2
0
 /**
  * Get the response from a client and request
  *
  * @param Client $client a guzzle client
  * @param object $request a guzzle request object
  * @return array the response
  */
 private function _getResponse(Client $client, $request)
 {
     try {
         $response = $client->send($request);
     } catch (RequestException $e) {
         PlacidPlugin::log($e->getMessage(), LogLevel::Error);
         $message = array('failed' => true);
         $response = null;
         if (method_exists($e, 'getResponse')) {
             $response = $e->getResponse();
             $message['statusCode'] = $response->getStatusCode();
         }
         return $response;
     }
     if ($this->config['cache']) {
         craft()->placid_cache->set($this->_getCacheId(), $response, $this->config['duration']);
     }
     return $response;
 }