Skip to content

Commit

Permalink
[DB MIGRATION REQ'D] Foursquare plugin
Browse files Browse the repository at this point in the history
Issue #718
  • Loading branch information
AaronKalair authored and ginatrapani committed Jul 19, 2012
1 parent 19d4310 commit 1e11d14
Show file tree
Hide file tree
Showing 48 changed files with 4,218 additions and 121 deletions.
31 changes: 31 additions & 0 deletions docs/source/userguide/settings/plugins/foursquare.rst
@@ -0,0 +1,31 @@
foursquare
==========

ThinkUp's foursquare plugin captures your foursquare checkins, photos and comments.


Configure the foursquare Plugin (Admin only)
--------------------------------------------

To set up the foursquare plugin:

1. Go to https://foursquare.com/oauth/ and click on "Register a New Consumer."
2. Set the application name to anything you like, perhaps "ThinkUp."
3. Set application web site to: the URL of your ThinkUp installation home page.
4. Set the callback URL to the URL displayed on the foursquare settings page in ThinkUp.
5. Fill in the CAPCTHA.
6. Click on the green "Register Application" button at the bottom of the page.
7. In ThinkUp->Settings->foursquare, fill in the foursquare-provided Client ID and Secret.

Plugin Settings
---------------

**Client ID** (required) is the Client ID provided when you register a new consumer on foursquare

**Client secret** (required) is the Client secret provided when you register a new consumer on foursquare

Add a foursquare User to ThinkUp
--------------------------------

Click on the "Add a foursquare User" button in ThinkUp->Settings->foursquare to add your foursquare user account to
ThinkUp. This button will only appear if the foursquare plugin is configured.
1 change: 1 addition & 0 deletions docs/source/userguide/settings/plugins/index.rst
Expand Up @@ -8,6 +8,7 @@ The official ThinkUp distribution comes with a set of approved plugins. Click on

expandurls
facebook
foursquare
geoencoder
googleplus
twitter
Expand Down
2 changes: 1 addition & 1 deletion extras/dev/makeplugin/makeplugin
Expand Up @@ -80,7 +80,7 @@ class $1PluginConfigurationController extends PluginConfigurationController {
public function authControl() {
\$config = Config::getInstance();
Utils::defineConstants();
Loader::definePathConstants();
\$this->setViewTemplate( THINKUP_WEBAPP_PATH.'plugins/$plugin_name_lcase/view/account.index.tpl');
\$this->addToView('message', 'Hello ThinkUp world! This is an auto-generated plugin configuration '.
'page for ' . \$this->owner->email .'.');
Expand Down
18 changes: 9 additions & 9 deletions tests/TestOfAccountConfigurationController.php
Expand Up @@ -349,7 +349,7 @@ public function testAuthControlLoggedInNotAdmin() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand All @@ -372,7 +372,7 @@ public function testAuthControlLoggedInAdmin() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -463,7 +463,7 @@ public function testAuthControlLoggedInChangePasswordSuccess() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -498,7 +498,7 @@ public function testAuthControlLoggedInChangePasswordOldPwdDoesntMatch() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -527,7 +527,7 @@ public function testAuthControlLoggedInChangePasswordOldPwdEmpty() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -556,7 +556,7 @@ public function testAuthControlLoggedInChangePasswordNewPwdsDontMatch() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -586,7 +586,7 @@ public function testAuthControlLoggedInChangePasswordNewPwdTooShort() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -617,7 +617,7 @@ public function testAuthControlLoggedInChangePasswordNewPwdNotAlphanumeric() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down Expand Up @@ -698,7 +698,7 @@ public function testResetAPIKey() {
//test if view variables were set correctly
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('installed_plugins'), 'array');
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 7);
$this->assertEqual(sizeof($v_mgr->getTemplateDataItem('installed_plugins')), 8);

$owner = $v_mgr->getTemplateDataItem('owner');
$this->assertIsA($owner, 'Owner');
Expand Down
40 changes: 32 additions & 8 deletions tests/TestOfDashboardController.php
Expand Up @@ -41,6 +41,7 @@ public function setUp(){
$webapp->registerPlugin('twitter', 'TwitterPlugin');
$webapp->registerPlugin('facebook', 'FacebookPlugin');
$webapp->registerPlugin('google+', 'GooglePlusPlugin');
$webapp->registerPlugin('foursquare', 'FoursquarePlugin');
}

public function testConstructor() {
Expand Down Expand Up @@ -77,12 +78,12 @@ public function testNoInstancesLoggedIn() {
public function testNotLoggedInNoUserOrViewSpecifiedDefaultServiceUserSet() {
$builders = $this->buildData();
//Add another public instance
$instance_builder = FixtureBuilder::build('instances', array('id'=>4, 'network_user_id'=>14,
$instance_builder = FixtureBuilder::build('instances', array('id'=>6, 'network_user_id'=>14,
'network_username'=>'jack', 'is_public'=>1, 'crawler_last_run'=>'-2d'));
$instance_owner_builder = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>4));
$instance_owner_builder = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>6));
//Set the default service user to jack, who is not last updated
$app_option_builder = FixtureBuilder::build('options', array('namespace'=>'application_options',
'option_name'=>'default_instance', 'option_value'=>'4'));
'option_name'=>'default_instance', 'option_value'=>'6'));

$controller = new DashboardController(true);
$results = $controller->go();
Expand All @@ -99,9 +100,9 @@ public function testNotLoggedInNoUserOrViewSpecifiedDefaultServiceUserSet() {
public function testNotLoggedInNoUserOrViewSpecifiedNoDefaultServiceUserSet() {
$builders = $this->buildData();
//Add another public instance
$instance_builder = FixtureBuilder::build('instances', array('id'=>4, 'network_user_id'=>14,
$instance_builder = FixtureBuilder::build('instances', array('id'=>5, 'network_user_id'=>14,
'network_username'=>'jack', 'is_public'=>1, 'crawler_last_run'=>'-2d'));
$instance_owner_builder = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>4));
$instance_owner_builder = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>5));

$controller = new DashboardController(true);
$results = $controller->go();
Expand Down Expand Up @@ -243,6 +244,20 @@ public function testLoggedInPostsGooglePlus() {
$this->assertPattern('/Export/', $results);
}

public function testLoggedInPostsFoursquare() {
$builders = $this->buildData();
$this->simulateLogin('me@example.com');
//required params
$_GET['u'] ='kim@kim.com';
$_GET['n'] = 'foursquare';
$_GET['v'] = 'posts';
$controller = new DashboardController(true);
$results = $controller->go();

$config = Config::getInstance();
$this->assertPattern('/kim@kim.com on Foursquare/', $results);
}

public function testLoggedInPostsWithUsernameApostrophe() {
$builders = $this->buildData();
$this->simulateLogin('me@example.com');
Expand Down Expand Up @@ -359,6 +374,7 @@ private function buildData($with_xss = false) {
$instance_owner_builder_3 = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>3,
'auth_error'=>'Error validating access token: Session has expired at unix time SOME_TIME. The current unix '.
'time is SOME_TIME.'));
$instance_owner_builder_4 = FixtureBuilder::build('owner_instances', array('owner_id'=>1, 'instance_id'=>4));

//Insert test data into test table
$user_builders = array();
Expand All @@ -375,15 +391,22 @@ private function buildData($with_xss = false) {
$user_builders[] = FixtureBuilder::build('users', array('user_id'=>'16', 'user_name'=>"Kim",
'last_updated'=>'-5d', 'network'=>'google+'));

$user_builders[] = FixtureBuilder::build('users', array('user_id'=>'17', 'user_name'=>"kim@kim.com",
'last_updated'=>'-5d', 'network'=>'foursquare'));

//Make public
$instance_builder_1 = FixtureBuilder::build('instances', array('id'=>1, 'network_user_id'=>'13',
'network_username'=>'ev', 'is_public'=>1, 'crawler_last_run'=>'-1d', 'network'=>'twitter'));

$instance_builder_2 = FixtureBuilder::build('instances', array('id'=>2, 'network_user_id'=>'16',
'network_username'=>"Kim", 'is_public'=>0, 'crawler_last_run'=>'-1d', 'network'=>'google+'));

$instance_builder_3 = FixtureBuilder::build('instances', array('id'=>3, 'network_user_id'=>'14',
'network_username'=>"Joe O'Malley", 'is_public'=>0, 'crawler_last_run'=>'-1d', 'network'=>'facebook'));

$instance_builder_2 = FixtureBuilder::build('instances', array('id'=>2, 'network_user_id'=>'16',
'network_username'=>"Kim", 'is_public'=>0, 'crawler_last_run'=>'-1d', 'network'=>'google+'));
$instance_builder_4 = FixtureBuilder::build('instances', array('id'=>4, 'network_user_id'=>'17',
'network_username'=>"kim@kim.com", 'is_public'=>1, 'crawler_last_run'=>'-1d',
'network'=>'foursquare'));

$post_builders = array();
//Add a bunch of posts
Expand Down Expand Up @@ -422,6 +445,7 @@ private function buildData($with_xss = false) {
}

return array($owner_builder, $instance_owner_builder_1, $instance_owner_builder_2, $instance_owner_builder_3,
$user_builders, $instance_builder_1, $instance_builder_2, $instance_builder_3, $post_builders);
$instance_owner_builder_4, $user_builders, $instance_builder_1, $instance_builder_2, $instance_builder_3,
$instance_builder_4, $post_builders);
}
}
1 change: 0 additions & 1 deletion tests/TestOfFollowerCountMySQLDAO.php
Expand Up @@ -80,7 +80,6 @@ public function testGetDayHistoryNoGapsMilestoneNotInSight() {
$dao = new FollowerCountMySQLDAO();
$result = $dao->getHistory('930061', 'twitter', 'DAY', 3);
$this->assertEqual(sizeof($result), 4, '4 sets of data returned--history, trend, and milestone, and vis_data');

$this->debug(Utils::varDumpToString($result));
//check history
$this->assertEqual(sizeof($result['history']), 3, '3 counts returned');
Expand Down
31 changes: 26 additions & 5 deletions tests/TestOfInstanceMySQLDAO.php
Expand Up @@ -740,6 +740,7 @@ public function testUpdateInstanceUsername() {

$instance = $this->DAO->getByUsername('johndoe');
$update_cnt = $this->DAO->updateUsername($instance->id, 'johndoe2');

$this->assertEqual(1, $update_cnt);
$instance = $this->DAO->getByUsername('johndoe');
$this->assertNull($instance);
Expand All @@ -749,7 +750,7 @@ public function testUpdateInstanceUsername() {

public function testGetActiveInstancesStalestFirstForOwnerByNetworkNoAuthError() {
$this->builders[] = FixtureBuilder::build('instances', array('network_user_id'=>17, 'network_username'=>'yaya',
'network'=>'twitter', 'network_viewer_id'=>17, 'crawler_last_run'=>'2010-01-21 12:00:00', 'is_active'=>1,
'network'=>'twitter', 'network_viewer_id'=>17, 'crawler_last_run'=>'2010-01-02 12:00:00', 'is_active'=>1,
'is_public'=>0));

$this->builders[] = FixtureBuilder::build('owner_instances', array('owner_id'=>3, 'instance_id'=>6,
Expand All @@ -774,9 +775,29 @@ public function testGetActiveInstancesStalestFirstForOwnerByNetworkNoAuthError()
//Should return 2 results
$result = $this->DAO->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($owner, 'twitter');
$this->assertEqual(sizeof($result), 2);
$this->assertEqual($result[0]->id, 2);
$this->assertEqual($result[0]->network_username, "jill");
$this->assertEqual($result[1]->id, 6);
$this->assertEqual($result[1]->network_username, "yaya");
$this->assertEqual($result[0]->id, 6);
$this->assertEqual($result[0]->network_username, "yaya");
$this->assertEqual($result[1]->id, 2);
$this->assertEqual($result[1]->network_username, "jill");
}

public function testCheckIfOldPostsHaveBeenArchived() {
$this->DAO = new InstanceMySQLDAO();
$builders[] = FixtureBuilder::build('instances', array('network_user_id'=>18,
'network_username'=>'johndoe', 'network'=>'foursquare', 'network_viewer_id'=>16,
'crawler_last_run'=>'2010-01-01 12:00:01', 'is_active'=>1, 'is_post_archive_loaded'=>1));
$query = $this->DAO->checkIfOldPostsHaveBeenArchived('johndoe', 'foursquare');
$this->assertTrue($query);
}

public function testUpdatePostArchivedLoaded() {
$this->DAO = new InstanceMySQLDAO();
$builders[] = FixtureBuilder::build('instances', array('network_user_id'=>19,
'network_username'=>'tyler', 'network'=>'foursquare', 'network_viewer_id'=>17,
'crawler_last_run'=>'2010-01-01 12:00:01', 'is_active'=>1, 'is_post_archive_loaded'=>0));
$this->DAO->updatePostArchivedLoaded('tyler', 'foursquare', 1);
$query = $this->DAO->checkIfOldPostsHaveBeenArchived('tyler', 'foursquare');
$this->assertTrue($query);
}
}

49 changes: 47 additions & 2 deletions tests/TestOfPlaceMySQLDAO.php
Expand Up @@ -78,7 +78,7 @@ public function testInsertPlaceBBoxOnly() {
);
$this->dao->insertPlace($place, 123456, 'twitter');
$res = $this->dao->getPlaceByID('1a16a1d70500c27d');
$this->assertEqual(sizeof($res), 10);
$this->assertEqual(sizeof($res), 12);
$this->assertEqual($res['place_id'], '1a16a1d70500c27d');
$this->assertEqual($res['name'], 'Hyde Park');
$this->assertPattern('/POINT\(-97.72446/', $res['longlat']);
Expand Down Expand Up @@ -142,7 +142,7 @@ public function testInsertPlace() {
$this->dao->insertPlace($place1, 123456, 'twitter');
$this->dao->insertPlace($place2, 123457, 'twitter');
$res = $this->dao->getPlaceByID('1a16a1d70500c27d');
$this->assertEqual(sizeof($res), 10);
$this->assertEqual(sizeof($res), 12);
$this->assertEqual($res['place_id'], '1a16a1d70500c27d');
$this->assertEqual($res['name'], 'Hyde Park');
$this->assertPattern('/POINT\(-97.72446/', $res['longlat']);
Expand All @@ -163,6 +163,51 @@ public function testInsertPlace() {
$this->assertEqual($res['post_id'], 123457);
}

public function testInsertGenericPlace() {
// Set all possible fields
$places['id'] = 123;
$places['place_type'] = "Park";
$places['name'] = "A Park";
$places['full_name'] = "The Greatest Park";
$places['country_code'] = "UK";
$places['country'] = "United Kingdom";
$places['icon'] = "http://www.iconlocation.com";
$places['lat_lng'] = 'POINT(51.514 -0.1167)';
$places['bounding_box'] = 'POLYGON((-0.213503 51.512805,-0.105303 51.512805,-0.105303 51.572068,'.
'-0.213503 51.572068, -0.213503 51.512805)))';
$places['map_image'] = "http://www.mapimage.com";

// Insert the place
$this->dao->insertGenericPlace($places, 1234, 'foursquare');
// Get the place from the database
$res = $this->dao->getPlaceByID('123');

// Check all 12 fields were returned
$this->assertEqual(sizeof($res), 12);
// Check the place ID was set correctly
$this->assertEqual($res['place_id'], '123');
// Check the type was set correctly
$this->assertEqual($res['place_type'], 'Park');
// Check the name was set correctly
$this->assertEqual($res['name'], 'A Park');
// Check the fullname was set correctly
$this->assertEqual($res['full_name'], 'The Greatest Park');
// Check the country code was set correctly
$this->assertEqual($res['country_code'], 'UK');
// Check the country was set correctly
$this->assertEqual($res['country'], 'United Kingdom');
// Check the icon was set correctly
$this->assertEqual($res['icon'], 'http://www.iconlocation.com');
// Check the point was set correctly
$this->assertPattern('/POINT\(51.514/', $res['longlat']);
$this->assertPattern('/ -0.1167/', $res['longlat']);
// Check the bounding box was set correctly
$this->assertEqual($res['bounding_box'], 'POLYGON((-0.213503 51.512805,-0.105303 51.512805,-0.105303 51.572068,'.
'-0.213503 51.572068,-0.213503 51.512805))');
// Check the map image was set correctly
$this->assertEqual($res['map_image'], 'http://www.mapimage.com');
}

public function testInsertPlacePointCoordsOnly() {
$place = array (
'point_coords' => array(
Expand Down
2 changes: 1 addition & 1 deletion tests/TestOfPluginMySQLDAO.php
Expand Up @@ -61,7 +61,7 @@ public function testGetInstalledPlugins() {
$dao = new PluginMySQLDAO();

$plugins = $dao->getInstalledPlugins();
$this->assertEqual(count($plugins), 7);
$this->assertEqual(count($plugins), 8);

usort($plugins, 'TestOfPluginMySQLDAO::pluginSort');
$this->assertEqual($plugins[0]->name,"Expand URLs");
Expand Down

0 comments on commit 1e11d14

Please sign in to comment.