/** * Read and process incomming data from listenable channels * @return void */ public function fire() { $today = Carbon::today(); $lastRun = Settings::get('reset_group_last_run'); if ($lastRun != $today->toDateTimeString()) { $day = strtolower($today->format('l')); $reset_groups_every_day = Settings::get('reset_groups_every_day'); $reset_groups_time = Settings::get('reset_groups_time'); if (in_array($day, $reset_groups_every_day)) { $reset_at = Carbon::parse($reset_groups_time); if ($reset_at->lte(Carbon::now())) { UserGroup::markInactiveGroups(); Settings::set('reset_group_last_run', $today->toDateTimeString()); } } } else { // \Log::info('Has already run'); } }
/** * {@inheritDoc} * @see \DMA\Friends\Classes\Notifications\Channels\Listenable::readChannel() */ public function read() { //https://api.twitter.com/1.1/search/tweets.json $url = 'https://api.twitter.com/1.1/search/tweets.json'; $requestMethod = 'GET'; $getfield = '?q=' . Settings::get('twitter_search_hashtag'); $maxId = Null; if ($sinceId = Settings::set('twitter_since_id') && ($maxId = Settings::get('twitter_max_id'))) { $getfield = $getfield . '&since_id=' . $sinceId; $getfield = $getfield . '&max_id=' . $maxId; } $client = $this->getClient(); $response = $client->setGetfield($getfield)->buildOauth($url, $requestMethod)->performRequest(); // Convert results to php objects $result = json_decode($response); // Convert tweets into messages $tweetIds = []; $messages = []; foreach ($result->statuses as $tweet) { $tweetId = $tweet->id; // Because max_id is also includes the tweet that we have already // processed if max_id is present we remove this tweet from the messages. if ($tweetId != $maxId) { $tweetIds[] = $tweet->id; $msg = new IncomingMessage($this->getKey()); $msg->from($tweet->user->id, $tweet->user->name); $msg->setContent($tweet->text); $messages[] = $msg; } } // Get max_id and since_id // Further information on this Twitter parameters go to // https://dev.twitter.com/rest/public/timelines Settings::set('twitter_max_id', min($tweetIds)); Settings::set('twitter_since_id', max($tweetIds)); return $messages; }