lib/hse/remote.rb in hse-0.0.1 vs lib/hse/remote.rb in hse-0.1.14
- old
+ new
@@ -46,9 +46,30 @@
response = Typhoeus::Request.get(path)
puts "GET Response: #{response.code} #{response.body[0..200]}"
response.code == 200 ? response.body : nil
end
+ def user email, push
+ server = "#{db_url}".split("/")[0..-2].join("/")
+ path = "#{server}/_users/org.couchdb.user:#{email}"
+ response = Typhoeus::Request.get(path)
+ #puts "GET Response: #{response.code} #{response.body[0..200]}"
+ response.code == 200 ? response.body : nil
+ user = JSON.parse(response.body)
+ puts user.inspect
+ return unless push
+ # curl -vX PUT $HOST/_users/org.couchdb.user:bob -d '{"name":"bob", "password":"bobspassword", "roles":[], "type":"user"}' -H "Content-Type: application/json"
+ picture = email.split("@").first
+ id = "org.couchdb.user:#{email}"
+ newuser = {type:"user", roles:[], _id: id, name: email, password:email, email: email, picture: picture, iterations:1000}
+ newuser["_rev"] = user["_rev"] if user
+ json = newuser.to_json
+ path = "#{server}/_users/#{id}"
+ #headers = {"Content-Type" => "application/json"}
+ response = Typhoeus::Request.put(path, body:json)
+ puts "PUT Response: #{response.code} #{response.body[0..200]}"
+ end
+
def get_doc_revision doc
puts "getting current revision"
current = get doc
if current
current_json = JSON.parse(current)