public
Created

  • Download Gist
changes_pub_carrot.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#!/usr/bin/ruby
 
# uses rest_client and carrot, seems to quit when no more data is in the stream
 
require 'rubygems'
require "yajl/http_stream"
require 'rest_client'
require 'carrot'
 
def main
url = "http://localhost:5984/"
db = "test"
feed_type = "continuous"
since = "0"
 
q = Carrot.queue("changes")
Yajl::HttpStream.get("#{url}#{db}/_changes?feed=#{feed_type}&since=#{since}", :symbolize_keys => true) do |hash|
if hash[:id]
p hash
json = RestClient.get("#{url}#{db}/#{hash[:id]}")
p json
q.publish(json)
end
end
end
 
main
usage
1 2 3 4 5
joe@ubuntu:~$ ruby code/changes_pub_carrot.rb
joe@ubuntu:~$ ruby code/changes_pub_carrot.rb
{:changes=>[{:rev=>"1-967a00dff5e02add41819138abb3284d"}], :id=>"3883bafcd1b1bf21ba95445137153dea", :seq=>1}
"{\"_id\":\"3883bafcd1b1bf21ba95445137153dea\",\"_rev\":\"1-967a00dff5e02add41819138abb3284d\"}\n"
joe@ubuntu:~$

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.