Skip to content

Instantly share code, notes, and snippets.

@joewilliams
Created December 23, 2009 21:00
Show Gist options
  • Save joewilliams/262799 to your computer and use it in GitHub Desktop.
Save joewilliams/262799 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'rest_client'
require 'yajl'
def run_ops(notifications)
url = "http://user:*****@somehost:5984"
auth_doc = '{"someuser":["_reader","_writer","_admin"],"someuser1":["_reader","_writer","_admin"]}'
case notifications["type"]
when "created"
RestClient.put("#{url}/#{notifications["db"]}", "")
RestClient.put("#{url}/#{notifications["db"]}/_local/authorization", auth_doc)
when "deleted"
RestClient.delete("#{url}/#{notifications["db"]}")
end
end
def main
run = true
parser = Yajl::Parser.new
while run do
notifications_json = gets
if notifications_json == nil
run = false
else
notifications = parser.parse(notifications_json)
run_ops(notifications)
end
end
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment