You are here

private function SendinblueHttpClient::doRequest in SendinBlue 8

Same name and namespace in other branches
  1. 8.2 src/Tools/Http/SendinblueHttpClient.php \Drupal\sendinblue\Tools\Http\SendinblueHttpClient::doRequest()

Do CURL request with authorization.

Parameters

string $resource: A request action of api.

string $method: A method of curl request.

string $input: A data of curl request.

Return value

array An associate array with respond data.

4 calls to SendinblueHttpClient::doRequest()
SendinblueHttpClient::delete in src/Tools/Http/SendinblueHttpClient.php
Delete Request of API.
SendinblueHttpClient::get in src/Tools/Http/SendinblueHttpClient.php
Get Request of API.
SendinblueHttpClient::post in src/Tools/Http/SendinblueHttpClient.php
Post Request of API.
SendinblueHttpClient::put in src/Tools/Http/SendinblueHttpClient.php
Put Request of API.

File

src/Tools/Http/SendinblueHttpClient.php, line 99

Class

SendinblueHttpClient
Sendinblue REST client.

Namespace

Drupal\sendinblue\Tools\Http

Code

private function doRequest($resource, $method, $input) {
  if (!function_exists('curl_init')) {
    $msg = 'SendinBlue requires CURL module';
    $this->loggerFactory
      ->get('sendinblue')
      ->error($msg);
    return NULL;
  }
  $called_url = $this->baseUrl . "/" . $resource;
  $options = [
    'headers' => [
      'api-key' => $this->apiKey,
      'Content-Type' => 'application/json',
    ],
    'verify' => FALSE,
  ];
  if (!empty($input)) {
    $options['body'] = $input;
  }
  try {
    $clientRequest = $this->client
      ->request($method, $called_url, $options);
    $body = $clientRequest
      ->getBody();
  } catch (RequestException $e) {
    $this->loggerFactory
      ->get('sendinblue')
      ->error('Curl error: @error', [
      '@error' => $e
        ->getMessage(),
    ]);
  }
  return Json::decode($body);
}