You are here

protected function TwitterProfile::buildQuery in Twitter Profile Widget 8.2

Same name and namespace in other branches
  1. 8 src/TwitterProfile.php \Drupal\twitter_profile_widget\TwitterProfile::buildQuery()
  2. 3.x src/TwitterProfile.php \Drupal\twitter_profile_widget\TwitterProfile::buildQuery()

Build the full REST URL, depending on user-selected type.

Return value

string A URL, e.g., https://api.twitter.com/1.1/favorites/list.json?count=2&screen_name=episod

1 call to TwitterProfile::buildQuery()
TwitterProfile::pull in src/TwitterProfile.php
Pull tweets from the Twitter API.

File

src/TwitterProfile.php, line 95

Class

TwitterProfile
Class TwitterProfile.

Namespace

Drupal\twitter_profile_widget

Code

protected function buildQuery($account, $type = '', $timeline = '', $search = '', $replies = 1, $retweets = 1) {
  switch ($type) {
    case 'timeline':
      $url = 'https://api.twitter.com/1.1/lists/statuses.json';
      $params = [
        'count' => 10,
        'slug' => $timeline,
        'owner_screen_name' => $account,
        'include_rts' => $retweets,
      ];
      if ($replies == 0) {
        $params['exclude_replies'] = 1;
      }
      break;
    case 'favorites':
      $url = 'https://api.twitter.com/1.1/favorites/list.json';
      $params = [
        'count' => 10,
        'screen_name' => $account,
      ];
      break;
    case 'search':
      $url = 'https://api.twitter.com/1.1/search/tweets.json';
      $params = [
        'q' => $search,
        'count' => 10,
      ];
      break;
    default:

      // Default to getting Tweets from a user.
      $url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
      $params = [
        'count' => 10,
        'screen_name' => $account,
        'include_rts' => $retweets,
      ];
      if ($replies == 0) {
        $params['exclude_replies'] = 1;
      }
      break;
  }
  $getfield = '?' . http_build_query($params);
  return [
    'url' => $url,
    'getfield' => $getfield,
  ];
}