Created
July 13, 2016 10:02
-
-
Save mfo/d4b59d66d7ef626f2a62685d9a4520dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EventMachine::HttpRequest.use EventMachine::Middleware::JSONResponse | |
# prepare request | |
con = EventMachine::HttpRequest.new('https://stream.twitter.com/1.1/statuses/filter.json', { | |
connect_timeout: 0, | |
inactivity_timeout: 0, | |
keepalive: true | |
}) | |
# plug oauth | |
con.use EventMachine::Middleware::OAuth({...keys..}) | |
# setup tracking | |
options = {} | |
options['track'] = "xxx, xxx..." | |
options['locations'] = "xxx, xxx, xxx..." | |
# string buf | |
buffer = '' | |
# make con | |
http = conn.post(head: {'User-Agent' => "xxx-#{@environment}-SM", 'Keep-alive' => 'true' }, | |
body: options) | |
# process stream | |
http.stream do |chunk| | |
buffer += chunk | |
while line = buffer.slice!(/.+\r?\n/) | |
# do the job | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment