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.

35 lines
970 B

  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. client.user do |obj|
  14. case obj
  15. when Twitter::Tweet
  16. puts "Got a tweet"
  17. puts obj.to_h.to_json
  18. response = HTTParty.post "#{$config['global']['APP_URL']}/twitter/stream", {
  19. body: obj.to_h.to_json,
  20. headers: {'Content-Type' => 'application/json'}
  21. }
  22. when Twitter::DirectMessage
  23. puts "Got a DM"
  24. when Twitter::Streaming::DeletedTweet
  25. puts "Someone deleted a tweet"
  26. when Twitter::Streaming::StallWarning
  27. puts "Falling behind!"
  28. end
  29. end