| 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