コード例 #1
0
 /**
  * Performs the request to make the deployment
  *
  * @param string $description
  * @param bool $change
  * @param bool $user
  *
  * @return bool|string
  */
 public function setDeployment($description, $change = false, $user = false)
 {
     $apiUrl = $this->config->getNewRelicApiUrl();
     if (empty($apiUrl)) {
         $this->logger->notice('New Relic API URL is blank, using fallback URL');
         $apiUrl = self::API_URL;
     }
     /** @var \Magento\Framework\HTTP\ZendClient $client */
     $client = $this->clientFactory->create();
     $client->setUri($apiUrl);
     $client->setMethod(ZendClient::POST);
     $client->setHeaders(['x-api-key' => $this->config->getNewRelicApiKey()]);
     $params = ['deployment[app_name]' => $this->config->getNewRelicAppName(), 'deployment[application_id]' => $this->config->getNewRelicAppId(), 'deployment[description]' => $description, 'deployment[changelog]' => $change, 'deployment[user]' => $user];
     $client->setParameterPost($params);
     try {
         $response = $client->request();
     } catch (\Zend_Http_Client_Exception $e) {
         $this->logger->critical($e);
         return false;
     }
     if ($response->getStatus() < 200 || $response->getStatus() > 210) {
         $this->logger->warning('Deployment marker request did not send a 200 status code.');
         return false;
     }
     return $response->getBody();
 }
コード例 #2
0
 /**
  * Returns all set custom parameters as JSON string
  *
  * @return string
  */
 protected function getJsonForResponse()
 {
     $json = ['eventType' => 'Cron', 'appName' => $this->config->getNewRelicAppName(), 'appId' => $this->config->getNewRelicAppId()];
     $jsonArrayKeys = array_keys($json);
     foreach ($jsonArrayKeys as $jsonKey) {
         if (array_key_exists($jsonKey, $this->customParameters)) {
             unset($this->customParameters[$jsonKey]);
         }
     }
     $json = array_merge($json, $this->customParameters);
     return $this->jsonEncoder->encode($json);
 }