summaryrefslogtreecommitdiff
path: root/lib/leap_ca/couch_stream.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/leap_ca/couch_stream.rb')
-rw-r--r--lib/leap_ca/couch_stream.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/leap_ca/couch_stream.rb b/lib/leap_ca/couch_stream.rb
new file mode 100644
index 0000000..ed56db2
--- /dev/null
+++ b/lib/leap_ca/couch_stream.rb
@@ -0,0 +1,21 @@
+class CouchStream
+ def initialize(database_url)
+ @database_url = database_url
+ end
+
+ def get(path, options)
+ url = url_for(path, options)
+ # puts url
+ Yajl::HttpStream.get(url, :symbolize_keys => true) do |hash|
+ yield(hash)
+ end
+ end
+
+ protected
+
+ def url_for(path, options = {})
+ url = [@database_url, path].join('/')
+ url += '?' if options.any?
+ url += options.map {|k,v| "#{k}=#{v}"}.join('&')
+ end
+end