Encoding.default_internal = 'UTF-8'
|
|
require 'rubygems'
|
|
require 'bundler/setup'
|
|
require 'json'
|
|
|
|
Bundler.require
|
|
|
|
$config = IniFile.load('../.env')
|
|
|
|
client = Twitter::Streaming::Client.new do |config|
|
|
config.consumer_key = $config['global']['TWITTER_CONSUMER_KEY']
|
|
config.consumer_secret = $config['global']['TWITTER_CONSUMER_SECRET']
|
|
config.access_token = $config['global']['TWITTER_ACCESS_TOKEN']
|
|
config.access_token_secret = $config['global']['TWITTER_ACCESS_TOKEN_SECRET']
|
|
end
|
|
|
|
client.user 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'}
|
|
}
|
|
when Twitter::DirectMessage
|
|
puts "Got a DM"
|
|
when Twitter::Streaming::DeletedTweet
|
|
puts "Someone deleted a tweet"
|
|
when Twitter::Streaming::StallWarning
|
|
puts "Falling behind!"
|
|
end
|
|
end
|
|
|