lib/fog/rackspace/requests/storage/delete_multiple_objects.rb in fog-maestrodev-1.19.0.20140212012611 vs lib/fog/rackspace/requests/storage/delete_multiple_objects.rb in fog-maestrodev-1.20.0.20140305101305

- old
+ new

@@ -1,8 +1,9 @@ module Fog module Storage class Rackspace + class Real # Deletes multiple objects or containers with a single request. # # To delete objects from a single container, +container+ may be provided @@ -68,8 +69,64 @@ response.body = Fog::JSON.decode(response.body) response end end + + class Mock + def delete_multiple_objects(container, object_names, options = {}) + results = { + "Number Not Found" => 0, + "Response Status" => "200 OK", + "Response Body" => "", + "Errors" => [], + "Number Deleted" => 0 + } + + object_names.each do |name| + if container + cname, oname = container, name + else + cname, oname = name.split('/', 2) + end + + c = mock_container cname + if c.nil? + # Container not found + results["Number Not Found"] += 1 + next + end + + if oname.nil? + # No object name specified; delete the container if it's nonempty + unless c.empty? + results["Response Status"] = "400 Bad Request" + results["Errors"] << [cname, "409 Conflict"] + next + end + + remove_container cname + results["Number Deleted"] += 1 + next + end + + o = c.mock_object oname + if o.nil? + # Object not found. + results["Number Not Found"] += 1 + next + end + + c.remove_object oname + results["Number Deleted"] += 1 + end + + response = Excon::Response.new + response.status = 200 + response.body = results + response + end + end + end end end