Skip to content

Instantly share code, notes, and snippets.

@tisba
Created April 11, 2010 14:44
Show Gist options
  • Select an option

  • Save tisba/362790 to your computer and use it in GitHub Desktop.

Select an option

Save tisba/362790 to your computer and use it in GitHub Desktop.
require "rubygems"
require "active_support/core_ext"
require "curb"
require "yajl"
class CouchDBChanges
def self.consume(database_url, opts={}, &block)
opts = {:feed => :continuous}.merge(opts)
parser = Yajl::Parser.new()
parser.on_parse_complete = block
changes = Curl::Easy.new("#{database_url}/_changes?#{opts.to_param}")
changes.headers["Accept"] = "application/json"
changes.on_body { |data_chunk| parser << data_chunk; data_chunk.length }
changes.perform
end
end
CouchDBChanges.consume("http://localhost:5984/foo") do |change|
puts change.inspect
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment