File: delete_object.rb

package info (click to toggle)
ruby-fog-google 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,568 kB
  • sloc: ruby: 16,775; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 1,402 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Fog
  module Storage
    class GoogleXML
      class Real
        # Delete an object from Google Storage
        #
        # ==== Parameters
        # * bucket_name<~String> - Name of bucket containing object to delete
        # * object_name<~String> - Name of object to delete
        #
        # ==== Returns
        # * response<~Excon::Response>:
        #   * status<~Integer> - 204
        def delete_object(bucket_name, object_name)
          request(:expects    => 204,
                  :headers    => {},
                  :host       => "#{bucket_name}.#{@host}",
                  :idempotent => true,
                  :method     => "DELETE",
                  :path       => Fog::Google.escape(object_name))
        end
      end

      class Mock
        def delete_object(bucket_name, object_name)
          response = Excon::Response.new
          if bucket = data[:buckets][bucket_name]
            if object = bucket[:objects][object_name]
              response.status = 204
              bucket[:objects].delete(object_name)
            else
              response.status = 404
              raise(Excon::Errors.status_error({ :expects => 204 }, response))
            end
          else
            response.status = 404
            raise(Excon::Errors.status_error({ :expects => 204 }, response))
          end
          response
        end
      end
    end
  end
end