]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/TwitterBridge/scripts/streamtest.php
Make it clearer that we're handling group IDs
[quix0rs-gnu-social.git] / plugins / TwitterBridge / scripts / streamtest.php
index a175c1efa54e479ef2cb52cecec46adffbb55927..a642920cee908e09b0363c03a0c9cc52c4958dd2 100644 (file)
@@ -28,7 +28,7 @@
 define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
 
 $shortoptions = 'n:';
-$longoptions = array('nick=','import','all');
+$longoptions = array('nick=','import','all','apiroot=');
 
 $helptext = <<<ENDOFHELP
 USAGE: streamtest.php -n <username>
@@ -36,6 +36,7 @@ USAGE: streamtest.php -n <username>
   -n --nick=<username> Local user whose Twitter timeline to watch
      --import          Experimental: run incoming messages through import
      --all             Experimental: run multiuser; requires nick be the app owner
+     --apiroot=<url>   Provide alternate streaming API root URL
 
 Attempts a User Stream connection to Twitter as the given user, dumping
 data as it comes.
@@ -43,8 +44,8 @@ data as it comes.
 ENDOFHELP;
 
 require_once INSTALLDIR.'/scripts/commandline.inc';
-require_once dirname(dirname(__FILE__)) . '/jsonstreamreader.php';
-require_once dirname(dirname(__FILE__)) . '/twitterstreamreader.php';
+require_once dirname(dirname(__FILE__)) . '/lib/jsonstreamreader.php';
+require_once dirname(dirname(__FILE__)) . '/lib/twitterstreamreader.php';
 
 if (have_option('n')) {
     $nickname = get_option_value('n');
@@ -62,12 +63,7 @@ if (have_option('n')) {
  */
 function twitterAuthForUser(User $user)
 {
-    $flink = Foreign_link::getByUserID($user->id,
-                                       TWITTER_SERVICE);
-    if (!$flink) {
-        throw new ServerException("No Twitter config for this user.");
-    }
-
+    $flink = Foreign_link::getByUserID($user->id, TWITTER_SERVICE);
     $token = TwitterOAuthClient::unpackToken($flink->credentials);
     if (!$token) {
         throw new ServerException("No Twitter OAuth credentials for this user.");
@@ -86,7 +82,12 @@ function siteStreamForOwner(User $user)
 {
     // The user we auth as must be the owner of the application.
     $auth = twitterAuthForUser($user);
-    $stream = new TwitterSiteStream($auth);
+
+    if (have_option('apiroot')) {
+        $stream = new TwitterSiteStream($auth, get_option_value('apiroot'));
+    } else {
+        $stream = new TwitterSiteStream($auth);
+    }
 
     // Pull Twitter user IDs for all users we want to pull data for
     $userIds = array();
@@ -107,7 +108,7 @@ function siteStreamForOwner(User $user)
 }
 
 
-$user = User::staticGet('nickname', $nickname);
+$user = User::getKV('nickname', $nickname);
 global $myuser;
 $myuser = $user;
 
@@ -164,11 +165,7 @@ $stream->hookEvent('status', function($data, $context) {
         $importer = new TwitterImport();
         printf("\timporting...");
         $notice = $importer->importStatus($data);
-        if ($notice) {
-            global $myuser;
-            Inbox::insertNotice($myuser->id, $notice->id);
-            printf(" %s\n", $notice->id);
-        } else {
+        if (!$notice instanceof Notice) {
             printf(" FAIL\n");
         }
     }