function twitter_puller::get_items in Twitter Pull 6
Same name and namespace in other branches
- 6.2 twitter_pull.class.inc \twitter_puller::get_items()
- 7.2 twitter_pull.class.inc \twitter_puller::get_items()
- 7 twitter_pull.class.inc \twitter_puller::get_items()
File
- ./
twitter_pull.class.inc, line 42 - twitter pull class implementation
Class
- twitter_puller
- @file twitter pull class implementation
Code
function get_items() {
$prefix = drupal_substr($this->twitkey, 0, 1);
$slash = strpos($this->twitkey, '/', 1);
$num = intval($this->num_items);
// lists have the format @username/listname
if ($prefix == '@' && $slash !== FALSE) {
$username = drupal_substr($this->twitkey, 1, $slash - 1);
$listname = drupal_substr($this->twitkey, $slash + 1);
$url = 'http://api.twitter.com/1/' . urlencode($username) . '/lists/' . urlencode($listname) . '/statuses.json?per_page=' . $num;
}
elseif ($prefix == "@") {
$key = drupal_substr($this->twitkey, 1);
$url = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=' . urlencode($key) . '&include_rts=true&count=' . $num;
}
else {
if ($num > 100) {
$num = 100;
}
$url = 'http://search.twitter.com/search.json?q=' . urlencode($this->twitkey) . '&rpp=' . $num;
}
$ret = drupal_http_request($url);
if ($ret->code < 200 || $ret->code > 399) {
$errmsg = json_decode($ret->data);
$errmsg = t('The error message received was: @message.', array(
'@message' => $errmsg->error,
));
if ($ret->code == 400) {
$errmsg .= t('This site may be subject to rate limiting. For more information, see:') . 'http://apiwiki.twitter.com/Rate-limiting';
}
throw new Exception(t('Could not retrieve data from Twitter.') . ' ' . $errmsg);
}
$items = json_decode($ret->data);
$this
->parse_items($items);
}