You are here

protected static function TwitterProfile::buildQuery in Twitter Profile Widget 3.x

Same name and namespace in other branches
  1. 8.2 src/TwitterProfile.php \Drupal\twitter_profile_widget\TwitterProfile::buildQuery()
  2. 8 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 66

Class

TwitterProfile
Class TwitterProfile.

Namespace

Drupal\twitter_profile_widget

Code

protected static function buildQuery($account, $type = '', $timeline = '', $search = '', $replies = 1, $retweets = 1) {
  switch ($type) {
    case 'timeline':
      $list_id = '';
      $lists = self::request('/lists/list.json?screen_name=' . $account);
      foreach ($lists as $list) {
        \Drupal::logger('twitter_profile_widget')
          ->notice(serialize($list));
        if ($list['name'] === $timeline) {
          $list_id = $list['id'];
        }
      }
      $url = '/lists/statuses.json';
      $params = [
        'count' => 10,
        'list_id' => $list_id,
        'owner_screen_name' => $account,
        'include_rts' => $retweets,
      ];
      if ($replies == 0) {
        $params['exclude_replies'] = 1;
      }
      break;
    case 'favorites':
      $url = '/favorites/list.json';
      $params = [
        'count' => 10,
        'screen_name' => $account,
      ];
      break;
    case 'search':
      $url = '/search/tweets.json';
      $params = [
        'q' => $search,
        'count' => 10,
      ];
      break;
    default:

      // Default to getting Tweets from a user.
      $url = '/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 . $getfield;
}