public function testGetInstance() { $stream_data = $this->setUpData(true); $twitter_data = $this->setUpTwitterData(); $consumer_user_stream = ConsumerUserStream::getInstance('token', 'secret'); $this->assertNotNull($consumer_user_stream); }
/** * @return string */ public function consume() { $logger = Logger::getInstance('stream_log_location'); $logger->logInfo("in StreamCollect2->consume()", __METHOD__ . ',' . __LINE__); if ($this->argc != 4) { $logger->logError("error: wrong number of args for StreamCollect2", __METHOD__ . ',' . __LINE__); return; } $instance_id = $this->argv[1]; $user_email = $this->argv[2]; $pw = $this->argv[3]; $output = ""; $pwd_match = false; $owner_dao = DAOFactory::getDAO('OwnerDAO'); $owner = $owner_dao->getByEmail($user_email); $passcheck = $owner_dao->getPass($user_email); if ($passcheck == $pw) { $pwd_match = true; } else { $logger->logError("ERROR: Incorrect username and password.", __METHOD__ . ',' . __LINE__); return; } if ($pwd_match && $instance_id) { $logger->logInfo("working on stream for {$user_email}", __METHOD__ . ',' . __LINE__); if (isset($instance_id)) { $logger->logInfo("setting up stream for instance {$instance_id}", __METHOD__ . ',' . __LINE__); $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $tokens = $oid->getOAuthTokens($instance_id); if (isset($tokens['oauth_access_token']) && $tokens['oauth_access_token'] != '' && isset($tokens['oauth_access_token_secret']) && $tokens['oauth_access_token_secret'] != '') { $stream = ConsumerUserStream::getInstance($tokens['oauth_access_token'], $tokens['oauth_access_token_secret']); if ($stream) { $stream->setKey($user_email, $instance_id); $stream->consume(); } else { return "Error: could not create stream object for instance {$instance_id}\n"; } } else { return "Error: could not get oauth information for user {$user_email}.\n"; } } else { return "Could not find a twitter instance for user {$user_email}.\n"; } } }
/** * @param $owner * @return */ public function consume($owner) { // This version will run just for (first) twitter instance of the given (admin) owner $instance_dao = DAOFactory::getDAO('InstanceDAO'); $instances = $instance_dao->getByOwnerAndNetwork($owner, 'twitter', true); $logger = Logger::getInstance('stream_log_location'); if (isset($instances[0])) { $instance = $instances[0]; $oid = DAOFactory::getDAO('OwnerInstanceDAO'); $tokens = $oid->getOAuthTokens($instance->id); if (isset($tokens['oauth_access_token']) && $tokens['oauth_access_token'] != '' && isset($tokens['oauth_access_token_secret']) && $tokens['oauth_access_token_secret'] != '') { $stream = ConsumerUserStream::getInstance($tokens['oauth_access_token'], $tokens['oauth_access_token_secret']); $stream->consume(); } else { $logger->logError("Error: could not get oauth information for user.", __METHOD__ . ',' . __LINE__); return; } } else { $logger->logError("Error: could not get twitter instance for user.", __METHOD__ . ',' . __LINE__); return; } }