lib/hse/remote.rb in hse-0.1.19 vs lib/hse/remote.rb in hse-0.1.21

- old
+ new

@@ -55,26 +55,36 @@ #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_id doc + puts "getting current revision #{doc[:_id]}" + current = get_id doc[:_id] rescue nil if current - current_json = JSON.parse(current) - puts "current revision: #{current_json['_rev']}" + puts "current revision: #{current['_rev']}" end - current ? current_json['_rev'] : nil + current ? current['_rev'] : nil end - def put id, body = "" - path = "#{db_url}/#{id}" - puts "remote: PUT path #{path}" - puts "remote: PUT body: #{body[0..80]} ..." - #response = Typhoeus::Request.put(path, :body => body) - puts "PUT Response: #{response.code} #{response.body[0..200]}" - response + # def put id, body = "" + # path = "#{db_url}/#{id}" + # puts "remote: PUT path #{path}" + # puts "remote: PUT body: #{body[0..80]} ..." + # #response = Typhoeus::Request.put(path, :body => body) + # puts "PUT Response: #{response.code} #{response.body[0..200]}" + # response + # end + + def push_docs docs + docs = docs.kind_of?(Array) ? docs : [docs] + docs.each_slice(1000) do |chunk| + json =RestClient.post "#{db_url}/_bulk_docs", {"docs" => chunk}.to_json, :content_type => :json, :accept => :json + JSON.parse(json) + puts "pushed #{chunk.size}" + end + true end + end end