You are here

protected function InstagramBlockBlock::fetchData in Instagram Block 8.2

Same name and namespace in other branches
  1. 8.3 src/Plugin/Block/InstagramBlockBlock.php \Drupal\instagram_block\Plugin\Block\InstagramBlockBlock::fetchData()

Sends a http request to the Instagram API Server.

Parameters

string $url: URL for http request.

Return value

bool|mixed The encoded response containing the instagram images or FALSE.

1 call to InstagramBlockBlock::fetchData()
InstagramBlockBlock::build in src/Plugin/Block/InstagramBlockBlock.php
Builds and returns the renderable array for this block plugin.

File

src/Plugin/Block/InstagramBlockBlock.php, line 241

Class

InstagramBlockBlock
Provides an Instagram block.

Namespace

Drupal\instagram_block\Plugin\Block

Code

protected function fetchData($url) {
  try {
    $response = $this->httpClient
      ->get($url, [
      'headers' => [
        'Accept' => 'application/json',
      ],
    ]);
    $data = Json::decode($response
      ->getBody());
    if (empty($data)) {
      $this->loggerFactory
        ->get('instagram_block')
        ->error($this
        ->t('Invalid JSON or empty body returned by Instagram'));
      return FALSE;
    }
    return $data;
  } catch (RequestException $e) {
    $this->loggerFactory
      ->get('instagram_block')
      ->error($e
      ->getMessage());
    return FALSE;
  }
}