From 92b2ed86aeebbd41d1d36a653295b0faf3bf811b Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Sun, 2 Jun 2019 17:00:53 -0700 Subject: [PATCH] switch to streaming search api --- .env.example | 2 ++ twitter/stream.rb | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 4661988..e6f3601 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,8 @@ APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost +GAME_HASHTAG="#thegame" + DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 diff --git a/twitter/stream.rb b/twitter/stream.rb index 8f56270..3096548 100644 --- a/twitter/stream.rb +++ b/twitter/stream.rb @@ -14,12 +14,16 @@ client = Twitter::Streaming::Client.new do |config| config.access_token_secret = $config['global']['TWITTER_ACCESS_TOKEN_SECRET'] end -client.user do |obj| +filters = { + track: $config['global']['GAME_HASHTAG'] +} + +client.filter(filters) do |obj| case obj when Twitter::Tweet puts "Got a tweet" puts obj.to_h.to_json - + response = HTTParty.post "#{$config['global']['APP_URL']}/twitter/stream", { body: obj.to_h.to_json, headers: {'Content-Type' => 'application/json'} @@ -32,4 +36,3 @@ client.user do |obj| puts "Falling behind!" end end -