Пример #1
0
 public function crawl()
 {
     $logger = Logger::getInstance();
     $config = Config::getInstance();
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
     $owner_dao = DAOFactory::getDAO('OwnerDAO');
     $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
     $options = $plugin_option_dao->getOptionsHash('googleplus', true);
     //get cached
     $current_owner = $owner_dao->getByEmail(Session::getLoggedInUser());
     //crawl Google+ users
     $instances = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'google+');
     if (isset($options['google_plus_client_id']->option_value) && isset($options['google_plus_client_secret']->option_value)) {
         foreach ($instances as $instance) {
             $logger->setUsername(ucwords($instance->network) . ' | ' . $instance->network_username);
             $logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
             $tokens = $owner_instance_dao->getOAuthTokens($instance->id);
             $access_token = $tokens['oauth_access_token'];
             $refresh_token = $tokens['oauth_access_token_secret'];
             $instance_dao->updateLastRun($instance->id);
             $google_plus_crawler = new GooglePlusCrawler($instance, $access_token);
             $dashboard_module_cacher = new DashboardModuleCacher($instance);
             try {
                 $google_plus_crawler->initializeInstanceUser($options['google_plus_client_id']->option_value, $options['google_plus_client_secret']->option_value, $access_token, $refresh_token, $current_owner->id);
                 $google_plus_crawler->fetchInstanceUserPosts();
             } catch (Exception $e) {
                 $logger->logUserError('EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__);
             }
             $dashboard_module_cacher->cacheDashboardModules();
             $instance_dao->save($google_plus_crawler->instance, 0, $logger);
             $logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
         }
     }
 }
Пример #2
0
 public function testFetchInstanceUserPosts()
 {
     $builders = self::buildData();
     $gpc = new GooglePlusCrawler($this->profile1_instance, 'fauxaccesstoken', 10);
     $gpc->fetchInstanceUserPosts();
     $post_dao = new PostMySQLDAO();
     $post = $post_dao->getPost('z12is5v4snurihgdl22iiz3pjrnws3lle', 'google+', true);
     $this->assertIsA($post, 'Post');
     $this->assertEqual($post->post_text, 'I've got a date with the G+ API this weekend to make a ThinkUp plugin!');
     $this->assertEqual($post->reply_count_cache, 24);
     $this->assertEqual($post->favlike_count_cache, 159);
     $this->assertEqual($post->retweet_count_cache, 29);
     $this->assertIsA($post->links[0], 'Link');
     $this->assertEqual($post->links[0]->url, 'http://googleplusplatform.blogspot.com/2011/09/getting-started-on-google-api.html');
     $this->assertEqual($post->links[0]->title, 'Getting Started on the Google+ API - Google+ Platform Blog');
     $this->assertEqual($post->links[0]->description, 'Official source of information about the Google+ platform');
     $this->assertEqual($post->links[0]->image_src, '');
     //test reshare with annotation
     $post = $post_dao->getPost('z12pcfdr2wvyzjfff22iiz3pjrnws3lle', 'google+', true);
     $this->assertIsA($post, 'Post');
     $this->assertEqual($post->post_text, 'Really fun episode this week.');
     //test reshare without annotation
     $post = $post_dao->getPost('z12pxlfjxpujivy3e230t3aqawfoz1qf1', 'google+', true);
     $this->assertIsA($post, 'Post');
     $this->assertEqual($post->post_text, '');
     //now crawl on updated data and assert counts and post text get updated in database
     $gpc->api_accessor->setDataLocation('new_counts/');
     $gpc->fetchInstanceUserPosts();
     $post = $post_dao->getPost('z12is5v4snurihgdl22iiz3pjrnws3lle', 'google+', true);
     $this->assertEqual($post->reply_count_cache, 64);
     $this->assertEqual($post->favlike_count_cache, 199);
     $this->assertEqual($post->retweet_count_cache, 69);
     $this->assertEqual($post->post_text, "I've got a date with the G+ API this weekend to make a ThinkUp plugin! Updated: New text here!");
 }