Skip to content

Instantly share code, notes, and snippets.

@joewilliams
Created August 6, 2010 23:26
Show Gist options
  • Select an option

  • Save joewilliams/512195 to your computer and use it in GitHub Desktop.

Select an option

Save joewilliams/512195 to your computer and use it in GitHub Desktop.
require 'rubygems'
require "yajl"
require 'em-http'
require 'happening'
def main
EM.run {
parser = Yajl::Parser.new
parser.on_parse_complete = (Proc.new { |hash|
if hash["id"]
http = EM::HttpRequest.new("http://localhost:5984/test/#{hash["id"]}").get
http.stream { |chunk|
s3 = Happening::S3::Item.new('joe-test', hash["id"], :aws_access_key_id => 'asdf', :aws_secret_access_key => 'asdf')
s3.put(chunk)
}
end
})
changes = EM::HttpRequest.new("http://localhost:5984/test/_changes?feed=continuous").get :timeout => 30
changes.stream { |chunk|
puts chunk.inspect
STDOUT.flush
parser.parse(chunk)
}
}
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment