/** * Constructor */ function __construct(\GuzzleHttp\Psr7\Response $response) { $this->_responseObj = $response; $xmlString = $this->_responseObj->getBody()->getContents(); if (!empty($xmlString)) { $this->response = $this->xmlToArray($xmlString); if (array_key_exists($this->errorKey, $this->response)) { if (isset($this->response[$this->errorKey]['Code'])) { $this->code = $this->response[$this->errorKey]['Code']; } if (isset($this->response[$this->errorKey]['Status'])) { $this->code = $this->response[$this->errorKey]['Status']; } if (isset($this->response[$this->errorKey]['Result'])) { $this->code = $this->response[$this->errorKey]['Result']; } if (isset($this->response[$this->errorKey]['Error'])) { $this->error = $this->response[$this->errorKey]['Error']; } if (isset($this->response[$this->errorKey]['Error'])) { $this->error = $this->response[$this->errorKey]['Error']; } } $this->checkErrors(); } return $this; }
/** * Update Debug entry data * * @param object $node * @param boolean $hasError * * @return object Xcom_Xfabric_Model_Resource_Debug */ public function update($node, $hasError) { //Fixed zero symbols //$body = preg_replace('/[\x00]\*[\x00]/', '___', serialize($node->getBody())); $this->_getWriteAdapter()->update($this->getMainTable(), array('parent_id' => $node->getParentId(), 'topic' => $node->getTopic(), 'headers' => $node->getHeaders(), 'body' => $node->getBody(), 'memory_usage_after' => $node->getMemoryUsageAfter(), 'completed_at' => now(), 'has_error' => $hasError, 'completed_microtime' => $node->getCompletedMicrotime()), array('node_id = ? ' => $node->getNodeId())); return $this; }
/** * Populate the object with data from the response * * @param object $response Guzzle response object */ public function setData($response) { if ($response->getStatusCode() == '200') { $this->setSuccess(true); } $body = json_decode($response->getBody(true)); $this->setBody($body->response); }
/** * Handle the response. * @param object $response * @return object * @throws \Exception */ private function handleResponse($response) { $statusCode = $response->getStatusCode(); $body = $response->getBody(); if ($statusCode >= 200 && $statusCode < 300) { return true; } throw new \Exception($body, $statusCode); }
/** * Get the details of the required request * @return object */ private function data() { $result = json_decode($this->response->getBody()); $mediatorResult = isset($result->minimum_price) ? $result->minimum_price : 'absent'; if ($mediatorResult == 'absent') { return $result; } $result->isFree = number_format($mediatorResult, 2) == 0.0; return $result; }
/** * Get the details of the required request * @return object */ private function data() { $result = json_decode($this->response->getBody()); $simplifiedResult = []; if (is_array($result)) { foreach ($result as $key => $value) { $simplifiedResult[$key] = (array) $value; } return $simplifiedResult; } return (array) $result; }
/** * Populate the object with data from the response * * @param object $response Guzzle response object */ public function setData($response) { if ($response->getStatusCode() == '200') { $this->setSuccess(true); } $body = json_decode($response->getBody(true)); if (isset($body->response)) { $this->setBody($body->response); } else { $this->setBody($body); // check for a "stat" of "FAIL" $body = $this->getBody(); if (isset($body->stat) && $body->stat == 'FAIL') { \DuoAuth\Error::add($body->message); $this->setSuccess(false); } } }
/** * @param Request $request * @param object $contentDocument * @param array $filters * * @return Response */ public function directAction(Request $request, $contentDocument, $filters = array()) { $response = new Response($contentDocument->getBody(), 200); $response->setLastModified($contentDocument->getUpdatedAt()); $response->setPublic(); if (!$this->get('kernel')->isDebug()) { if ($response->isNotModified($request)) { return $response; } $asset = new StringAsset($response->getContent()); $asset->load(); $filterManager = $this->get('assetic.filter_manager'); if ($filterManager) { foreach ($filters as $filter) { if ($processor = $filterManager->get($filter)) { $processor->filterDump($asset); } } } $response->setContent($asset->getContent()); } $response->prepare($request); return $response; }
/** * Process the successfull request performed. * Throws exceptions where the request was unsuccessful from the server. * @param object $response * @throws \Exception * @return \FrontCore\Models\ApiRequestModel */ private function processResponse($response) { if ($response->isSuccess()) { $this->objResponse = $response; //check received status code //anything else than 200 indicates an error try { $objResponse = Json::decode($response->getBody(), Json::TYPE_OBJECT); } catch (\Exception $e) { throw new \Exception(__CLASS__ . " : Line " . __LINE__ . " : Request could not be processed. JSON could not be decoded. Response : " . $response->getBody(), 500); } //end catch if (!is_object($objResponse)) { throw new \Exception(__CLASS__ . " : Line " . __LINE__ . " : An error occurred performing request. Data could not be decoded. Raw Data : '" . $response->getBody() . "'", 500); } //end if if ($objResponse->HTTP_RESPONSE_CODE != 200) { //throw new \Exception(__CLASS__ . " : An API processing error occurred. Status : $objResponse->HTTP_STATUS_MESSAGE. Raw Data : " . $response->getBody(), $objResponse->HTTP_RESPONSE_CODE); //@TODO make another plan with failures throw new \Exception($response->getBody(), $objResponse->HTTP_RESPONSE_CODE); } //end function /** * Return class as object */ return $this; } else { throw new \Exception(__CLASS__ . " : An error occured performing request. Status Code : {$response->getStatusCode()}. Reason : {$response->getReasonPhrase()}", 500); } //end if }
/** * Set response * * @param object $response */ public function response($response) { $statusCode = (int) $response->getStatusCode(); if ($statusCode !== 200) { $this->status = static::STATUS_COMPLETED; return; } $this->status = static::STATUS_COMMENTS; $body = (string) $response->getBody(); if (!empty($body)) { $dom = new Document($body); if ($this->hasComments($dom)) { $comments = $this->extractComments($dom); $this->comments = $comments; return; } } $this->status = static::STATUS_COMPLETED; }
/** * Query the status of a message previously sent. * * Use OSS_Service_Clickatll_Abstract::$MESSAGE_STATES and OSS_Service_Clickatll_Abstract::getMessageStateDescription() * to interpret the state. * * @throws OSS_Service_Clickatell_Exception * @param $msgid string The message ID to query * @returns string */ public function queryMessage($msgid) { $this->getHttpClient()->setParameterGet('apimsgid', $msgid); $this->call(OSS_Service_Clickatell_Http::API_METHOD_QUERY); $data = explode(' ', $this->_response->getBody()); if ($data[0] == 'ID:') { return $data[3]; } throw new OSS_Service_Clickatell_Exception('Unknown response for Clickatell message query: ' . $this->_response->getBody()); }
/** * Helper function for getNewsContent to get video/audio content if $imageobj is a video/audio object if using Zenpage CombiNews * * @param object $imageobj The object of an image */ function getNewsVideoContent($imageobj) { global $_zp_flash_player, $_zp_current_image, $_zp_gallery, $_zp_page; $videocontent = ""; $ext = strtolower(strrchr($imageobj->getFullImage(), ".")); switch ($ext) { case '.flv': case '.mp3': case '.mp4': if (is_null($_zp_flash_player)) { $videocontent = '<img src="' . WEBPATH . '/' . ZENFOLDER . '/images/err-noflashplayer.png" alt="' . gettext('No flash player installed.') . '" />'; } else { $_zp_current_image = $imageobj; $videocontent = $_zp_flash_player->getPlayerConfig(getFullNewsImageURL(), getNewsTitle(), $_zp_current_image->get("id")); } break; case '.3gp': case '.mov': $videocontent = $imageobj->getBody(); break; } return $videocontent; }
/** * Get the details of the required request * @return object */ private function data() { $result = json_decode($this->response->getBody()); return $result->data; }
/** Decode the response for json object * * @param object $response */ private function getDecode($response) { $data = $response->getBody(); return $data; }
/** Decode the response from the curl call * * @param object $response */ private function getDecode($response) { $data = $response->getBody(); $json = json_decode($data); return $json; }
/** * Parse the reponse into a formatted array * also set the status code and status message * @param object $response * @return array */ protected function parseResponse($response) { // echo $response->getStatusCode(); // 200 // echo $response->getReasonPhrase(); // OK // echo $response->getProtocolVersion(); // 1.1 if ($response->getStatusCode() != 200) { // throw exception?? } $xml = (string) $response->getBody(); $xml = simplexml_load_string($xml); $json = json_encode($xml); $this->response = json_decode($json, TRUE); if (!isset($this->response['message'])) { $this->setStatus(999, 'XML WAS NOT FOUND'); return; } // Check if we have an error $this->setStatus($this->response['message']['code'], $this->response['message']['text']); // If request was succesful then parse the result if ($this->isSuccessful()) { if ($this->response['response'] && isset($this->response['response']['results']) && count($this->response['response']['results'])) { foreach ($this->response['response']['results'] as $result) { if (isset($result[0])) { // multiple results foreach ($result as $r) { $this->results[$r['zpid']] = $r; } } else { // one result $this->results[$result['zpid']] = $result; } } } } return isset($this->response['response']) ? $this->response['response'] : $this->response; }
/** * Log the api request that resulted in an error * * @param object $response the apiClient response object * @param object $request the apiClient request object * @param string $httpVerb GET | POST | PUT * @param string $endpoint full url to endpoint * @param array $data the data that was passed to the request * @return void */ public function logError($response, $request, $httpVerb, $endpoint, $data) { // Info variables $code = null; $body = null; // Set info variables if we have a response from the api if ($response) { $code = $response->getStatusCode(); $body = $response->getBody(); } // Set message based on code error $message = 'API Response Error: '; switch ($code) { // Networking error case null: $message .= 'Could Not Make A Connection'; break 1; // Server error // Server error case 500: $message .= 'Internal Server Error'; break 1; // Server error // Server error case 503: $message .= 'Service Unavailable'; break 1; } // Log this error \Log::error($message, ['code' => $code, 'body' => $body, 'httpVerb' => $httpVerb, 'endpoint' => $endpoint, 'data' => $data]); // 10.5.3 502 Bad Gateway // Translate api 500 error responses as 502's from the website if ($code === 500) { abort(502); } // "10.5.5 504 Gateway Timeout" // Show api communication error page // only for networking errors "null" to the api if ($code === null || $code === 503) { abort(504); } }
/** * Get JSON object from the response. * * @param object $response * @param bool $asArray * @return object */ public function getJson($response, $asArray = false) { return json_decode($response->getBody(), $asArray); }