You are here

public static function TwitterProfile::request in Twitter Profile Widget 3.x

Helper method to perform the HTTP request.

Parameters

string $endpoint: The Twiter API endpoint.

Return value

mixed The Basecamp response in PHP array format, or FALSE if failed.

2 calls to TwitterProfile::request()
TwitterProfile::buildQuery in src/TwitterProfile.php
Build the full REST URL, depending on user-selected type.
TwitterProfile::pull in src/TwitterProfile.php
Pull tweets from the Twitter API.

File

src/TwitterProfile.php, line 137

Class

TwitterProfile
Class TwitterProfile.

Namespace

Drupal\twitter_profile_widget

Code

public static function request($endpoint) {
  $client = new Client();
  $headers = [
    'Authorization' => 'Bearer ' . \Drupal::state()
      ->get('twitter_api_access_token'),
    'Accept' => 'application/json',
  ];
  try {
    $response = $client
      ->request('GET', self::BASE_URI . $endpoint, [
      'headers' => $headers,
    ]);
  } catch (RequestException $e) {
    if ($e
      ->hasResponse()) {
      \Drupal::logger('twitter_profile_widget')
        ->error(Psr7\str($e
        ->getResponse()));
      return FALSE;
    }
  }
  return json_decode($response
    ->getBody(), TRUE);
}