<commit_before><?php
/**
 * Created by PhpStorm.
 * User: tspycher
 * Date: 22/06/14
 * Time: 12:59
 */

namespace Zerodine\DashboardBundle\Twitter;


class Twitter {
    const USER_TIMELINE = "user_timeline";
    const MENTIONS_TIMELINE = "mentions_timeline";
    const HOME_TIMELINE = "home_timeline";
    const RETWEETS_OF_ME = "retweets_of_me";

    protected $username;
    protected $consumer_key;
    protected $consumer_secret;
    protected $oauth_access_token;
    protected $oauth_access_token_secret;

    function __construct($username, $consumer_key, $consumer_secret, $oauth_access_token, $oauth_access_token_secret)
    {
        $this->username = $username;
        $this->consumer_key = $consumer_key;
        $this->consumer_secret = $consumer_secret;
        $this->oauth_access_token = $oauth_access_token;
        $this->oauth_access_token_secret = $oauth_access_token_secret;
    }

    public function getUsername() {
        return $this->username;
    }

    public function followers() {
        $url = "followers/ids.json";
        $data = $this->call($url);
        if ($data) {
            return count($data['ids']);
        }

        return 0;
    }

    public function collect($num = 10) {
        $url = "statuses/".self::USER_TIMELINE.".json";
        //  create request
        $request = array(
            'screen_name'       => $this->username,
            'count'             => $num
        );

        $data = array();
        foreach($this->call($url, $request) as $tweet) {
            $data[strtotime($tweet['created_at'])] = array(
                'text' => $tweet['text'],
                'url' => sprintf('https://twitter.com/%s/status/%d',$this->username, $tweet['id']),
                'created_at' => $tweet['created_at']
            );
        }<commit_msg>Twitter does now handle errors correctly<commit_after><?php
/**
 * Created by PhpStorm.
 * User: tspycher
 * Date: 22/06/14
 * Time: 12:59
 */

namespace Zerodine\DashboardBundle\Twitter;


class Twitter {
    const USER_TIMELINE = "user_timeline";
    const MENTIONS_TIMELINE = "mentions_timeline";
    const HOME_TIMELINE = "home_timeline";
    const RETWEETS_OF_ME = "retweets_of_me";

    protected $username;
    protected $consumer_key;
    protected $consumer_secret;
    protected $oauth_access_token;
    protected $oauth_access_token_secret;

    function __construct($username, $consumer_key, $consumer_secret, $oauth_access_token, $oauth_access_token_secret)
    {
        $this->username = $username;
        $this->consumer_key = $consumer_key;
        $this->consumer_secret = $consumer_secret;
        $this->oauth_access_token = $oauth_access_token;
        $this->oauth_access_token_secret = $oauth_access_token_secret;
    }

    public function getUsername() {
        return $this->username;
    }

    public function followers() {
        $url = "followers/ids.json";
        $data = $this->call($url);
        if (!empty($data) and !array_key_exists('errors', $data)) {
            return count($data['ids']);
        }

        return 0;
    }

    public function collect($num = 10) {
        $url = "statuses/".self::USER_TIMELINE.".json";
        //  create request
        $request = array(
            'screen_name'       => $this->username,
            'count'             => $num
        );

        $data = array();
        foreach($this->call($url, $request) as $tweet) {
            $data[strtotime($tweet['created_at'])] = array(
                'text' => $tweet['text'],
                'url' => sprintf('https://twitter.com/%s/status/%d',$this->username, $tweet['id']),
                'created_at' => $tweet['created_at']
            );
        }
{'fraction_non_alphanumeric': 0.1396103896103896, 'fraction_numerical': 0.007034632034632035, 'mean_word_length': 2.4910292728989614, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3219156', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1153, 'n_words': 206}