public function youCannotSayThat() { // Register the new behavior BaseBehaviors::add(function ($tweet) { // I know we can improve this part but this is just an example $client = new Client(['base_uri' => 'http://www.wdyl.com/']); $request = $client->request('GET', 'profanity', ['query' => ['q' => $tweet->text]]); // We should return a boolean // true to exclude the tweet, false to include it $response = json_decode($request->getBody()->getContents()); return $response->response; }, __METHOD__); return $this; }
/** * Track is the main method, you should use it with your custom logic. * This method will return the $tweet data, you can use this method * to store the tweets in your database, for example. * * @param $func * @throws TwitterStreamingException */ public function track($func) { try { $request = new Request($this->debug); $request->connect($this->method(), $this->url(), $this->params); } catch (TwitterStreamingException $e) { exit($e->getMessage()); } // Return the data retrieved and send to the callback $request->retrieve(function ($data) use($func, $request) { if (is_callable($func)) { // Execute the behaviors registered // return true to continue, return false to exclude the tweet if (BaseBehaviors::resolve($data)) { // If all the behaviors returns true, lets continue with this tweet return call_user_func($func, $data, $request); } } }); }
public function onlyRTsFromVerified() { BaseBehaviors::add(function ($tweet) { return $this->with('retweeted_status', $tweet) && $tweet->retweeted_status->user->verified; }, __METHOD__); return $this; }