/** @noinspection PhpUnusedPrivateMethodInspection
  * @param string       $endpoint
  * @param array        $url_parameters
  * @param string|array $query_parameters
  * @param bool         $try_to_auth if set to false, no access token will be used
  * @param mixed|null   $originalData
  *
  * @return \MicrosoftTranslator\Response
  * @throws \MicrosoftTranslator\Exception
  * @codeCoverageIgnore
  */
 private function delete($endpoint, $url_parameters = array(), $query_parameters = array(), $try_to_auth = true, $originalData = null)
 {
     $url = $this->buildUrl($endpoint, $url_parameters);
     $api_access_token = $try_to_auth === true ? is_null($this->api_access_token) ? $this->auth->getAccessToken() : $this->api_access_token : '';
     $query_parameters = $this->fixQueryParameters($query_parameters);
     return $this->getResponseObject($endpoint, $url_parameters, $query_parameters, $try_to_auth, $url, $this->http->delete($url, $api_access_token, $query_parameters), $originalData);
 }
 /**
  * @return array|string
  * @throws \MicrosoftTranslator\Exception
  */
 private function generateAndStoreNewAccessToken()
 {
     $url = trim($this->auth_base_url, "/ \t\n\r\v");
     $access_token = null;
     $auth = array('grant_type' => 'client_credentials', 'client_id' => $this->api_client_id, 'client_secret' => $this->api_client_secret, 'scope' => $this->api_client_scope);
     $result = $this->http->post($url, null, $auth, null);
     if (Http::isRequestOk($result)) {
         $result['http_body'] = json_decode($result['http_body'], true);
         if (!isset($result['http_body']['access_token'])) {
             throw new Exception('Access token not found in response');
         }
         if (!is_string($result['http_body']['access_token'])) {
             throw new Exception('Access token found in response but it is not a string');
         }
         $access_token = strval(@$result['http_body']['access_token']);
         $expires_in = @(int) $result['http_body']['expires_in'];
         $this->logger->debug(__CLASS__, 'oauth', sprintf('New access_token generated %s...', substr($access_token, 0, 10)));
         $this->guard->storeAccessTokenForSeconds($access_token, $expires_in);
     } else {
         $this->logger->fatal(__CLASS__, 'oauth', 'Unable to generate a new access token : ' . json_encode($result));
     }
     return $access_token;
 }