You are here

private function Client::doRequest in Flickr API Integration 8

Guzzle request for Flickr.

Parameters

string $url: Url.

array $parameters: Parameters.

string $requestMethod: Request method.

Return value

bool|array False or array.

1 call to Client::doRequest()
Client::request in src/Service/Client.php
Flickr request.

File

src/Service/Client.php, line 228

Class

Client
Class Client.

Namespace

Drupal\flickr_api\Service

Code

private function doRequest($url, array $parameters = [], $requestMethod = 'GET') {
  if (!$this->apiKey || !$this->apiSecret) {
    $msg = $this
      ->t('Flickr API credentials are not set. It can be set on the <a href=":config_page">configuration page</a>.', [
      ':config_page' => Url::fromRoute('flickr_api.settings'),
    ]);
    $this->messenger
      ->addError($msg);
    return FALSE;
  }
  $response = $this->guzzleClient
    ->request($requestMethod, $url, [
    'query' => $parameters,
  ]);

  // TODO Error checking can be improved.
  if ($response
    ->getStatusCode() == !200) {
    return FALSE;
  }

  // TODO Add some checking.
  $body = $response
    ->getBody();

  // TODO Add some checking.
  return json_decode((string) $body, TRUE);
}