Created
April 11, 2010 14:44
-
-
Save tisba/362790 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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