Skip to content

Instantly share code, notes, and snippets.

@joewilliams
Created January 9, 2010 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joewilliams/272679 to your computer and use it in GitHub Desktop.
Save joewilliams/272679 to your computer and use it in GitHub Desktop.
#!/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
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:~$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment