How to consume twitter / datasift stream with rails on geroku

How can I use a streaming api (e.g. twitter streaming api) with rails on the hero? Will this include saving a script with a worker that consumes a thread? If there are any existing resources that document this, please link, I have not yet been able to find a lot.

+3
source share
2 answers

Your two options are to use a working dyno to run a script that consumes a stream and write it to the data store (your database, etc.), or to extract parts of the stream on the fly in your rails application as part of your query response HTTP

, , .

+3

, ...

API Heroku - EventMachine

- :

EM.schedule do
  http = EM::HttpRequest.new(STREAMING_URL).get :head => { 'Authorization' => [ 'USERNAME', 'PASSWORD' ] }
  buffer = ""
  http.stream do |chunk|
    buffer += chunk
    while line = buffer.slice!(/.+\r?\n/)
      handle_tweet JSON.parse(line)
    end
  end
end

. , Joslyn Esser Kenne Jima

0

All Articles