Browse Source

switch to streaming search api

master
Aaron Parecki 5 years ago
parent
commit
92b2ed86ae
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 8 additions and 3 deletions
  1. +2
    -0
      .env.example
  2. +6
    -3
      twitter/stream.rb

+ 2
- 0
.env.example View File

@ -5,6 +5,8 @@ APP_DEBUG=true
APP_LOG_LEVEL=debug APP_LOG_LEVEL=debug
APP_URL=http://localhost APP_URL=http://localhost
GAME_HASHTAG="#thegame"
DB_CONNECTION=mysql DB_CONNECTION=mysql
DB_HOST=127.0.0.1 DB_HOST=127.0.0.1
DB_PORT=3306 DB_PORT=3306

+ 6
- 3
twitter/stream.rb View File

@ -14,12 +14,16 @@ client = Twitter::Streaming::Client.new do |config|
config.access_token_secret = $config['global']['TWITTER_ACCESS_TOKEN_SECRET'] config.access_token_secret = $config['global']['TWITTER_ACCESS_TOKEN_SECRET']
end end
client.user do |obj|
filters = {
track: $config['global']['GAME_HASHTAG']
}
client.filter(filters) do |obj|
case obj case obj
when Twitter::Tweet when Twitter::Tweet
puts "Got a tweet" puts "Got a tweet"
puts obj.to_h.to_json puts obj.to_h.to_json
response = HTTParty.post "#{$config['global']['APP_URL']}/twitter/stream", { response = HTTParty.post "#{$config['global']['APP_URL']}/twitter/stream", {
body: obj.to_h.to_json, body: obj.to_h.to_json,
headers: {'Content-Type' => 'application/json'} headers: {'Content-Type' => 'application/json'}
@ -32,4 +36,3 @@ client.user do |obj|
puts "Falling behind!" puts "Falling behind!"
end end
end end

Loading…
Cancel
Save