Skip to content

Instantly share code, notes, and snippets.

@mfo
Created July 13, 2016 10:02
Show Gist options
  • Save mfo/d4b59d66d7ef626f2a62685d9a4520dd to your computer and use it in GitHub Desktop.
Save mfo/d4b59d66d7ef626f2a62685d9a4520dd to your computer and use it in GitHub Desktop.
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