You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.0 KiB

  1. Encoding.default_internal = 'UTF-8'
  2. require 'rubygems'
  3. require 'bundler/setup'
  4. require 'json'
  5. Bundler.require
  6. $config = IniFile.load('../.env')
  7. client = Twitter::Streaming::Client.new do |config|
  8. config.consumer_key = $config['global']['TWITTER_CONSUMER_KEY']
  9. config.consumer_secret = $config['global']['TWITTER_CONSUMER_SECRET']
  10. config.access_token = $config['global']['TWITTER_ACCESS_TOKEN']
  11. config.access_token_secret = $config['global']['TWITTER_ACCESS_TOKEN_SECRET']
  12. end
  13. filters = {
  14. track: $config['global']['GAME_HASHTAG']
  15. }
  16. client.filter(filters) do |obj|
  17. case obj
  18. when Twitter::Tweet
  19. puts "Got a tweet"
  20. puts obj.to_h.to_json
  21. response = HTTParty.post "#{$config['global']['APP_URL']}/twitter/stream", {
  22. body: obj.to_h.to_json,
  23. headers: {'Content-Type' => 'application/json'}
  24. }
  25. when Twitter::DirectMessage
  26. puts "Got a DM"
  27. when Twitter::Streaming::DeletedTweet
  28. puts "Someone deleted a tweet"
  29. when Twitter::Streaming::StallWarning
  30. puts "Falling behind!"
  31. end
  32. end