public function actionIndex()
 {
     /**
      * GuzzleHttp\Client;
      */
     $client = new Client();
     $out = 'Connection Test Passed: ';
     $authenticated = null;
     try {
         /**
          * GuzzleHttp\Psr7\Response;
          */
         $response = $client->get('api/1/test');
         if ($response->getStatusCode() != 200) {
             $out = 'Connection Test Failed with code:' . $response->getStatusCode();
         }
         if ($response->getStatusCode() == 200) {
             //Determine Mode
             $tmp = json_decode($response->getBody()->getContents());
             $authenticated = isset($tmp->connectedUser);
         }
     } catch (\Exception $ex) {
         $out = 'Connection Test Failed with message: ' . "\n" . $ex->getMessage();
     }
     $this->stdout($out);
     if (isset($authenticated)) {
         $this->stdout('IN ' . ($authenticated ? 'AUTHENTICATED' : 'ANONYMOUS') . " MODE\n", Console::FG_GREEN, Console::BOLD);
     }
     return 0;
 }
 /**
  * 
  * @param type $topicId
  * @param type $lastUpdate
  * @return int
  */
 public function actionSync($topicId, $lastUpdate)
 {
     $topic = Topic::findOne(!is_numeric($topicId) ? ['name' => $topicId] : $topicId);
     if (NULL === $topic) {
         $this->stdout("No Such Topic \n");
         return 1;
     }
     $this->stdout('processing topic: ');
     $this->stdout($topic->name . "\n", Console::FG_GREEN, Console::BOLD);
     $client = new Client();
     //Auto scoop when condition is satisfied
     if (isset($this->module->params['autoScoopTopicCondition']) && call_user_func($this->module->params['autoScoopTopicCondition'], $topic)) {
         //     $this->stdout("auto-scooping \n");
         $client->autoScoop($topic->id, $lastUpdate);
     }
     //Syncronise Scoops
     $scoops = $client->getScoops($topic->id, $lastUpdate);
     // $this->stdout("saving scoops to local storage \n");
     foreach ($scoops as $scoop) {
         $model = $this->_sync($scoop, $topic, TRUE);
     }
     //Store suggestions
     if (isset($this->module->params['saveSuggestions']) && $this->module->params['saveSuggestions']) {
         $this->stdout("saving suggestions to local storage \n");
         foreach ($client->getSources($topic->id, $lastUpdate) as $source) {
             $source = $this->_sync($source, $topic, FALSE);
         }
     }
     return 0;
 }
 /**
  * 
  * @param integer|string $topicId
  */
 public function actionRemote($topicId)
 {
     $topic = \humanized\scoopit\models\Topic::findOne(!is_numeric($topicId) ? ['name' => $topicId] : $topicId);
     if (NULL === $topic) {
         $this->stdout("No Such Topic \n");
         return 1;
     }
     $queryParams = ['action' => 'delete'];
     $client = new Client();
     foreach ($client->getScoops($topic->id) as $remoteScoop) {
         $queryParams['id'] = $remoteScoop->id;
         $client->post('api/1/post', ['query' => $queryParams]);
     }
 }
 public function actionKeywords($topicId)
 {
     $model = Topic::findOne($topicId);
     if (!isset($model)) {
         throw new \Exception('Topic ID does not correspond to a database-entry');
     }
     $client = new Client();
     $keywordData = $client->getTopicKeywords($topicId);
     foreach ($keywordData as $keyword) {
         $this->_syncKeyword($keyword);
         $model->linkKeyword($keyword);
     }
     return 0;
 }